2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
|
|
|
|
include('shared.lua')
|
|
|
|
|
2007-05-24 06:02:07 +00:00
|
|
|
ENT.WireDebugName = "Explosive"
|
2007-02-04 06:14:27 +00:00
|
|
|
ENT.OverlayDelay = 0
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: Initialize
|
|
|
|
Desc: First function called. Use to set up your entity
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function ENT:Initialize()
|
|
|
|
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
|
|
|
|
|
|
|
local phys = self.Entity:GetPhysicsObject()
|
2007-05-24 06:02:07 +00:00
|
|
|
if (phys:IsValid()) then
|
|
|
|
phys:Wake()
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.exploding = false
|
|
|
|
self.reloading = false
|
2007-02-04 06:14:27 +00:00
|
|
|
self.NormInfo = ""
|
2007-02-04 01:16:06 +00:00
|
|
|
self.count = 0
|
2007-05-24 06:02:07 +00:00
|
|
|
self.ExplodeTime = 0
|
|
|
|
self.ReloadTime = 0
|
|
|
|
self.CountTime = 0
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
self.Inputs = Wire_CreateInputs(self.Entity, { "Detonate", "ResetHealth" })
|
|
|
|
|
|
|
|
self.Entity:SetMaxHealth(100)
|
|
|
|
self.Entity:SetHealth(100)
|
|
|
|
self.Outputs = Wire_CreateOutputs(self.Entity, { "Health" })
|
|
|
|
end
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: TriggerInput
|
|
|
|
Desc: the inputs
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function ENT:TriggerInput(iname, value)
|
|
|
|
if (iname == "Detonate") then
|
|
|
|
if ( !self.exploding && !self.reloading ) then
|
|
|
|
if ( math.abs(value) == self.key ) then
|
|
|
|
self:Trigger()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif (iname == "ResetHealth") then
|
2007-05-24 06:02:07 +00:00
|
|
|
self:ResetHealth()
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: Setup
|
|
|
|
Desc: does a whole lot of setting up
|
|
|
|
---------------------------------------------------------*/
|
2007-02-04 06:14:27 +00:00
|
|
|
function ENT:Setup( damage, delaytime, removeafter, doblastdamage, radius, affectother, notaffected, delayreloadtime, maxhealth, bulletproof, explosionproof, fallproof, explodeatzero, resetatexplode, fireeffect, coloreffect, invisibleatzero, nocollide )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
2007-12-09 01:30:41 +00:00
|
|
|
self.Damage = math.Clamp( damage, 0, 1500 )
|
2007-05-24 06:02:07 +00:00
|
|
|
self.Delaytime = delaytime
|
2007-02-04 01:16:06 +00:00
|
|
|
self.Removeafter = removeafter
|
|
|
|
self.DoBlastDamage = doblastdamage
|
2008-09-16 17:05:56 +00:00
|
|
|
self.Radius = math.min(512,math.max(radius, 1))
|
2007-02-04 01:16:06 +00:00
|
|
|
self.Affectother = affectother
|
|
|
|
self.Notaffected = notaffected
|
|
|
|
self.Delayreloadtime = delayreloadtime
|
|
|
|
|
|
|
|
self.BulletProof = bulletproof
|
|
|
|
self.ExplosionProof = explosionproof
|
|
|
|
self.FallProof = fallproof
|
|
|
|
|
|
|
|
self.ExplodeAtZero = explodeatzero
|
|
|
|
self.ResetAtExplode = resetatexplode
|
|
|
|
|
|
|
|
self.FireEffect = fireeffect
|
|
|
|
self.ColorEffect = coloreffect
|
2007-02-04 06:14:27 +00:00
|
|
|
self.NoCollide = nocollide
|
|
|
|
self.InvisibleAtZero = invisibleatzero
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
self.Entity:SetMaxHealth(maxhealth)
|
2007-02-04 06:14:27 +00:00
|
|
|
self:ResetHealth()
|
|
|
|
|
|
|
|
|
|
|
|
//self.Entity:SetHealth(maxhealth)
|
|
|
|
//Wire_TriggerOutput(self.Entity, "Health", maxhealth)
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
//reset everthing back and try to stop exploding
|
2007-02-04 06:14:27 +00:00
|
|
|
//self.exploding = false
|
|
|
|
//self.reloading = false
|
|
|
|
//self.count = 0
|
|
|
|
//self.Entity:Extinguish()
|
|
|
|
//if (self.ColorEffect) then self.Entity:SetColor(255, 255, 255, 255) end
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
self.NormInfo = "Explosive"
|
|
|
|
if (self.DoBlastDamage) then self.NormInfo = self.NormInfo.." (Damage: "..self.Damage..")" end
|
2007-05-24 06:02:07 +00:00
|
|
|
if (self.Radius > 0 || self.Delaytime > 0) then self.NormInfo = self.NormInfo.."\n" end
|
2007-02-04 01:16:06 +00:00
|
|
|
if (self.Radius > 0 ) then self.NormInfo = self.NormInfo.." Rad: "..self.Radius end
|
2007-05-24 06:02:07 +00:00
|
|
|
if (self.Delaytime > 0) then self.NormInfo = self.NormInfo.." Delay: "..self.Delaytime end
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
self:ShowOutput()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:ResetHealth( )
|
|
|
|
self.Entity:SetHealth( self.Entity:GetMaxHealth() )
|
2007-02-04 06:14:27 +00:00
|
|
|
Wire_TriggerOutput(self.Entity, "Health", self.Entity:GetMaxHealth())
|
|
|
|
|
|
|
|
//put the fires out and try to stop exploding
|
|
|
|
self.exploding = false
|
|
|
|
self.reloading = false
|
|
|
|
self.count = 0
|
|
|
|
self.Entity:Extinguish()
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
if (self.ColorEffect) then self.Entity:SetColor(255, 255, 255, 255) end
|
2007-02-04 06:14:27 +00:00
|
|
|
|
|
|
|
self.Entity:SetNoDraw( false )
|
|
|
|
|
|
|
|
if (self.NoCollide) then
|
2007-05-24 06:02:07 +00:00
|
|
|
self.Entity:SetCollisionGroup(COLLISION_GROUP_WORLD)
|
2007-02-04 06:14:27 +00:00
|
|
|
else
|
|
|
|
self.Entity:SetCollisionGroup(COLLISION_GROUP_NONE)
|
|
|
|
end
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
self:ShowOutput()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: OnTakeDamage
|
|
|
|
Desc: Entity takes damage
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function ENT:OnTakeDamage( dmginfo )
|
|
|
|
|
|
|
|
if ( dmginfo:GetInflictor():GetClass() == "gmod_wire_explosive" && !self.Affectother ) then return end
|
|
|
|
|
|
|
|
if ( !self.Notaffected ) then self.Entity:TakePhysicsDamage( dmginfo ) end
|
|
|
|
|
|
|
|
if (dmginfo:IsBulletDamage() && self.BulletProof) ||
|
|
|
|
(dmginfo:IsExplosionDamage() && self.ExplosionProof) ||
|
|
|
|
(dmginfo:IsFallDamage() && self.FallProof) then return end //fix fall damage, it doesn't happen
|
|
|
|
|
|
|
|
if (self.Entity:Health() > 0) then //don't need to beat a dead horse
|
2007-05-26 07:23:42 +00:00
|
|
|
local dammage = dmginfo:GetDamage()
|
|
|
|
local h = self.Entity:Health() - dammage
|
2007-02-04 01:16:06 +00:00
|
|
|
if (h < 0) then h = 0 end
|
|
|
|
self.Entity:SetHealth(h)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Health", h)
|
|
|
|
self:ShowOutput()
|
|
|
|
if (self.ColorEffect) then
|
|
|
|
if (h == 0) then c = 0 else c = 255 * (h / self.Entity:GetMaxHealth()) end
|
|
|
|
self.Entity:SetColor(255, c, c, 255)
|
|
|
|
end
|
2007-02-04 06:14:27 +00:00
|
|
|
if (h == 0) then
|
|
|
|
if (self.ExplodeAtZero) then self:Trigger() end //oh shi--
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: Trigger
|
|
|
|
Desc: Start exploding
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function ENT:Trigger()
|
2007-05-24 06:02:07 +00:00
|
|
|
if ( self.Delaytime > 0 ) then
|
|
|
|
//self.exploding = true
|
|
|
|
self.ExplodeTime = CurTime() + self.Delaytime
|
|
|
|
if (self.FireEffect) then self.Entity:Ignite((self.Delaytime + 3),0) end
|
|
|
|
/* timer.Simple( self.Delaytime, self.Explode, self )
|
|
|
|
//self.count = self.Delaytime
|
|
|
|
//self:Countdown()
|
|
|
|
//else
|
|
|
|
//self.exploding = true
|
|
|
|
//self:Explode()
|
|
|
|
*/
|
|
|
|
end
|
|
|
|
self.exploding = true
|
|
|
|
// Force reset of counter
|
|
|
|
self.CountTime = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: Think
|
|
|
|
Desc: Thinks :P
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function ENT:Think()
|
|
|
|
self.BaseClass.Think(self)
|
|
|
|
|
|
|
|
if (self.exploding) then
|
|
|
|
if (self.ExplodeTime < CurTime()) then
|
|
|
|
self:Explode()
|
|
|
|
end
|
|
|
|
elseif (self.reloading) then
|
|
|
|
if (self.ReloadTime < CurTime()) then
|
|
|
|
self.reloading = false
|
|
|
|
if (self.ResetAtExplode) then
|
|
|
|
self:ResetHealth()
|
|
|
|
else
|
|
|
|
self:ShowOutput()
|
|
|
|
end
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
2007-05-24 06:02:07 +00:00
|
|
|
|
|
|
|
// Do count check to ensure that
|
|
|
|
// ShowOutput() is called every second
|
|
|
|
// when exploding or reloading
|
2007-05-26 07:23:42 +00:00
|
|
|
if ((self.CountTime or 0) < CurTime()) then
|
2007-05-24 06:02:07 +00:00
|
|
|
local temptime = 0
|
|
|
|
if (self.exploding) then
|
|
|
|
temptime = self.ExplodeTime
|
|
|
|
elseif (self.reloading) then
|
|
|
|
temptime = self.ReloadTime
|
|
|
|
end
|
|
|
|
|
|
|
|
if (temptime > 0) then
|
|
|
|
self.count = math.ceil(temptime - CurTime())
|
|
|
|
self:ShowOutput()
|
|
|
|
end
|
|
|
|
|
|
|
|
self.CountTime = CurTime() + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
self.Entity:NextThink(CurTime() + 0.05)
|
|
|
|
return true
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: Explode
|
|
|
|
Desc: is one needed?
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function ENT:Explode( )
|
|
|
|
|
|
|
|
if ( !self.Entity:IsValid() ) then return end
|
|
|
|
|
|
|
|
self.Entity:Extinguish()
|
|
|
|
|
|
|
|
if (!self.exploding) then return end //why are we exploding if we shouldn't be
|
|
|
|
|
2007-05-23 01:48:42 +00:00
|
|
|
ply = self:GetPlayer() or self.Entity
|
2008-04-07 15:40:22 +00:00
|
|
|
if(not ValidEntity(ply)) then ply = self.Entity end;
|
2007-02-04 01:16:06 +00:00
|
|
|
|
2007-02-04 06:14:27 +00:00
|
|
|
if (self.InvisibleAtZero) then
|
|
|
|
ply:SetCollisionGroup(COLLISION_GROUP_DEBRIS)
|
|
|
|
ply:SetNoDraw( true )
|
|
|
|
ply:SetColor(255, 255, 255, 0)
|
|
|
|
end
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
if ( self.DoBlastDamage ) then
|
|
|
|
util.BlastDamage( self.Entity, ply, self.Entity:GetPos(), self.Radius, self.Damage )
|
|
|
|
end
|
|
|
|
|
|
|
|
local effectdata = EffectData()
|
|
|
|
effectdata:SetOrigin( self.Entity:GetPos() )
|
|
|
|
util.Effect( "Explosion", effectdata, true, true )
|
|
|
|
|
|
|
|
if ( self.Removeafter ) then
|
|
|
|
self.Entity:Remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
self.exploding = false
|
2007-05-24 06:02:07 +00:00
|
|
|
|
|
|
|
self.reloading = true
|
|
|
|
self.ReloadTime = CurTime() + math.max(1, self.Delayreloadtime)
|
|
|
|
// Force reset of counter
|
|
|
|
self.CountTime = 0
|
|
|
|
self:ShowOutput()
|
2007-02-04 01:16:06 +00:00
|
|
|
|
2007-05-24 06:02:07 +00:00
|
|
|
/*if ( self.Delayreloadtime > 0 ) then
|
2007-02-04 01:16:06 +00:00
|
|
|
//t = self.Delayreloadtime + 1
|
|
|
|
self.reloading = true
|
2007-05-24 06:02:07 +00:00
|
|
|
//timer.Simple( self.Delayreloadtime, self.Reloaded, self )
|
|
|
|
//self.count = self.Delayreloadtime
|
|
|
|
//self:Countdown()
|
2007-02-04 01:16:06 +00:00
|
|
|
else //keep it from going off again for at least another second
|
|
|
|
self.reloading = true
|
|
|
|
timer.Simple( 1, self.Reloaded, self )
|
|
|
|
self:ShowOutput(0)
|
2007-05-24 06:02:07 +00:00
|
|
|
end*/
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2007-05-24 06:02:07 +00:00
|
|
|
/* Don't need these anymore
|
2007-02-04 01:16:06 +00:00
|
|
|
function ENT:Reloaded( )
|
|
|
|
self.reloading = false
|
|
|
|
if (self.ResetAtExplode) then self:ResetHealth() end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Countdown( )
|
|
|
|
self:ShowOutput()
|
|
|
|
self.count = self.count - 1
|
|
|
|
if ( self.count > 0 ) then //theres still time left
|
|
|
|
timer.Simple( 1, self.Countdown, self )
|
|
|
|
else //will be done after this second
|
|
|
|
timer.Simple( 1, self.ShowOutput, self )
|
|
|
|
end
|
|
|
|
end
|
2007-05-24 06:02:07 +00:00
|
|
|
*/
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
Name: ShowOutput
|
|
|
|
Desc: don't foreget to call this when changes happen
|
|
|
|
---------------------------------------------------------*/
|
2007-05-24 06:02:07 +00:00
|
|
|
function ENT:ShowOutput( )
|
|
|
|
local txt = ""
|
|
|
|
if (self.reloading && self.Delayreloadtime > 0) then
|
2007-02-04 01:16:06 +00:00
|
|
|
txt = "Rearming... "..self.count
|
2007-02-04 06:14:27 +00:00
|
|
|
if (self.ColorEffect && !self.InvisibleAtZero) then
|
2007-02-04 01:16:06 +00:00
|
|
|
if (self.count == 0) then c = 255 else c = 255 * ((self.Delayreloadtime - self.count) / self.Delayreloadtime) end
|
|
|
|
self.Entity:SetColor(255, c, c, 255)
|
|
|
|
end
|
2007-02-04 06:14:27 +00:00
|
|
|
if (self.InvisibleAtZero) then
|
|
|
|
ply:SetNoDraw( false )
|
|
|
|
if (self.count == 0) then c = 255 else c = 255 * ((self.Delayreloadtime - self.count) / self.Delayreloadtime) end
|
|
|
|
self.Entity:SetColor(255, 255, 255, c)
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
elseif (self.exploding) then
|
|
|
|
txt = "Triggered... "..self.count
|
|
|
|
else
|
|
|
|
txt = self.NormInfo.."\nHealth: "..self.Entity:Health().."/"..self.Entity:GetMaxHealth()
|
2007-05-24 06:02:07 +00:00
|
|
|
end
|
|
|
|
self:SetOverlayText(txt)
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|