[lua]
function GM:PlayerDeath(ply,inf,kill)
if (ply.job=="killer") then
ply.job="runner" -- to be on the safe side
NotifyAll("The killer has been killed by " .. kill:Nick(),2)
StartNewRound()
else
local cnt=0
for d,f in pairs(player.GetAll()) do
if (!f:Alive() && f.job == "runner") then
cnt = cnt+1
end
end
print("Living - " .. cnt)
if (cnt==0) then
NotifyAll("All runners have been killed!",2)
StartNewRound()
end
end
end
[/lua]
[lua]
function StartNewRound()
NotifyAll("The round has been restarted!",1)
used = {}
local killer = SelectKiller()
killer.job = "killer"
killer:Spawn()
killer:Notify("You have been selected as a killer!",3)
for a,b in pairs(player.GetAll()) do
if (b != killer) then
b.job = "runner"
b:Spawn()
b:Notify("You have been selected as a runner!",3)
end
end
game.CleanUpMap()
AddSpawnEnts()
end
[/lua]
[lua]
function AddSpawnEnts()
local m = spawns[game.GetMap()]
for a,b in pairs(m['runners']) do
local e = ents.Create("info_runner_spawn")
e:SetPos(b)
e:Spawn()
e:DropToFloor()
end
for a,b in pairs(m['killers']) do
local e = ents.Create("info_killer_spawn")
e:SetPos(b)
e:Spawn()
end
end
[/lua]
When I remove the call for AddSpawnEnts in the second snip of code it runs fine. I need to readd the spawn points as they are removed when I clean up the map. It seems to crash whenever all runners are dead.
[QUOTE=Capatcha;29499828] I need to readd the spawn points as they are removed when I clean up the map.[/QUOTE]
[b][url=http://wiki.garrysmod.com/?title=Game.CleanUpMap]Game.CleanUpMap [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] has a second argument where you can define filters. If you put your ent here, it wont be removed.
[lua]
game.CleanUpMap( false , { "info_runner_spawn" , "info_killer_spawn" } )
[/lua]
Also. Why do you use custom entities for this? All deathrun maps usually have info_player_terrorist and info_player_counterterrorist spawnpoints.
Tyvm!
I changed my code to..
[lua]
function GM:PlayerSelectSpawn(ply)
if (ply.job=="killer") then
local spawns = ents.FindByClass( "info_player_terrorist" )
return table.Random(spawns)
else
local spawns2 = ents.FindByClass( "info_player_counterterrorist" )
return table.Random(spawns2)
end
end
function SelectKiller()
local killer = table.Random(player.GetAll())
return killer
end
function StartNewRound()
game.CleanUpMap()
NotifyAll("The round has been restarted!",1)
used = {}
local killer = SelectKiller()
killer.IsDead = false
killer.job = "killer"
killer:Spawn()
killer:Notify("You have been selected as a killer!",3)
for a,b in pairs(player.GetAll()) do
if (b != killer) then
b.IsDead = false
b.job = "runner"
b:Spawn()
b:Notify("You have been selected as a runner!",3)
end
end
end
function GM:PlayerDeath(ply,inf,kill)
ply.IsDead = true
if (ply.job=="killer") then
ply.job="runner" -- to be on the safe side
NotifyAll("The killer has been killed!",2)
StartNewRound()
else
local cnt = 0
for d,f in pairs(player.GetAll()) do
if (!f.IsDead && f.job == "runner") then
cnt = cnt+1
end
end
if (cnt==0) then
NotifyAll("All runners have been killed!",2)
StartNewRound()
end
end
end
[/lua]
And when someone dies because of water it crashes the server.
Sorry, you need to Log In to post a reply to this thread.