need help cusomizing a player respawn script

The Details of the respawn script are going ot be in a link here in a minute but first let me expalin what we want to change in the functions.
1#We want to not get sent back to spawn if our charcters are not dead dead players spawn back at start
2#We have a working Purge timer that is in synq with the gamemodes timer however we need it to rest the pruge timer by calling this particualr file at the end of every round to start over. here is the script.


util.AddNetworkString("RoundState")
GM.GameState = GAMEMODE and GAMEMODE.GameState or 1

--
-- Game States
-- 0 = Waiting for players to join
-- 1 = Building Phase
-- 2 = purge Phase
-- 3 = Fight Phase
-- 4 = Reset Phase
--

-- 
function GM:GetGameState()
	return self.GameState
end

function GM:SetGameState(state)
	self.GameState = state
end

function GM:GetStateStart()
	return self.StateStart
end

function GM:GetStateRunningTime()
	return CurTime() - self.StateStart
end

local tNextThink = 0
function GM:TimerController()
	if CurTime() >= tNextThink then
		if self:GetGameState() == 0 then
			self:CheckPhase()
		elseif self:GetGameState() == 1 then
			self:BuildPhase()
		elseif self:GetGameState() == 2 then
			self:purgePhase()
		elseif self:GetGameState() == 3 then
			self:FightPhase()
		elseif self:GetGameState() == 4 then
			self:ResetPhase()
		end

		local gState = self:GetGameState() -- Because gamestate was nil every other way -_-
		net.Start("RoundState")
			net.WriteFloat(gState)
			net.WriteFloat(purge_buildTime)
			net.WriteFloat(purge_purgeTime)
			net.WriteFloat(purge_fightTime)
			net.WriteFloat(purge_resetTime)
		net.Broadcast()

		tNextThink = CurTime() + 1
	end
end

function GM:CheckPhase()
	local count = 0
	for _, v in pairs(player.GetAll()) do
		if IsValid(v) and v:Alive() then
			count = count + 1
		end
	end

	if count >= 2 then
		-- Time to build
		self:SetGameState(1)

		-- Clean the map, game is about to start
		self:CleanupMap()

		-- Respawn all the players
		for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				v:Spawn()
			end
		end
	end
end

function GM:BuildPhase()
	if purge_buildTime <= 0 then
		-- Time to purge
		self:SetGameState(2) 
resource.AddFile( "sound/purge/thepurge.mp3" )

		-- Nobody can respawn now
		for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				v:SetCanRespawn(false)
			end
		end

		-- Prep phase two
		for _, v in pairs(self:GetActivePlayers()) do
			v:StripWeapons()
			v:RemoveAllAmmo()
			v:SetHealth(100)
			v:SetArmor(0)
		end

		-- Remove teh shitty windows that are above players.
		for _, v in pairs(ents.FindByClass("func_breakable")) do
			v:Fire("Break", "", 0)
		end

		-- Unfreeze everything
		for _, v in pairs(ents.GetAll()) do
			if IsValid(v) then
				local phys = v:GetPhysicsObject()
			
				if phys:IsValid() then 
					phys:EnableMotion(false)
					phys:Wake()
				end
			end
		end

		-- Raise the water
		self:RiseAllWaterControllers()
	else
		purge_buildTime = purge_buildTime - 1
	end
end

function GM:purgePhase()
	if purge_purgeTime <= 0 then
		-- Time to Kill
		self:SetGameState(3)

		-- Its time to fight!
		self:GivePlayerWeapons()
	else  
		purge_purgeTime = purge_purgeTime - 1
	end
end

function GM:FightPhase()
	if purge_fightTime <= 0 then
		-- Time to Reset
		self:SetGameState(4)

		-- Lower Water
		self:LowerAllWaterControllers()

		-- Declare winner is nobody because time ran out
		self:DeclareWinner(3)
	else  
		purge_fightTime = purge_fightTime - 1
		self:ParticipationBonus()
	end
end

function GM:ResetPhase()
	if purge_resetTime <= 0 then
		-- Time to wait for players (if players exist, should go to build phase)
		self:SetGameState(0) 

		-- Give people their money
		self:RefundAllProps()

		-- Game is over, lets tidy up the players
		for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				v:SetCanRespawn(true)

				-- Wait till they respawn
				timer.Simple(0, function()
					v:StripWeapons()
					v:RemoveAllAmmo()
					v:SetHealth(100)
					v:SetArmor(0)

					timer.Simple(0, function()
						v:Give("gmod_tool")
						v:Give("weapon_physgun")
						v:Give("purge_propseller")

						v:SelectWeapon("weapon_physgun")
					end)
				end)
			end
		end

		-- Reset all the round timers
		self:ResetAllTimers()
	else  
		purge_resetTime = purge_resetTime - 1
	end	
end

function GM:InitializeRoundController()
	purge_buildTime = GetConVar("purge_build_time"):GetFloat()
	purge_purgeTime = GetConVar("purge_purge_time"):GetFloat()
	purge_fightTime = GetConVar("purge_fight_time"):GetFloat()
	purge_resetTime = GetConVar("purge_reset_time"):GetFloat()

	hook.Add("Think", "purge_TimeController", function() hook.Call("TimerController", GAMEMODE) end)
end

function GM:ResetAllTimers()
	purge_buildTime = GetConVar("purge_build_time"):GetFloat()
	purge_purgeTime = GetConVar("purge_purge_time"):GetFloat()
	purge_fightTime = GetConVar("purge_fight_time"):GetFloat()
	purge_resetTime = GetConVar("purge_reset_time"):GetFloat()
end

any help will be greatly apreciated and a 25 dollar reward for the person whos script works :smiley: payment via paypal.

About the “Dont send players which are alive back to spawn” just check for them if they’re alive or not.

and I dont understand the 2nd quesiton?

the second question im abit confused on myself you see the coder who wrote this thinks that we need to insert somewhere a function to call for a another script file but we aren’t entirelysure

and about the “About the “Dont send players which are alive back to spawn” just check for them if they’re alive or not.” can you show me where I need to fix that on my script

[editline]17th August 2015[/editline]

Essentially I am posting my teams work online as the one who is in charge of posting to forums while they diligently work on the issue I mentioned to them what you were on about but they cant seem to find the line number or know what needs to be changed could you give me a code example?



for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				if !v:Alive() then
                                    v:Spawn()
                                end
			end
		end


ok thanks man

hey i talked to the guys and when they switchd that line of code for that one it started creating errors in a different file or did they not put it in the right place.

dead players respawn back at start
alive players were spawning back at start at end of round when we jut added that line

shut up with your spam

Then you probably coded it wrong, you can test it yourself by making an addon and overwriding the playerspawn stuff.

so does it replace line 164 to line 167 which is this


 for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				v:SetCanRespawn(true)

correct and when we tested that the round would not start and we get script errors. if we dont replace anything and add that it simply does not do anything because im assuming it needs to replace that line. of code. cause it cant run both im just curious could it posibly be because of my othre file which is where the error code is coming from sv_rounds.lua i can share that if you need me too

[editline]18th August 2015[/editline]

Ok so if you can help me fix this problem ill give you in particular 50$ for helping me out just add me on steam and ill pay you through paypal when we get it working :slight_smile: since it may take more tweaking


function GM:CheckPhase()
	local count = 0
	for _, v in pairs(player.GetAll()) do
		if IsValid(v) and v:Alive() then
			count = count + 1
		end
	end

	if count >= 2 then
		-- Time to build
		self:SetGameState(1)

		-- Clean the map, game is about to start
		self:CleanupMap()

		-- Respawn all the players
		for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
                                if !v:Alive() then -- check if the given ply is alive
                                        v:Spawn()
                                end
			end
		end
	end
end

Ok so after i worked for a while with whitestar to try and fix this is what we came up with the only problem so far is it gets stuck in the waiting for players phase all other issues right now are unsure of till this script gets checked again but this i what i have so far


util.AddNetworkString("RoundState")
GM.GameState = GAMEMODE and GAMEMODE.GameState or 1

--
-- Game States
-- 0 = Waiting for players to join
-- 1 = Building Phase
-- 2 = purge Phase
-- 3 = Fight Phase
-- 4 = Reset Phase
--

-- 
function GM:GetGameState()
	return self.GameState
end

function GM:SetGameState(state)
	self.GameState = state
end

function GM:GetStateStart()
	return self.StateStart
end

function GM:GetStateRunningTime()
	return CurTime() - self.StateStart
end

local tNextThink = 0
function GM:TimerController()
	if CurTime() >= tNextThink then
		if self:GetGameState() == 0 then
			self:CheckPhase()
		elseif self:GetGameState() == 1 then
			self:BuildPhase()
		elseif self:GetGameState() == 2 then
			self:purgePhase()
		elseif self:GetGameState() == 3 then
			self:FightPhase()
		elseif self:GetGameState() == 4 then
			self:ResetPhase()
		end

		local gState = self:GetGameState() -- Because gamestate was nil every other way -_-
		net.Start("RoundState")
			net.WriteFloat(gState)
			net.WriteFloat(purge_buildTime)
			net.WriteFloat(purge_purgeTime)
			net.WriteFloat(purge_fightTime)
			net.WriteFloat(purge_resetTime)
		net.Broadcast()

		tNextThink = CurTime() + 1
	end
end

function GM:CheckPhase()
	local count = 0
	for _, v in pairs(player.GetAll()) do
		if IsValid(v) and v:Alive() then
			count = count + 1
		end
	end
end

	if count >= 1 then
		-- Time to build
		self:SetGameState(1)

		-- Clean the map, game is about to start
		self:CleanupMap()

		-- Respawn all the players
		for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				v:Spawn()
			end
		end
	end
end

function GM:BuildPhase()
	if purge_buildTime <= 0 then
		-- Time to purge
		self:SetGameState(2) 
resource.AddFile( "sound/purge/thepurge.mp3" )

		-- Nobody can respawn now
		for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				v:SetCanRespawn(false)
			end
		end

		-- Prep phase two
		for _, v in pairs(self:GetActivePlayers()) do
			v:StripWeapons()
			v:RemoveAllAmmo()
			v:SetHealth(100)
			v:SetArmor(0)
		end

		-- Remove teh shitty windows that are above players.
		for _, v in pairs(ents.FindByClass("func_breakable")) do
			v:Fire("Break", "", 0)
		end

		-- Unfreeze everything
		for _, v in pairs(ents.GetAll()) do
			if IsValid(v) then
				local phys = v:GetPhysicsObject()
			
				if phys:IsValid() then 
					phys:EnableMotion(false)
					phys:Wake()
				end
			end
		end

		-- Raise the water
		self:RiseAllWaterControllers()
	else
		purge_buildTime = purge_buildTime - 1
	end
end

function GM:purgePhase()
	if purge_purgeTime <= 0 then
		-- Time to Kill
		self:SetGameState(3)

		-- Its time to fight!
		self:GivePlayerWeapons()
	else  
		purge_purgeTime = purge_purgeTime - 1
	end
end

function GM:FightPhase()
	if purge_fightTime <= 0 then
		-- Time to Reset
		self:SetGameState(4)

		-- Lower Water
		self:LowerAllWaterControllers()

		-- Declare winner is nobody because time ran out
		self:DeclareWinner(3)
	else  
		purge_fightTime = purge_fightTime - 1
		self:ParticipationBonus()
	end
end

function GM:ResetPhase()
	if purge_resetTime <= 0 then
		-- Time to wait for players (if players exist, should go to build phase)
		self:SetGameState(0) 

		-- Give people their money
		self:RefundAllProps()

		-- Game is over, lets tidy up the players
		for _, v in pairs(player.GetAll()) do
			if IsValid(v) then
				v:SetCanRespawn(true)

				-- Wait till they respawn
				timer.Simple(0, function()
					v:StripWeapons()
					v:RemoveAllAmmo()
					v:SetHealth(100)
					v:SetArmor(0)

					timer.Simple(0, function()
						v:Give("gmod_tool")
						v:Give("weapon_physgun")
						v:Give("purge_propseller")

						v:SelectWeapon("weapon_physgun")
					end)
				end)
			end
		end

		-- Reset all the round timers
		self:ResetAllTimers()
	else  
		purge_resetTime = purge_resetTime - 1
	end	
end

function GM:InitializeRoundController()
	purge_buildTime = GetConVar("purge_build_time"):GetFloat()
	purge_purgeTime = GetConVar("purge_purge_time"):GetFloat()
	purge_fightTime = GetConVar("purge_fight_time"):GetFloat()
	purge_resetTime = GetConVar("purge_reset_time"):GetFloat()

	hook.Add("Think", "purge_TimeController", function() hook.Call("TimerController", GAMEMODE) end)
end

function GM:ResetAllTimers()
	purge_buildTime = GetConVar("purge_build_time"):GetFloat()
	purge_purgeTime = GetConVar("purge_purge_time"):GetFloat()
	purge_fightTime = GetConVar("purge_fight_time"):GetFloat()
	purge_resetTime = GetConVar("purge_reset_time"):GetFloat()
end

[editline]18th August 2015[/editline]

has been updated