Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GAMEMODE.Rounds={}
- GAMEMODE.Rounds.CurRound=0
- GAMEMODE.Rounds.Paused=false
- GAMEMODE.Rounds.SqrtVal=1
- GAMEMODE.Rounds.TimeStarted=CurTime()
- GAMEMODE.Rounds.TimeToEnd=-1
- GAMEMODE.Rounds.Waiting=false
- GAMEMODE.Rounds.HasSpawnedBoss=false
- GAMEMODE.Rounds.SpecialRounds={}
- GAMEMODE.Rounds.BossBattles={}
- local nextSpawnTime=0
- function AddSpecialRound(num, spawnfunc) -- Adds to spawning code, or overrides if a value is returned
- if !num or !spawnfunc then return end
- num=math.floor(num)
- GAMEMODE.Rounds.SpecialRounds[num]=function()
- spawnfunc()
- hook.Call("SpecialRoundStarted", GM, GetCurrentRound())
- end
- end
- AddSpecialRound(5, function()
- if CountEnemies()<(GetMaxEnemies()*2) and nextSpawnTime<CurTime() then
- nextSpawnTime=CurTime()+0.5
- local spawnpos=PickRandomSpawnpoint()
- if spawnpos then
- CreateZombie(spawnpos)
- print("Spawning zombie...")
- end
- return true
- end
- end)
- AddSpecialRound(10, function()
- if CountEnemies()<(GetMaxEnemies()*2) and nextSpawnTime<CurTime() then
- nextSpawnTime=CurTime()+0.5
- local spawnpos=PickRandomSpawnpoint()
- if spawnpos then
- CreateAntlion(spawnpos)
- print("Spawning antlion...")
- end
- return true
- end
- end)
- AddSpecialRound(15, function()
- if (GetCurrentRound()==10) and !GAMEMODE.Rounds.HasSpawnedBoss then
- nextSpawnTime=CurTime()+0.5
- local spawnpos=PickRandomStriderSpawnpoint()
- GAMEMODE.Rounds.HasSpawnedBoss=true
- if spawnpos then
- CreateStrider(spawnpos)
- end
- end
- end)
- function ResetRound()
- GAMEMODE.Rounds.CurRound=0
- GAMEMODE.Rounds.SqrtVal=1
- GAMEMODE.Rounds.TimeStarted=CurTime()
- GAMEMODE.Rounds.TimeToEnd=-1
- GAMEMODE.Rounds.Waiting=false
- GAMEMODE.Rounds.HasSpawnedBoss=false
- for f, v in pairs(player.GetAll()) do
- v:SetTeam(TEAM_REBEL)
- v:Spawn()
- end
- if GAMEMODE.Rounds.CurRound==0 and GAMEMODE.Rounds.SqrtVal==1 and GAMEMODE.Rounds.TimeToEnd==-1 and !GAMEMODE.Rounds.Waiting then
- return true;
- else
- return false;
- end
- end
- function StartRound(num, cl)
- if table.Count(player.GetAll())==0 then
- return ResetRound();
- end
- if !cl then
- EndWaiting()
- GAMEMODE.Rounds.HasSpawnedBoss=false
- for f, v in pairs(player.GetAll()) do
- v:SetHealth(100)
- end
- num=num or GAMEMODE.Rounds.CurRound+1
- num=math.floor(num)
- GAMEMODE.Rounds.SqrtVal=math.sqrt(num)
- print("Starting round "..num.."!")
- GAMEMODE.Rounds.Waiting=false
- GAMEMODE.Rounds.CurRound=num
- GAMEMODE.Rounds.TimeStarted=CurTime()
- GAMEMODE.Rounds.TimeToEnd=CurTime()+30*(math.floor(GAMEMODE.Rounds.SqrtVal))
- hook.Call("RoundStarted", GM, num)
- end
- if ValidEntity(cl) then
- umsg.Start("roundData", cl)
- else
- umsg.Start("roundData")
- end
- umsg.Long(GAMEMODE.Rounds.CurRound)
- umsg.Long(GAMEMODE.Rounds.TimeStarted)
- umsg.Long(GAMEMODE.Rounds.TimeToEnd)
- umsg.End()
- end
- function CleanupEnemies()
- for f, v in pairs(GAMEMODE.Enemies) do
- for k, ent in pairs(v) do
- if ValidEntity(ent) then
- if ent.Kill then
- ent:Kill()
- else
- ent:Remove()
- end
- end
- end
- end
- end
- function GetCurrentRound()
- return GAMEMODE.Rounds.CurRound
- end
- function GetRoundStartTime()
- return GAMEMODE.Rounds.TimeStarted
- end
- function GetRoundEndTime()
- return GAMEMODE.Rounds.TimeToEnd
- end
- function GetMaxEnemies()
- return math.floor(GAMEMODE.Rounds.SqrtVal*10)
- end
- function CheckRoundOver()
- return (GAMEMODE.Rounds.TimeToEnd!=(-1)) and CurTime()>GAMEMODE.Rounds.TimeToEnd
- end
- function GetWaiting()
- return GAMEMODE.Rounds.Waiting
- end
- function StartWaiting(num)
- for f, v in pairs(player.GetAll()) do
- v:SetHealth(100)
- end
- if num then
- GAMEMODE.Rounds.CurRound=num-1
- end
- GAMEMODE.Rounds.Waiting=true
- GAMEMODE.Rounds.TimeStarted=CurTime()+60
- SendUserMessage("roundWaiting", RecipientFilter():AddAllPlayers(), true, GAMEMODE.Rounds.TimeStarted)
- end
- function EndWaiting()
- GAMEMODE.Rounds.Waiting=false
- SendUserMessage("roundWaiting", RecipientFilter():AddAllPlayers(), false, GAMEMODE.Rounds.TimeStarted)
- end
- function GetPaused()
- return GAMEMODE.Rounds.IsPaused or false
- end
- function SetPaused(bool)
- if bool or bool==false then
- GAMEMODE.Rounds.IsPaused=bool or false
- end
- end
- concommand.Add("cs_pause", function(ply)
- if !ply:IsPlayer() or ply:IsAdmin() then
- SetPaused(true)
- end
- end)
- concommand.Add("cs_resume", function(ply)
- if !ply:IsPlayer() or ply:IsAdmin() then
- SetPaused(false)
- StartWaiting()
- end
- end)
- /*
- if (GetCurrentRound()==5) then
- if CountEnemies()<(GetMaxEnemies()*2) and nextSpawnTime<CurTime() then
- nextSpawnTime=CurTime()+0.5
- local spawnpos=PickRandomSpawnpoint()
- if spawnpos then
- CreateZombie(spawnpos)
- print("Spawning zombie...")
- end
- end
- return
- end
- if (GetCurrentRound()==10) and !GAMEMODE.Rounds.HasSpawnedBoss then
- nextSpawnTime=CurTime()+0.5
- local spawnpos=PickRandomStriderSpawnpoint()
- GAMEMODE.Rounds.HasSpawnedBoss=true
- if spawnpos then
- CreateStrider(spawnpos)
- end
- end
- */
- function SpawnEnemies()
- if !GAMEMODE.Rounds.SpecialRounds[GetCurrentRound()] or !GAMEMODE.Rounds.SpecialRounds[GetCurrentRound()]() then
- if CountEnemies()<GetMaxEnemies() and nextSpawnTime<CurTime() then
- nextSpawnTime=CurTime()+0.5
- local spawnpos=PickRandomSpawnpoint()
- local shouldSpawn=true
- for f, v in pairs(player.GetAll()) do
- local tracedata = {}
- tracedata.start = v:EyePos()
- tracedata.endpos = spawnpos
- tracedata.filter = player.GetAll()
- local trace=util.TraceLine(tracedata)
- --PrintTable(trace)
- if trace.Hit and trace.HitPos:Distance(spawnpos)<10 then
- shouldSpawn=false
- end
- print(shouldSpawn)
- end
- if spawnpos and shouldSpawn then
- local perc=math.random(0, 100)
- if perc>80 then
- CreateScanner(spawnpos)
- print("Spawning a scanner!")
- elseif perc>60 then
- CreateManhack(spawnpos)
- print("Spawning a manhack!")
- else
- CreateCombineSoldier(spawnpos)
- print("Spawning a soldier!")
- end
- end
- end
- end
- end
- hook.Add("Think", "runRoundCode", function()
- if table.Count(team.GetPlayers(TEAM_REBEL))==0 then return end
- if GAMEMODE.Rounds.Waiting and CurTime()>GetRoundStartTime() then
- if GetPaused() then
- if !GetWaiting() then
- StartWaiting()
- end
- return
- else
- EndWaiting()
- StartRound()
- end
- end
- if CurTime()>GetRoundEndTime() and !GetWaiting() and CountEnemies()<1 then
- hook.Call("RoundEnded", GM, GetCurrentRound())
- StartWaiting()
- elseif CurTime()<GetRoundEndTime() and !(GetWaiting()) then
- SpawnEnemies()
- elseif (GetRoundStartTime()+120)<CurTime() and !(!GAMEMODE.Rounds.SpecialRounds[GetCurrentRound()] or !GAMEMODE.Rounds.SpecialRounds[GetCurrentRound()]()) then
- CleanupEnemies()
- StartRound()
- end
- end)
- concommand.Add("cs_cleanup", function(ply, cmd, args)
- if !ply:IsPlayer() or ply:IsAdmin() then
- CleanupEnemies()
- end
- end)
- concommand.Add("cs_forcestartround", function(ply, cmd, args)
- if !ply:IsPlayer() or ply:IsAdmin() then
- CleanupEnemies()
- for f, v in pairs(player.GetAll()) do
- v:SendLua("game.RemoveRagdolls()")
- end
- if args[1] and tonumber(args[1]) then
- StartRound(tonumber(args[1]))
- else
- StartRound()
- end
- end
- end)
- /*hook.Add("PlayerDeath", "checkAllPlayersDead", function(ply, inf, att)
- ply:SetTeam(TEAM_SPECTATOR)
- ply:Spectate(OBS_MODE_ROAMING)
- timer.Simple(1, function()
- if table.Count(team.GetPlayers(TEAM_REBEL))==0 then
- game.CleanUpMap()
- for f, v in pairs(player.GetAll()) do
- v:UnSpectate()
- v:SetTeam(TEAM_REBEL)
- v:Spawn()
- StartWaiting(1)
- end
- end
- end)
- end)
- hook.Add("CharacterLoaded", "StartRoundWhenLoaded", function(ply)
- if table.Count(player.GetAll()==1) then
- StartWaiting(1)
- else
- StartRound(1, ply)
- end
- end)*/
- hook.Add("PlayerDisconnected", "cleanupOnDisconnect", function(ply)
- if table.Count(player.GetAll())==0 then
- game.CleanUpMap()
- ResetRound()
- StartWaiting()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment