Gamemode Scripting- Issues With Looping And Timers
0 replies, posted
Hi everybody. I tested my gamemode out earlier today and it is throwing these errors in the console:
[ERROR] gamemodes/michaelmyers/gamemode/shared.lua:32: attempt to call method 'SetTeam' (a nil value)
1. Begin - gamemodes/michaelmyers/gamemode/shared.lua:32
2. unknown - gamemodes/michaelmyers/gamemode/shared.lua:55
Timer Failed! [round.Handle][@gamemodes/michaelmyers/gamemode/shared.lua (line 71)]
The timer is put in place for the round to restart and run the roundBegin() function but after the first go, it doesn't seem to properly run.
The SetTeam error occurs when trying to force every player via a for loop to join team 2 at the beginning of the round. Code is below.
[CODE]
//Round system
round = {}
round.Break = 5 -- time in between rounds (seconds)
round.Time = 30 -- length of rounds (seconds)
round.TimeLeft = -1
round.Breaking = false
function round.Broadcast(Text)
for k, v in pairs(player.GetAll()) do
v:ConCommand("play buttons/button17.wav")
v:ChatPrint(Text)
end
end
function round.Begin()
game.CleanUpMap()
// Loops through each player and forces them to be on Runners to prevent multiple Myers from previous rounds & strips weapons
for k, ply in pairs( player.GetAll() ) do
ply:SetTeam( 2 )
ply:StripWeapons()
end
// Picks a random player and makes them Michael Myers for the round
randomply = table.Random(player.GetAll())
randomply:SetTeam( 1 )
// Loops through each player and tells them who Michael Myers is for the round
for k, ply in pairs( player.GetAll() ) do
ply:ChatPrint(randomply:Nick() .. " is Michael Myers!")
end
round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
round.TimeLeft = round.Time
end
function round.End()
round.Broadcast("Round over! Next round in " .. round.Break .. " seconds!")
round.TimeLeft = round.Break
end
function round.Handle()
if (round.TimeLeft == -1) then
round.Begin()
return
end
round.TimeLeft = round.TimeLeft - 1
if (round.TimeLeft == 0) then
if (round.Breaking) then
round.Begin()
round.Breaking = false
else
round.End()
round.Breaking = true
end
end
end
timer.Create("round.Handle", 1, 0, round.Handle)
[/CODE]
Any help is greatly appreciated!
[editline]1st July 2015[/editline]
Shameful bump. I really need help. I've been stuck with this for hours now.
[editline]1st July 2015[/editline]
Please. I need help.
Sorry, you need to Log In to post a reply to this thread.