• My round system is not working =(
    4 replies, posted
Hey guys, Lua nab here with another issue... I've been trying hard to make a round system for my gamemode but I'm having very little luck... the game doesn't trigger endround when it's meant to, but when I force it to endround by killing everyone (for some reason that works) a player is left as team 3 if you wanna see what I mean feel free to join the server it's on and look - connect planetnerd.zapto.org anyway here's my code [CODE]function GM:PlayerDeath( ply ) Fatboy = team.NumPlayers ( 1 ) AvgJoe = team.NumPlayers ( 2 ) if Fatboy < 1 then ply:SetTeam( 2 ) timer.Stop("Weightloss") PrintMessage( HUD_PRINTCENTER, "Fatboy is dead, Average Joe's WIN!" ) EndRound() elseif AvgJoe < 1 then PrintMessage( HUD_PRINTCENTER, "All the Average Joe's have been slaughtered, Fatboy wins!" ) EndRound() end if ply:Team() == 2 then ply:SetTeam( 3 ) end end function EndRound() local randomPlayer = table.Random(player.GetAll()) timer.Stop("Weightloss") timer.Stop("Weightloss2") timer.Stop("Weightloss3") game.CleanUpMap() for k, v in pairs(player.GetAll()) do v:StripAmmo() v:StripWeapons() v:SetTeam(2) randomPlayer:SetTeam( 1 ) v:Spawn() end end[/CODE]
Can you paste the full code?
I apologize in advanced for my messy code ;( [CODE]local ply = FindMetaTable("Player") AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) // Serverside only stuff goes here /*--------------------------------------------------------- Name: gamemode:plyLoadout( ) Desc: Give the ply the default spawning weapons/ammo ---------------------------------------------------------*/ function GM:PlayerInitialSpawn( ply ) Fatboy = team.NumPlayers ( 1 ) AvgJoe = team.NumPlayers ( 2 ) local randomPlayer = table.Random(player.GetAll()) if Fatboy >= 1 then ply:SetTeam( 2 ) elseif Fatboy < 1 then randomPlayer:SetTeam( 1 ) end if ply:Team()== 1 then timer.Start("Weightloss") end end function GM:PlayerSpawn( ply ) Fatboy = team.NumPlayers ( 1 ) AvgJoe = team.NumPlayers ( 2 ) local randomPlayer = table.Random(player.GetAll()) if ply:Team()== 1 then timer.Start("Weightloss") timer.Start("Weightloss2") timer.Start("Weightloss3") ply:Give( "knife" ) ply:SetGravity ( 1 ) ply:SetWalkSpeed( 50 ) ply:SetRunSpeed( 50 ) ply:SetMaxHealth( 100000 ) ply:SetHealth( 500*(#player.GetAll())) ply:SetModel("models/player/combine_soldier_prisonguard.mdl") end if ply:Team()== 2 then ply:Give( "weapon_shotgun" ) ply:SetWalkSpeed( 150 ) ply:GiveAmmo( 999, "buckshot", true ) ply:SetRunSpeed( 200 ) ply:SetGravity ( 1 ) ply:SetModel("models/player/Group03/Male_02.mdl") end if ply:Team()== 3 then ply:Give( "Knife" ) ply:SetGravity ( 0.5 ) ply:SetHealth( 1 ) ply:SetWalkSpeed( 300 ) ply:SetRunSpeed( 600 ) ply:SetModel("models/player/charple.mdl") end end function GM:PlayerDeath( ply ) Fatboy = team.NumPlayers ( 1 ) AvgJoe = team.NumPlayers ( 2 ) if Fatboy < 1 then ply:SetTeam( 2 ) PrintMessage( HUD_PRINTCENTER, "Fatboy is dead, Average Joe's WIN!" ) EndRound() elseif AvgJoe < 1 then PrintMessage( HUD_PRINTCENTER, "All the Average Joe's have been slaughtered, Fatboy wins!" ) EndRound() end if ply:Team() == 2 then ply:SetTeam( 3 ) end end function EndRound() local randomPlayer = table.Random(player.GetAll()) timer.Stop("Weightloss") timer.Stop("Weightloss2") timer.Stop("Weightloss3") game.CleanUpMap() for k, v in pairs(player.GetAll()) do v:StripAmmo() v:StripWeapons() v:SetTeam(2) randomPlayer:SetTeam( 1 ) v:Kill() v:Spawn() end end function Weightloss( ply ) if ply:Team()== 1 then ply:SetWalkSpeed(ply:GetWalkSpeed() + 1) ply:SetRunSpeed(ply:GetRunSpeed() + 1) end end function Weightloss2( ply ) if ply:Team() == 1 then PrintMessage( HUD_PRINTCENTER, "Fatboy is losing weight and is gradually getting faster!" ) end end function Weightloss3( ply ) if ply:Team() == 1 then PrintMessage( HUD_PRINTCENTER, "Fatboy has reached optimal weight!" ) end end timer.Create("Weightloss", 2, 85, function() for id, p in pairs(player.GetAll()) do Weightloss( p ) end end ) timer.Create("Weightloss2", 20, 8, function() for id, p in pairs(player.GetAll()) do Weightloss2( p ) end end ) timer.Create("Weightloss3", 170, 1, function() for id, p in pairs(player.GetAll()) do Weightloss3( p ) end end ) function GM:PlayerShouldTakeDamage( ply, victim) if ply:IsPlayer() then if ply:Team() == 1 and victim:Team()== 3 or ply:Team() == victim:Team() or ply:Team() == 3 and victim:Team() == 1 then return false end end return true end [/CODE] and if you're wondering, yes I am trying to remake the classic Halo gamemode ;)
[QUOTE=bungo;46490899]I apologize in advanced for my messy code ;( [CODE]local ply = FindMetaTable("Player") AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) // Serverside only stuff goes here /*--------------------------------------------------------- Name: gamemode:plyLoadout( ) Desc: Give the ply the default spawning weapons/ammo ---------------------------------------------------------*/ function GM:PlayerInitialSpawn( ply ) Fatboy = team.NumPlayers ( 1 ) AvgJoe = team.NumPlayers ( 2 ) local randomPlayer = table.Random(player.GetAll()) if Fatboy >= 1 then ply:SetTeam( 2 ) elseif Fatboy < 1 then randomPlayer:SetTeam( 1 ) end if ply:Team()== 1 then timer.Start("Weightloss") end end function GM:PlayerSpawn( ply ) Fatboy = team.NumPlayers ( 1 ) AvgJoe = team.NumPlayers ( 2 ) local randomPlayer = table.Random(player.GetAll()) if ply:Team()== 1 then timer.Start("Weightloss") timer.Start("Weightloss2") timer.Start("Weightloss3") ply:Give( "knife" ) ply:SetGravity ( 1 ) ply:SetWalkSpeed( 50 ) ply:SetRunSpeed( 50 ) ply:SetMaxHealth( 100000 ) ply:SetHealth( 500*(#player.GetAll())) ply:SetModel("models/player/combine_soldier_prisonguard.mdl") end if ply:Team()== 2 then ply:Give( "weapon_shotgun" ) ply:SetWalkSpeed( 150 ) ply:GiveAmmo( 999, "buckshot", true ) ply:SetRunSpeed( 200 ) ply:SetGravity ( 1 ) ply:SetModel("models/player/Group03/Male_02.mdl") end if ply:Team()== 3 then ply:Give( "Knife" ) ply:SetGravity ( 0.5 ) ply:SetHealth( 1 ) ply:SetWalkSpeed( 300 ) ply:SetRunSpeed( 600 ) ply:SetModel("models/player/charple.mdl") end end function GM:PlayerDeath( ply ) Fatboy = team.NumPlayers ( 1 ) AvgJoe = team.NumPlayers ( 2 ) if Fatboy < 1 then ply:SetTeam( 2 ) PrintMessage( HUD_PRINTCENTER, "Fatboy is dead, Average Joe's WIN!" ) EndRound() elseif AvgJoe < 1 then PrintMessage( HUD_PRINTCENTER, "All the Average Joe's have been slaughtered, Fatboy wins!" ) EndRound() end if ply:Team() == 2 then ply:SetTeam( 3 ) end end function EndRound() local randomPlayer = table.Random(player.GetAll()) timer.Stop("Weightloss") timer.Stop("Weightloss2") timer.Stop("Weightloss3") game.CleanUpMap() for k, v in pairs(player.GetAll()) do v:StripAmmo() v:StripWeapons() v:SetTeam(2) randomPlayer:SetTeam( 1 ) v:Kill() v:Spawn() end end function Weightloss( ply ) if ply:Team()== 1 then ply:SetWalkSpeed(ply:GetWalkSpeed() + 1) ply:SetRunSpeed(ply:GetRunSpeed() + 1) end end function Weightloss2( ply ) if ply:Team() == 1 then PrintMessage( HUD_PRINTCENTER, "Fatboy is losing weight and is gradually getting faster!" ) end end function Weightloss3( ply ) if ply:Team() == 1 then PrintMessage( HUD_PRINTCENTER, "Fatboy has reached optimal weight!" ) end end timer.Create("Weightloss", 2, 85, function() for id, p in pairs(player.GetAll()) do Weightloss( p ) end end ) timer.Create("Weightloss2", 20, 8, function() for id, p in pairs(player.GetAll()) do Weightloss2( p ) end end ) timer.Create("Weightloss3", 170, 1, function() for id, p in pairs(player.GetAll()) do Weightloss3( p ) end end ) function GM:PlayerShouldTakeDamage( ply, victim) if ply:IsPlayer() then if ply:Team() == 1 and victim:Team()== 3 or ply:Team() == victim:Team() or ply:Team() == 3 and victim:Team() == 1 then return false end end return true end [/CODE] and if you're wondering, yes I am trying to remake the classic Halo gamemode ;)[/QUOTE] 1. You shouldn't be using solid GM methods like GM:PlayerDeath instead do [CODE] --Example hook.Add( "PlayerDeath", "This happens on player death ", function( ply ) end) [/CODE] Also you're using [CODE] local ply = FindMetaTable("Player")[/CODE] Use it for a reason so endround should be [CODE]function ply:EndRound( arguments ) end [/CODE]
I've done everything you said, but now when I die my server crashes - in the console it is spamming [IMG]http://i.imgur.com/zwPsQdU.png[/IMG] but, so far thanks for replying - I know it's me doing something stupid...
Sorry, you need to Log In to post a reply to this thread.