How would I make game rounds? Every 10 minutes, everyone dies, then a 10 second intermission, then it restarts again.
Here it is a round system I was working on a couple of months ago, it is not complete but it gives you a rough idea of a round system
[lua]
if CLIENT then
local function TimerStatus()
timetowrite = “Round Finished”
end
usermessage.Hook(“TimerStatus”, TimerStatus)
function ReceiveTime( um )
roundtime = um:ReadShort()
timetowrite = "Time: " … string.ToMinutesSeconds(tostring(roundtime))
end
usermessage.Hook(“SendTime”, ReceiveTime)
function DrawTime()
draw.SimpleText(timetowrite, “HUDNumber5”, ScrW() / 2, 20, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
hook.Add(“HUDPaint”, “DrawTime”, DrawTime)
end
if SERVER then
roundtime = 600
function RoundTime()
roundtime = roundtime - 1
umsg.Start(“SendTime”)
umsg.Short(roundtime)
umsg.End()
if roundtime == 0 then
umsg.Start(“TimerStatus”)
umsg.End()
end
if roundtime == 0 then
for _, ply in pairs(player.GetAll()) do
ply:StripWeapons()
ply:StripAmmo()
end
end
end
timer.Create(“RoundTimer”, 1, 60, RoundTime)
end
[/lua]
If you don’t specify a second argument in umsg.Start, it just sends the usermessage to all players. There’s no need for a RecipientFilter in this case.
Fixed, thanks!
Thanks Loures, you answered my next question too! Which was how to add it to the HUD.
[editline]03:03PM[/editline]
I can’t figure out how to add intermission time, can someone help?
What do you mean with intermission time, the time between a round finishing and another one starting?
Yup. Like, after the round ends, there’s a 10 second timer, then a new round starts again.
There you go
[lua]
if CLIENT then
local function TimerStatus()
timetowrite = “Starting new round”
end
usermessage.Hook(“TimerStatus”, TimerStatus)
function ReceiveTime( um )
roundtime = um:ReadShort()
timetowrite = "Time: " … string.ToMinutesSeconds(tostring(roundtime))
end
usermessage.Hook(“SendTime”, ReceiveTime)
function DrawTime()
draw.SimpleText(timetowrite, “HUDNumber5”, ScrW() / 2, 20, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
hook.Add(“HUDPaint”, “DrawTime”, DrawTime)
end
if SERVER then
roundtime = 600
intermissiontime = 10
function IntermissionTime()
if intermissiontime == 0 then
roundtime = 600
timer.Start(“RoundTimer”)
timer.Stop(“IntermissionTime”)
end
–Do other stuff here (this function gets run each seconds of the intermission time)
function RoundTime()
roundtime = roundtime - 1
umsg.Start(“SendTime”)
umsg.Short(roundtime)
umsg.End()
if roundtime == 0 then
umsg.Start(“TimerStatus”)
umsg.End()
end
if roundtime == 0 then
for _, ply in pairs(player.GetAll()) do
ply:StripWeapons()
ply:StripAmmo()
end
if not timer.IsTimer("IntermissionTime") then
timer.Create("IntermissionTime", 1, intermissiontime, IntermissionTime)
else timer.Start("IntermissionTime")
end
timer.Stop("RoundTimer")
end
end
timer.Create(“RoundTimer”, 1, roundtime, RoundTime)
end
[/lua]
100th post! :cheers:
Doesn’t work… You forgot an end, which I added. But now the round doesn’t even end.
Ohh fuck it… I’ll go for a fix tomorrow, or you can try to fix it by yourself (trying to code at midnight gives such results)
Ok, thanks. I have been looking at it for a while, and cannot find a fix it.
Can anyone fix this?
Fixed
[lua]
if CLIENT then
local function TimerStatus()
timetowrite = “Round Finished”
end
usermessage.Hook(“TimerStatus”, TimerStatus)
function ReceiveTime( um )
roundtime = um:ReadShort()
timetowrite = "Time: " … string.ToMinutesSeconds(tostring(roundtime))
end
usermessage.Hook(“SendTime”, ReceiveTime)
function DrawTime()
draw.SimpleText(timetowrite, “HUDNumber5”, ScrW() / 2, 20, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
hook.Add(“HUDPaint”, “DrawTime”, DrawTime)
end
if SERVER then
roundtime = 600
local function SetupNewRound()
timer.Simple(10, function()
roundtime = 600
timer.Start(“RoundTimer”)
end)
end
function RoundTime()
roundtime = roundtime - 1
umsg.Start(“SendTime”)
umsg.Short(roundtime)
umsg.End()
if roundtime == 0 then
umsg.Start(“TimerStatus”)
umsg.End()
for _, ply in pairs(player.GetAll()) do
ply:StripWeapons()
ply:StripAmmo()
end
SetupNewRound()
end
end
timer.Create(“RoundTimer”, 1, roundtime, RoundTime)
end
[/lua]
Thank you, it works now.