For some reason, the code in my function won't register the arguments as variables. (did that make sense?)
heres the parts of my code that matter:
This is what calls the function:
[lua]
timer.Create("WepSpawn", 10.5, 1, SpawnDrop, ent )
[/lua]
This is what the function is:
[lua]
function SpawnDrop( can )
local attachment
if not can.Eject then
can.eject = can:LookupAttachment( "headcrab" )
end
attachment = can:GetAttachment( can.eject )
local gun = ents.Create( "weapon_ar2" )
gun:SetPos( attachment.pos )
gun:SetAngles( can.Angles )
gun:Spawn()
end
[/lua]
Please help :(
We have to see more code from where the timer is being created. Also, use [lua] tags next time, and
[lua]
if not can.Eject then
can.eject = can:LookupAttachment( "headcrab" )
end
[/lua]
That will be run every time, because your checking for Eject, but you're only using eject.
[QUOTE=PortalGod;25926111]We have to see more code from where the timer is being created. Also, use [lua] tags next time, and
[lua]
if not can.Eject then
can.eject = can:LookupAttachment( "headcrab" )
end
[/lua]
That will be run every time, because your checking for Eject, but you're only using eject.[/QUOTE]
Ok, i fixed the can.Eject part, the timer is comming from a SWEP:PrimaryAttack function
Can we see the whole function?
[QUOTE=PortalGod;25928207]Can we see the whole function?[/QUOTE]
[lua]
function SWEP:PrimaryAttack(bSecondary)
local tr = self.Owner:GetEyeTrace()
self:ShootEffects(self)
if (SERVER) then
local aBaseAngle = tr.HitNormal:Angle()
local aBasePos = tr.HitPos
local bScanning = true
local iPitch = 10
local iYaw = -180
local iLoopLimit = 0
local iProcessedTotal = 0
local tValidHits = {}
while (bScanning == true && iLoopLimit < 500) do
iYaw = iYaw + YawIncrement
iProcessedTotal = iProcessedTotal + 1
if (iYaw >= 180) then
iYaw = -180
iPitch = iPitch - PitchIncrement
end
local tLoop = util.QuickTrace( aBasePos, (aBaseAngle+Angle(iPitch,iYaw,0)):Forward()*40000 )
if (tLoop.HitSky || bSecondary) then
table.insert(tValidHits,tLoop)
end
if (iPitch <= -80) then
bScanning = false
end
iLoopLimit = iLoopLimit + 1
end
local iHits = table.Count(tValidHits)
if (iHits > 0) then
local iRand = math.random(1,iHits)
local tRand = tValidHits[iRand]
--Canister Spawn
local ent = ents.Create( "env_headcrabcanister" )
ent:SetPos( aBasePos )
ent:SetAngles( (tRand.HitPos-tRand.StartPos):Angle() )
ent:SetKeyValue( "HeadcrabType", 0 )
ent:SetKeyValue( "HeadcrabCount", 0 )
ent:SetKeyValue( "FlightSpeed", 4500 )
ent:SetKeyValue( "FlightTime", 10 )
ent:SetKeyValue( "Damage", math.random(25,75) )
ent:SetKeyValue( "DamageRadius", 50 )
ent:SetKeyValue( "SmokeLifetime", math.random(10,30) )
ent:SetKeyValue( "StartingHeight", 1000 )
local iSpawnFlags = 8192
if (bSecondary) then iSpawnFlags = iSpawnFlags + 4096 end //If Secondary, spawn impacted.
ent:SetKeyValue( "spawnflags", iSpawnFlags )
ent:Spawn()
ent:Input("FireCanister", self.Owner, self.Owner)
undo.Create("CrabLaunch")
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.AddFunction(function(undo)
for k, v in pairs(ents.FindByClass("weapon_ar2"))do
if (v:GetOwner() == ent) then v:Remove() end
end
end)
undo.Finish()
self:EmitSound( ShootSoundFire )
else
self:EmitSound( ShootSoundFail )
end
tLoop = nil
tValidHits = nil
timer.Simple( 10, Prep, ent )
end
end
[/lua]
That's the function with the timer in it.
You declared ent to be local to the if statement.
[QUOTE=PortalGod;25928660]You declared ent to be local to the if statement.[/QUOTE]
Thank you, I'm convinced your god.
[QUOTE=wardino388;25941520]Thank you, I'm convinced your god.[/QUOTE]
His God isn't real, convince mine plz.
Sorry, you need to Log In to post a reply to this thread.