Hi, I'm coding a bit and i would like to know how to make this ignite the target it hits and if it is an npc/player it'd count the kill as theirs.
[lua]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
local Grenade_Sound = Sound( "npc/headcrab/headcrab_burning_loop2.wav" )
local Bounce_Sound = Sound( "physics/concrete/rock_impact_hard4.wav" )
/*---------------------------------------------------------
Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()
// Use the helibomb model just for the shadow (because it's about the same size)
self.Entity:SetModel( "models/props_c17/lamp001a.mdl" )
// Don't use the model's physics - create a sphere instead
self.Entity:PhysicsInitSphere( 16, "metal_bouncy" )
// Wake the physics object up. It's time to have fun!
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
phys:SetDamping( 0.2, 0 )
phys:AddAngleVelocity( VectorRand() * 360 )
end
// Set collision bounds exactly
self.Entity:SetCollisionBounds( Vector()*-16, Vector()*16 )
self.ExplodeTime = CurTime() + self.FuseLength
self.Entity:SetNetworkedFloat( "ExplodeTime", self.ExplodeTime )
self.Sound = CreateSound( self.Entity, Grenade_Sound )
self.Sound:SetSoundLevel( 80 )
self.Sound:Play()
self.Sound:ChangePitch( 255, self.FuseLength )
self.Sound:ChangeVolume( 10, 0.1 )
self.SpriteTrail1 = util.SpriteTrail( self, 0, Color(100, 200, 255), true, 4, 0, 2, 0, "sprites/bluelaser1.vmt" )
self.SpriteTrail2 = util.SpriteTrail( self, 0, Color(255, 255, 255), true, 32, 0, 1, 0, "sprites/bluelaser1.vmt" )
end
/*---------------------------------------------------------
Name: Initialize
---------------------------------------------------------*/
function ENT:OnRemove()
if ( self.Sound ) then
self.Sound:Stop()
end
end
/*---------------------------------------------------------
Name: Initialize
---------------------------------------------------------*/
function ENT:Think()
if ( self.ExplodeTime > CurTime() ) then return end
self:Explode()
end
function ENT:Explode()
if ( self.Exploded ) then return end
self.Exploded = true
self.SpriteTrail1:SetParent( NULL )
self.SpriteTrail2:SetParent( NULL )
SafeRemoveEntityDelayed( self.SpriteTrail1, 4 )
SafeRemoveEntityDelayed( self.SpriteTrail2, 4 )
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint ) // not sure if we need a start and origin (endpoint) for this effect, but whatever
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 1 )
util.Effect( "cball_explode", effectdata )
util.BlastDamage(self.Entity, self.Entity:GetOwner(),self.Entity:GetPos(), 100, 30)
for k,v in pairs (ents.FindInSphere(self.Entity:GetPos(),100)) do
if v:IsNPC() or v:IsPlayer() then v:Ignite(1) end
end
self.Entity:Remove()
end
/*---------------------------------------------------------
Name: PhysicsCollide
---------------------------------------------------------*/
function ENT:PhysicsCollide( data, physobj )
self:Explode()
end
/*---------------------------------------------------------
Name: OnTakeDamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )
// React physically when shot/getting blown
self.Entity:TakePhysicsDamage( dmginfo )
// Explode now, but delayed
self.ExplodeTime = CurTime() + 0.1
end
/*---------------------------------------------------------
Name: Use
---------------------------------------------------------*/
function ENT:Use( activator, caller )
self.Entity:Remove()
if ( activator:IsPlayer() ) then
// Give the collecting player some free health
local health = activator:Health()
activator:SetHealth( health + 5 )
end
end
[/lua]
Are you experiencing any errors?
[QUOTE=Yobdren;16623554]Are you experiencing any errors?[/QUOTE]
No i just want to know how to do it
You'd use [url=http://wiki.garrysmod.com/?title=Entity.SetOwner]Entity:SetOwner()[/url] when the entity is created, and set the owner as the person who spawned it. Then when a player touches it use [url=http://wiki.garrysmod.com/?title=Entity.Ignite]EntityThatTouchedIt:Ignite()[/url]. Then use upon the victims death, [url=http://wiki.garrysmod.com/?title=Entity.GetOwner]Entity:GetOwner[/url] to get the owner and add a score to that player with [url=http://wiki.garrysmod.com/?title=Player.AddFrags]PlayerObjectHere.AddFrags()[/url]
Sorry, you need to Log In to post a reply to this thread.