Ok so I have this shit simple code:
[lua]
function GM:EntityTakeDamage( ent, inf, atk, amount, dmginfo )
if ent:IsPlayer() and ( atk:GetClass() == "prop_physics" or inf:GetClass() == "prop_physics" ) then
dmginfo:ScaleDamage( 0 )
return
elseif ent:GetClass() == "prop_physics" then
ent:TakeDamage( amount, attk )
end
if ent:Health() <= 0 then
local Effect = EffectData()
Effect:SetStart( ent:GetPos() )
Effect:SetOrigin( ent:GetPos() )
Effect:SetScale( 5 )
util.Effect( "balloon_pop", Effect )
end
end
[/lua]
And it keeps giving me this error:
ERROR: GAMEMODE:'EntityTakeDamage' Failed: gamemodes\flood\gamemode\entity.lua:2: C stack overflow
Can anyone help me? I don't understand why this is happening.
You put an extra parentheses at the end of line 2.
I fixed it, and it is still happening.
[editline]09:37PM[/editline]
Update, it only gives that error if I attack a prop_physics. If I (the player) get hurt, it gives me this error:
lua\includes\modules\hook.lua:75: C stack overflow
[editline]09:42PM[/editline]
Another update, if I get hurt before I attack a prop after reloading the gamemode, my game freezes and doesn't unfreeze. :aaaaa:
[editline]11:01PM[/editline]
Nevermind, I restarted my GMod and now everything seems to be working... :tinfoil:
[QUOTE=Chief Tiger;22813299]Ok so I have this shit simple code:
[lua]
function GM:EntityTakeDamage( ent, inf, atk, amount, dmginfo )
if ent:IsPlayer() and ( atk:GetClass() == "prop_physics" or inf:GetClass() == "prop_physics" ) then
dmginfo:ScaleDamage( 0 )
return
elseif ent:GetClass() == "prop_physics" then
ent:TakeDamage( amount, attk )
end
[/lua]
[/QUOTE]
Uh... looks like an infinite loop to me. Look, whenever a physics prop is damaged, you tell it to take damage. Which will trigger the EntityTakeDamage hook. Which will damage the prop again, which will trigger the EntityTakeDamage hook again, and so on...
Why do you need to do that?
C Stack overflows mostly has the line wrong, but your causing an infinite loop there, you can do something like this:
[lua]function GM:EntityTakeDamage( ent, inf, atk, amount, dmginfo )
if TAKEDAMAGE then return end
TAKEDAMAGE = true
if ent:IsPlayer() and ( atk:GetClass() == "prop_physics" or inf:GetClass() == "prop_physics" ) then
dmginfo:ScaleDamage( 0 )
return
elseif ent:GetClass() == "prop_physics" then
ent:TakeDamage( amount, attk )
end
TAKEDAMAGE = false
[/lua]
As _Kilburn said, you are creating the infinite loop by calling TakeDamage on line 6 of the posted code.
Why are doing that?
Sorry, you need to Log In to post a reply to this thread.