aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/game_rounds.lua
diff options
context:
space:
mode:
authorApickx <Apickx@cogarr.org>2015-12-28 19:10:44 -0500
committerApickx <Apickx@cogarr.org>2015-12-28 19:10:44 -0500
commit5c4ebc932d8c02522802c842d43d863d89aca162 (patch)
tree6be7ad664bdf060127e6df6baa72beaf508aa149 /gamemode/shared/game_rounds.lua
downloadwintersurvival2-5c4ebc932d8c02522802c842d43d863d89aca162.tar.gz
wintersurvival2-5c4ebc932d8c02522802c842d43d863d89aca162.tar.bz2
wintersurvival2-5c4ebc932d8c02522802c842d43d863d89aca162.zip
Initial commit
Diffstat (limited to 'gamemode/shared/game_rounds.lua')
-rw-r--r--gamemode/shared/game_rounds.lua105
1 files changed, 105 insertions, 0 deletions
diff --git a/gamemode/shared/game_rounds.lua b/gamemode/shared/game_rounds.lua
new file mode 100644
index 0000000..67b77c9
--- /dev/null
+++ b/gamemode/shared/game_rounds.lua
@@ -0,0 +1,105 @@
+local meta = FindMetaTable("Player")
+local Time = 10
+
+if (SERVER) then
+ util.AddNetworkString("RoundStart")
+
+ function GM:StartCountDown()
+ self.CountDown = CurTime()+Time+1
+
+ //items to clean up in between rounds
+ cleanup = {
+ "ws_alter",
+ "ws_arrow",
+ "ws_barrel",
+ "ws_campfire",
+ "ws_grave",
+ "ws_infuser",
+ "ws_item",
+ "ws_prop",
+ "ws_researchtable",
+ "ws_shop",
+ "ws_rune",
+ }
+ for k,v in pairs(cleanup) do
+ for i,j in pairs(ents.FindByClass(v)) do
+ j:Remove()
+ end
+ end
+
+
+
+ --Generate a completly new rain of props :D
+ self:GeneratePropRain()
+
+ net.Start("RoundStart")
+ net.WriteUInt(Time,8)
+ net.Broadcast()
+ end
+
+ function meta:UpdateRoundTimer()
+ if (!self.CountDown or self.CountDown<CurTime()) then return end
+
+ net.Start("RoundStart")
+ net.WriteUInt(math.floor(self.CountDown-CurTime()),8)
+ net.Send(self)
+ end
+ hasprinted = false
+ hook.Add("Tick","CountDowner",function()
+ if (GAMEMODE.GameOn) then
+ if (#player.GetAll() < 2) then
+ --TODO: Less than 2 players in the server
+ GAMEMODE.CountDown = nil
+ GAMEMODE.GameOn = false
+ return
+ elseif (#player.GetAllHumans() < 2) then
+ GAMEMODE.CountDown = nil
+ GAMEMODE.GameOn = false
+ for k,v in pairs(player.GetAllHumans()) do
+ v:AddAccountItem(table.Random(GetItemsByClass("account")).Name,1)
+ end
+
+ timer.Simple(Time,function() for k,v in pairs(player.GetAllHumans()) do v:Kill() end end)
+
+ GAMEMODE:StartCountDown()
+ return
+ end
+ else
+ if(!hasprinted) then
+ for k,v in pairs(player.GetAll()) do
+ v:ChatPrint("Winter survival requires 2 players or more to play")
+ v:ChatPrint("Invite a friend!")
+ end
+ hasprinted = true
+ end
+ end
+
+ if (GAMEMODE.GameOn or !GAMEMODE.CountDown) then return end
+
+ if (GAMEMODE.CountDown < CurTime()) then
+ print("Test2")
+ if (#player.GetAll() < 2) then
+ GAMEMODE.CountDown = CurTime()+Time+1
+ return
+ end
+
+ for k,v in pairs(player.GetAll()) do
+ if (v:IsPigeon()) then
+ if (IsValid(v.Pigeon)) then v.Pigeon:Remove() end
+ v:SetHuman(true)
+ v:KillSilent()
+
+ timer.Simple(1,function() if (IsValid(v) and !v:Alive()) then v:Spawn() end end)
+ end
+ end
+
+ GAMEMODE.GameOn = true
+ end
+ end)
+else
+ net.Receive("RoundStart",function() GAMEMODE.CountDown = CurTime()+net.ReadUInt(8) end)
+end
+
+function GetCountDown()
+ return GAMEMODE.CountDown
+end