• C stack overflow?
    20 replies, posted
[IMG_thumb]http://i48.tinypic.com/20b22p4.jpg[/IMG_thumb] What would cause this to be spammed so horribly? I tried some searching, but couldn't find anything. I don't even know what code you'll need to see, but here's for when they die, ignore any horrible mistakes, as I'm a noob. Okay, I've established that it's because of this big section... [editline]7:25PM[/editline] [B]I believe it has to do with the timers.[/B] [editline]12:09AM[/editline] [B]I've now realized it only happens when the player is in a vehicle.[/B] [lua] function GM:PlayerSpawn( ply ) local players = #player.GetHumans() if players < 2 then return end ply:CrosshairDisable( true ) self.BaseClass:PlayerSpawn( ply ) ply:SetMaxSpeed( 1 ) ply:SetGravity( 0.75 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 1 ) ply:SetRunSpeed( 1 ) ply:StripWeapons() if ply:Team() == 2 then Spectate( ply ) elseif ply:Team() == 1 then ply:Lock() timer.Simple( 3, spawncar, ply ) end timer.Simple( 1, RaceMsgOne, ply ) timer.Simple( 2, RaceMsgTwo, ply ) timer.Simple( 3, RaceMsgThree, ply ) timer.Simple( 4, RaceMsgGo, ply ) end[/lua]
[lua] local function playerDies( victim, weapon, killer ) if victim:Team() == 1 then victim:SetTeam( 2 ) local car = victim:GetVehicle() if IsValid( car ) then car:Remove() end end end hook.Add( "PlayerDeath", "playerDeathTest", playerDies ) [/lua] Try that. I think when the player dies, getting the vehicle will return nothing.
Also, in addition to using blackops's code, try changing the hook to "DoPlayerDeath" instead of "PlayerDeath." That's called before they're finished dying, so getting their vehicle should be more reliable.
No luck, same error. You don't think it could have something to do with a trigger_hurt brush, do you? [editline]04:31PM[/editline] Nevermind, it happens if you leave the vehicle (you're killed by pl:Kill() ).
Well, I die once, and then it suicides me 99 times, if that helps?
I think switching the team kills you, which causes this deep recursion try setting some kind of flag on the player to prevent recursion [editline]08:14PM[/editline] [lua]local function playerDies( victim, weapon, killer ) if victim:Team() == 1 and not victim.changingteam then victim.changingteam = true victim:SetTeam( 2 ) victim.changingteam = nil local car = victim:GetVehicle() if IsValid( car ) then car:Remove() end end end hook.Add( "PlayerDeath", "playerDeathTest", playerDies )[/lua]
Same problem.
how about this? [lua]local function playerDies( victim, weapon, killer ) if victim:Team() == 1 and not victim.changingteam then victim.changingteam = true victim:SetTeam( 2 ) local car = victim:GetVehicle() if IsValid( car ) then car:Remove() end victim.changingteam = nil end end hook.Add( "PlayerDeath", "playerDeathTest", playerDies )[/lua] if that doesn't work, the error is elsewhere
Okay, I've established that it's because of this big section... [lua] function GM:PlayerSpawn( ply ) ply:CrosshairDisable( true ) self.BaseClass:PlayerSpawn( ply ) ply:SetMaxSpeed( 1 ) ply:SetGravity( 0.75 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 1 ) ply:SetRunSpeed( 1 ) ply:StripWeapons() if ply:Team() == 2 then Spectate( ply ) end local function RaceMsgOne() PrintMessage( HUD_PRINTCENTER, "3" ) end local function RaceMsgTwo() PrintMessage( HUD_PRINTCENTER, "2" ) end local function RaceMsgThree() PrintMessage( HUD_PRINTCENTER, "1" ) end local function RaceMsgGo() PrintMessage( HUD_PRINTCENTER, "Go!" ) ply:Freeze( false ) end if ply:Team() == 1 then ply:Freeze( true ) timer.Simple( 3, spawncar ) timer.Simple( 1, RaceMsgOne ) timer.Simple( 2, RaceMsgTwo ) timer.Simple( 3, RaceMsgThree ) timer.Simple( 4, RaceMsgGo ) function spawncar() if ply:Team() == 1 then local Jeep = ents.Create( "prop_vehicle_jeep_old" ) Jeep:SetModel( "models/buggy.mdl" ) Jeep:SetKeyValue( "vehiclescript", "scripts/vehicles/vehtest.txt" ) Jeep:Spawn() Jeep:Activate() ply.Jeep = Jeep ply.Jeep:SetPos( ply:GetPos()+ply:GetForward()*32+Vector(0, 0, 32) ) ply:EnterVehicle( ply.Jeep) end end end end [/lua]
[lua]local function spawncar(ply) local Jeep = ents.Create( "prop_vehicle_jeep_old" ) Jeep:SetModel( "models/buggy.mdl" ) Jeep:SetKeyValue( "vehiclescript", "scripts/vehicles/vehtest.txt" ) Jeep:Spawn() Jeep:Activate() ply.Jeep = Jeep ply.Jeep:SetPos( ply:GetPos()+ply:GetForward()*32+Vector(0, 0, 32) ) ply:EnterVehicle( ply.Jeep) end local function RaceMsgOne() PrintMessage( HUD_PRINTCENTER, "3" ) end local function RaceMsgTwo() PrintMessage( HUD_PRINTCENTER, "2" ) end local function RaceMsgThree() PrintMessage( HUD_PRINTCENTER, "1" ) end local function RaceMsgGo() PrintMessage( HUD_PRINTCENTER, "Go!" ) ply:Freeze( false ) end function GM:PlayerSpawn( ply ) ply:CrosshairDisable( true ) self.BaseClass:PlayerSpawn( ply ) -- try commenting out this line and seeing if it happens. ply:SetMaxSpeed( 1 ) ply:SetGravity( 0.75 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 1 ) ply:SetRunSpeed( 1 ) ply:StripWeapons() if ply:Team() == 2 then Spectate( ply ) elseif ply:Team() == 1 then ply:Freeze( true ) timer.Simple( 3, spawncar, ply ) end timer.Simple( 1, RaceMsgOne ) timer.Simple( 2, RaceMsgTwo ) timer.Simple( 3, RaceMsgThree ) timer.Simple( 4, RaceMsgGo ) end [/lua] The layout of your code was... 'questionable'. I believe that somewhere in that bizzare-ness was the reason for the stack overflow.
I think it works, but ply is nil on line 07 in your code. (I'm a big newbie to Lua, trying to work it out.)
Fixed!
Well, doing that didn't allow me to unfreeze the player with the MsgGo timer...I switched the :Freeze to :Lock, now getting the original overflow problem.
[QUOTE=TomyLobo;19447966]I think switching the team kills you, which causes this deep recursion[/QUOTE] What the fuck no? SetTeam() does not kill you at all, it just changes your team.
Did you try commenting out the line I recommended?
[QUOTE=Deco Da Man;19484049]Did you try commenting out the line I recommended?[/QUOTE] Yes, same error, but it doesn't set my player model.
Okay, I believe it is to do with the fact that the timers are inside of that function? I had put a timer inside of PlayerInitialSpawn and it gave me the same stack overflow. How should I re-write it then? [editline]07:27PM[/editline] [lua] function GM:PlayerSpawn( ply ) local players = #player.GetHumans() if players < 2 then return end ply:CrosshairDisable( true ) self.BaseClass:PlayerSpawn( ply ) ply:SetMaxSpeed( 1 ) ply:SetGravity( 0.75 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 1 ) ply:SetRunSpeed( 1 ) ply:StripWeapons() if ply:Team() == 2 then Spectate( ply ) elseif ply:Team() == 1 then ply:Lock() timer.Simple( 3, spawncar, ply ) end timer.Simple( 1, RaceMsgOne, ply ) timer.Simple( 2, RaceMsgTwo, ply ) timer.Simple( 3, RaceMsgThree, ply ) timer.Simple( 4, RaceMsgGo, ply ) end [/lua]
Comment out self.BaseClass:PlayerSpawn(ply). [editline]07:35PM[/editline] And in line 15, what do you exactly want to do? Did you define the Spectate function?
Yes, it's defined, and commenting that out didn't fix it. And I just want it to turn the player into a spectator.
I've now realized it only happens when the player is in a vehicle.
Sorry, you need to Log In to post a reply to this thread.