I am having trouble making this so that
A: You keep re-using it ( Should I just make a hook and tell the hook to repeat after the func is complete? )
B: It explodes after 100hp has been depleted..
( Please help. )
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self.Entity:SetModel( "models/Items/ammocrate_ar2.mdl" )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
self.Entity:SetHealth( 100 )
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self.use = true
end
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "sent_AmmoCrate" )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function GM:EntityTakeDamage( self, CTakeDamageInfo )
if ( CTakeDamageInfo:GetDamage( ) and Entity:Health ( (<= 0)) then
ent:Remove()
end
end
function ENT:Use(activator)
if (self.use) then
activator:GiveAmmo( 30, "357" )
activator:GiveAmmo( 30, "Buckshot" )
activator:GiveAmmo( 30, "AR2" )
activator:GiveAmmo( 30, "Pistol" )
activator:GiveAmmo( 30, "SMG1" )
self.use = true
timer.Simple(2.0,usereply)
end
end
function usereply(self)
self.use = true
end
[/lua]
[highlight](User was banned for this post ("utt" - garry))[/highlight]
Are you getting errors or what?
Also why do you do self.use = true in the Use function and in the usereply function?
This will do the trick.
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/Items/ammocrate_ar2.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
self.CHealth = 100
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self.UseDelay = 10
self.LastUse = CurTime()
end
function ENT:SpawnFunction(ply, tr)
if (!tr.Hit) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create("sent_AmmoCrate")
ent:SetPos(SpawnPos)
ent:Spawn()
ent:Activate()
return ent
end
function ENT:OnTakeDamage(dmginfo)
local dmg = dmginfo:GetDamage()
if !dmg then return false end
self.CHealth = self.CHealth - dmg
if self.CHealth <= 0 then
local pos = self:GetPos()
local eData = EffectData()
eData:SetStart(pos)
eData:SetOrigin(pos)
eData:SetScale(1)
util.Effect("Explosion", eData)
ent:Remove()
end
end
function ENT:Use(activator)
if !activator:IsValid() then return end
if CurTime() - self.LastUse < self.UseDelay then return end
activator:GiveAmmo(30, "357")
activator:GiveAmmo(30, "Buckshot")
activator:GiveAmmo(30, "AR2")
activator:GiveAmmo(30, "Pistol")
activator:GiveAmmo(30, "SMG1")
self.LastUse = CurTime()
end
[/lua]
Sorry, you need to Log In to post a reply to this thread.