• Deathrun fretta
    12 replies, posted
When I play on my friends Deathrun server it happends sometimes that the round just doesn't want to restart. I realy don't know why but could I get help with getting a script getting it auto restarting whenever TEAM_RUN is 0?
Something like this should work. It goes into lua\autorun\server\roundrestart.lua. [lua]hook.Add("Initialize", "End round thing", function() -- Modify this to fit whatever your gamemode is called. if(GAMEMODE.Name ~= "Deathrun") then return; end hook.Add("Think", "End round thing", function() if(#team.GetPlayers(TEAM_RUN) == 0) then GAMEMODE:RoundTimerEnd(); end end); end);[/lua]
Thanks!
Now that I think about it, it wouldn't work properly. Here's an improved version that checks it every five seconds and only works when there's a round running and at least two players. [lua]hook.Add("Initialize", "End round thing", function() -- Modify this to fit whatever your gamemode is called. if(GAMEMODE.Name ~= "Deathrun") then return; end timer.Create("End round thing", 5, 0, function() if(GAMEMODE:InRound() and #player.GetAll() >= 2 and #team.GetPlayers(TEAM_RUN) == 0) then GAMEMODE:RoundTimerEnd(); end end); end);[/lua]
Way better. :) [editline]03:55PM[/editline] Well, didn't work. Same problem :|
Got same problem seems after few people have joined the rounds will go to 0 and the timer will and then after eveyone is dead the round will not restart [editline]01:23PM[/editline] Can have look through this code see if there is anything wrong Init.lua [CODE]DrunMapsWithoutCrowbars = { "deathrun_warehouse_final" } DrunDieSounds = { "vo/npc/Barney/ba_ohshit03.wav", "vo/npc/Barney/ba_no01.wav", "vo/npc/Barney/ba_no02.wav", "vo/npc/male01/no01.wav", "vo/npc/male01/no02.wav" } DrunSawDieSounds = { "vo/npc/male01/gordead_ques01.wav", "vo/npc/male01/gordead_ques02.wav", "vo/npc/male01/gordead_ques06.wav", "vo/npc/male01/gordead_ques07.wav", "vo/npc/male01/gordead_ques11.wav", "vo/npc/Barney/ba_danger02.wav", "vo/npc/Barney/ba_damnit.wav" } AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "cl_init.lua" ) include( 'shared.lua' ) local file_path = "deathrun_weapon_spawns/"..game.GetMap()..".txt" local file_contents = "" local SpawnersPos = {} if file.Exists(file_path) then file_contents = file.Read(file_path) for x, y, z in string.gmatch(file_contents, "(%-?[%d%.]+), (%-?[%d%.]+), (%-?[%d%.]+)\n") do table.insert(SpawnersPos, {x = tonumber(x), y = tonumber(y), z = tonumber(z)}) end end function GM:CanStartRound() if #team.GetPlayers( TEAM_RUN ) + #team.GetPlayers( TEAM_DEATH ) >= 2 then return true end return false end function GM:OnPreRoundStart( num ) game.CleanUpMap() local replacing = {} replacing = table.Add(replacing, ents.FindByClass("weapon_ak47")) replacing = table.Add(replacing, ents.FindByClass("weapon_aug")) replacing = table.Add(replacing, ents.FindByClass("weapon_awp")) replacing = table.Add(replacing, ents.FindByClass("weapon_deagle")) replacing = table.Add(replacing, ents.FindByClass("weapon_elite")) replacing = table.Add(replacing, ents.FindByClass("weapon_glock")) replacing = table.Add(replacing, ents.FindByClass("weapon_m3")) replacing = table.Add(replacing, ents.FindByClass("weapon_m4a1")) replacing = table.Add(replacing, ents.FindByClass("weapon_m249")) replacing = table.Add(replacing, ents.FindByClass("weapon_mp5navy")) replacing = table.Add(replacing, ents.FindByClass("weapon_p90")) replacing = table.Add(replacing, ents.FindByClass("weapon_scout")) replacing = table.Add(replacing, ents.FindByClass("weapon_sg552")) replacing = table.Add(replacing, ents.FindByClass("weapon_usp")) replacing = table.Add(replacing, ents.FindByClass("weapon_xm1014")) for _,wep in ipairs(replacing) do if not SpawnersPos[1] then local spawner = ents.Create("weapon_spawner") spawner:SetPos(wep:GetPos()) spawner:Spawn() end wep:Remove() end for _,pos in ipairs(SpawnersPos) do local spawner = ents.Create("weapon_spawner") spawner:SetPos(Vector(pos.x, pos.y, pos.z)) spawner:Spawn() end local OldRun = team.GetPlayers( TEAM_RUN ) local OldDeath = team.GetPlayers( TEAM_DEATH ) local NrActivePlayers = #OldRun + #OldDeath if NrActivePlayers >= 2 then local NrDeath = math.ceil( NrActivePlayers/10 ) for _,pl in pairs ( OldDeath ) do pl:SetTeam( TEAM_RUN ) end local count=0 for _, pl in RandomPairs( OldRun ) do if count < NrDeath then pl:SetTeam( TEAM_DEATH ) count=count+1 end end for _, pl in RandomPairs( OldDeath ) do if count < NrDeath then pl:SetTeam( TEAM_DEATH ) count=count+1 end end end UTIL_StripAllPlayers() UTIL_SpawnAllPlayers() UTIL_FreezeAllPlayers() end function GM:ProcessResultText( result, resulttext ) if ( resulttext == nil ) then resulttext = "" end if ( result == TEAM_RUN ) then resulttext = "The Runners prevailed!" elseif ( result == TEAM_DEATH ) then resulttext = "Death has triumphed!" end return resulttext end function GM:OnRoundResult( result, resulttext ) self.BaseClass:OnRoundResult( result, resulttext ) if result == TEAM_RUN then umsg.Start("Deathrun - Runners Win", ply) umsg.End() elseif result == TEAM_DEATH then umsg.Start("Deathrun - Death Wins", ply) umsg.End() end end function GM:PlayerUse( pl, ent ) if pl:Alive() and ( pl:Team() == TEAM_DEATH or pl:Team() == TEAM_RUN )then return true else return false end end function GM:GetFallDamage( ply, flFallSpeed ) if ( GAMEMODE.RealisticFallDamage ) then return flFallSpeed / 9 end return 10 end function GM:PlayerDeathSound() return true end function GM:DoPlayerDeath( ply, attacker, dmginfo ) if ply:Team() == TEAM_RUN then ply:EmitSound( DrunDieSounds[math.random(1, #DrunDieSounds)] ) elseif ply:Team() == TEAM_DEATH then ply:EmitSound( DrunDieSounds[math.random(1, #DrunDieSounds)], 90, 80 ) end self.BaseClass:DoPlayerDeath( ply, attacker, dmginfo ) end local LastSawDie_Run = 0 local LastSawDie_Death = 0 function GM:PlayerDeath( ply, inflictor, attacker ) self.BaseClass:PlayerDeath( ply, inflictor, attacker ) local nearby_ents = ents.FindInSphere( ply:GetPos(), 750 ) for _,ent in RandomPairs(nearby_ents) do if ent:IsValid() and ent:IsPlayer() and ent:Alive() and ent:Team() == ply:Team() and ent!=ply then if ent:Team() == TEAM_RUN then if LastSawDie_Run + 5 <= CurTime() then ent:EmitSound( DrunSawDieSounds[math.random(1, #DrunSawDieSounds)] ) LastSawDie_Run = CurTime() end elseif ent:Team() == TEAM_DEATH then if LastSawDie_Death + 5 <= CurTime() then ent:EmitSound( DrunSawDieSounds[math.random(1, #DrunSawDieSounds)], 90, 80 ) LastSawDie_Death = CurTime() end end break end end end concommand.Add("deathrun_weapon_spawner", function(ply) if not ply:IsValid() then return end if not ply:IsSuperAdmin() then return end local pos = ply:GetEyeTrace().HitPos local spawner = ents.Create("weapon_spawner") spawner:SetPos(pos) spawner:Spawn() table.insert(SpawnersPos, {x = pos.x, y = pos.y, z = pos.z}) file_contents = file_contents..pos.x..", "..pos.y..", "..pos.z.."\n" file.Write(file_path, file_contents) end) function GM:PlayerInitialSpawn(ply) RunConsoleCommand("html") if file.Exists( "deathrun/player/kills/" .. ply:UniqueID( ) .. ".txt" ) then ply:SetNWInt( "kills", tonumber( file.Read( "deathrun/player/kills/" .. ply:UniqueID( ) .. ".txt" ) ) ) end if file.Exists( "deathrun/player/deaths/" .. ply:UniqueID( ) .. ".txt" ) then ply:SetNWInt( "deaths", tonumber( file.Read( "deathrun/player/deaths/" .. ply:UniqueID( ) .. ".txt" ) ) ) end end function SaveKillsAndDeaths( ply ) file.Write( "deathrun/player/kills/" .. ply:UniqueID( ) .. ".txt", ply:GetNWInt( "kills" ) ) file.Write( "deathrun/player/deaths/" .. ply:UniqueID( ) .. ".txt", ply:GetNWInt( "deaths" ) ) end concommand.Add( "savekd", SaveKillsAndDeaths ) function DeathKill( victim, killer ) killer:SetNWInt( "kills", tonumber( killer:GetNWInt( "kills" ) ) + 1 ) victim:SetNWInt( "deaths", tonumber( victim:GetNWInt( "deaths" ) ) + 1 ) end hook.Add( "PlayerDeath", "addkilldeath", DeathKill ) self.BaseClass:PlayerInitialSpawn(ply) RunConsoleCommand("html") umsg.Start("DeathRunRules", ply) umsg.End()[/CODE] cl_init.lua [CODE]include( 'shared.lua' ) usermessage.Hook("Deathrun - Runners Win", function() surface.PlaySound("music/HL2_song15.mp3") end) usermessage.Hook("Deathrun - Death Wins", function() surface.PlaySound("music/stingers/HL1_stinger_song8.mp3") end) function DeathRunRules( ) local Frame = vgui.Create( "Frame" ); //Create a frame Frame:SetSize( 500,
init.lua Remove from the bottom [lua] self.BaseClass:PlayerInitialSpawn(ply) RunConsoleCommand("html") umsg.Start("DeathRunRules", ply) umsg.End()[/lua] [lua]function GM:PlayerInitialSpawn(ply) RunConsoleCommand("html")-- remove this if file.Exists( "deathrun/player/kills/" .. ply:UniqueID( ) .. ".txt" ) then ply:SetNWInt( "kills", tonumber( file.Read( "deathrun/player/kills/" .. ply:UniqueID( ) .. ".txt" ) ) ) end if file.Exists( "deathrun/player/deaths/" .. ply:UniqueID( ) .. ".txt" ) then ply:SetNWInt( "deaths", tonumber( file.Read( "deathrun/player/deaths/" .. ply:UniqueID( ) .. ".txt" ) ) ) end end [/lua] Change the RunConsoleCommand("html") -- remove this bit with [lua] ply:ConCommand("html") [/lua] So you don't send it to everyone when they're playing.
well lots better now for html just still getting the round not ending also for some reason player can spawn as connected/joining and run around
Force them to spectate in PlayerInitialSpawn. :smile: I thought they already spectate in fretta anyway?
they did but after update 93 everything seemed get messed up fixed The spawns now just Round end bug which is the main problem
Yeah this is the initial problem that we've been trying to fix, but struggled that's why we're here trying to fix the problem.
[QUOTE=Doubleedge;24063124]Yeah this is the initial problem that we've been trying to fix, but struggled that's why we're here trying to fix the problem.[/QUOTE] [lua]function GM:PlayerInitialSpawn(ply) ply:ConCommand("html") ply:KillSilent() ply:Spectate( OBS_MODE_CHASE ) ply:SpectateEntity( player.GetAll()[1] ) if file.Exists( "deathrun/player/kills/" .. ply:UniqueID( ) .. ".txt" ) then ply:SetNWInt( "kills", tonumber( file.Read( "deathrun/player/kills/" .. ply:UniqueID( ) .. ".txt" ) ) ) end if file.Exists( "deathrun/player/deaths/" .. ply:UniqueID( ) .. ".txt" ) then ply:SetNWInt( "deaths", tonumber( file.Read( "deathrun/player/deaths/" .. ply:UniqueID( ) .. ".txt" ) ) ) end end [/lua]
doesnt fix it also now the players stated spawning as connectors again add me steam jaythorpe al show you what i mean
Sorry, you need to Log In to post a reply to this thread.