All pastes #2048515 Raw Edit

Something

public text v1 · immutable
#2048515 ·published 2011-04-20 02:53 UTC
rendered paste body
//AddCSLuaFile( "cl_init.lua" ) -- Make sure clientside
AddCSLuaFile( "shared.lua" )  -- and shared scripts are sent.
 
include('shared.lua')
 
function ENT:Initialize()	
	self.bombTime = 20 // in seconds
	self.defuseTime = 66*5 // this is in server ticks REMEMBER TO CHANGE THIS IN shared.lua
	
//	self.countDown = self.bombTime
	self.countDown = 0				// this makes the bomb explode the next time self.Timer is called
	self.defuse = self.defuseTime
	
	self:SetNWInt("DefuseTimer", self.defuseTime)

	self:SetModel("models/weapons/w_c4_planted.mdl")
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	self:SetCollisionGroup(COLLISION_GROUP_WEAPON) // collides with everything except players

	local phys = self:GetPhysicsObject()
	if ( phys:IsValid() ) then
		phys:Wake()
	end

	self:SetUseType(CONTINUOUS_USE)

	self.bombsprite = ents.Create("env_sprite")
	self.bombsprite:SetKeyValue("model","sprites/blueflare1.spr")
	self.bombsprite:SetKeyValue("scale","0.3")
	self.bombsprite:SetKeyValue("rendermode","3")
	self.bombsprite:SetKeyValue("rendercolor","255 0 0")
	self.bombsprite:SetPos(self:GetPos() + Vector(0,0,10))
	self.bombsprite:SetParent(self)
	self.bombsprite:Spawn()
	self.bombsprite:Fire("ShowSprite","",0)

//	timer.Simple(1, self.Timer, self)
	timer.Simple(0.5,self.SpriteToggle, self)

end

function ENT:SpriteToggle()
         if !self:IsValid() then return end
         if self.chargecountdown == 0 then return end
            self.bombsprite:Fire("ToggleSprite","",0)

            timer.Simple(0.5,self.SpriteToggle,self)
end

function ENT:Use( ply, caller )
	self.defuse = self.defuse - 1
	self:SetNWInt("DefuseTimer", self.defuse )
	if self.defuse <= 0 then
		self:Remove()
	end
end

function ENT:Timer()
	if !self:IsValid() then return; end

	if self.countDown > 0 then
//		self:EmitSound("weapons/c4/c4_beep1.wav")
		self.Owner:PrintMessage(HUD_PRINTCENTER, self.countDown)
		self.countDown = self.countDown - 1
		timer.Simple(1, self.Timer, self)
	else
//		self:EmitSound("ambient/explosions/explode_1.wav")
//		self:EmitSound("weapons/c4/c4_explode1.wav")
//		self:EmitSound("weapons/c4/c4_exp_deb2.wav")

		for k, v in pairs(player.GetAll()) do
			v:EmitSound("ambient/explosions/explode_1.wav")
			v:EmitSound("weapons/c4/c4_explode1.wav")
			v:EmitSound("weapons/c4/c4_exp_deb2.wav")
		end

		local wallTable = ents.FindInSphere( self:GetPos(), 1200 )
		for _,wall in pairs(wallTable) do
			 if ValidEntity(wall:GetNetworkedEntity("OwnerObj")) && wall:GetNetworkedEntity("OwnerObj"):IsPlayer() then
				constraint.RemoveAll( wall )
				wall:SetParent( nil )
				wall:SetMoveType( MOVETYPE_VPHYSICS )
				wall:SetSolid( SOLID_VPHYSICS )
				wall:SetPhysicsAttacker(self.Owner)
	
				local phys = wall:GetPhysicsObject()
				if phys:IsValid() then
					phys:EnableMotion( true )
					phys:Wake()
					phys:ApplyForceCenter( (wall:GetPos() - self:GetPos() ):Normalize() * 999999999999999 )
				end
				wall:Ignite( 10, 0 )
/*				
				timer.Simple( 8, function()
					if !wall:IsValid() or wall:IsPlayer() then return end
					wall:Remove()
				end)
*/
			 end
		end

		local explode = ents.Create( "env_explosion" )
		explode:SetPos( self:GetPos() )
		explode:SetOwner( self.Owner )
		explode:Spawn()
		explode:SetKeyValue( "iMagnitude", "220" )
		explode:Fire( "Explode", 0, 0 )
	
		self.sparktable = {}
		for i = 1,12,1 do
			self.EntSpark = ents.Create("env_spark")
			table.insert(self.sparktable, self.EntSpark)
		end

		for _,Sparks in pairs(self.sparktable) do
			local trace = {}
			trace.start = self:GetPos() + Vector(0,0,200)
			trace.endpos = self:GetPos() + Vector(math.random(-350,350),math.random(-350,350),math.random(0,250))
			
			local tr = util.TraceLine(trace)

			Sparks:SetKeyValue("Magnitude",tostring(math.random(2,8)))
			Sparks:SetKeyValue("TrailLength",tostring(math.random(1,3)))
			Sparks:SetPos(tr.HitPos)
			Sparks:Spawn()
			Sparks:Fire("SparkOnce","",0)
			Sparks:Fire("kill","",2)
         end
		 
		self:Remove()
	end
end

function ENT:OnRemove( )
	self.bombsprite:Remove()
end