(TTT) Script may be crashing server

Can anyone check this script over for me, see if anything looks funny.



if SERVER then

hook.Add("TTTEndRound", "PRDM", function()

	-- Initializing/default values PRDM winner vars
	prdmWinner = ""
	prdmWinnerKC = 0
	prdmWinnerENT = ""
	
	
	-- Setting PRDM kill counts back to 0
	for k, v in pairs(player.GetAll()) do
		v:SetFrags(0)
		v:SetHealth(100)
	end
	
	-- Setting PRDM state
	prdmState = true
	prdmRespawn()

	-- PRDM respawn
	timer.Create("RespawnTimer", 3, 9, function()
		prdmRespawn()
	end )
end )

hook.Add("TTTPrepareRound", "EndPRDM", function()
	
	-- Set PRDM state
	prdmState = false
	
	-- Make sure timers stop
	timer.Remove("RespawnTimer")
	
	-- Check kill counts and find winner
	for k, v in pairs(player.GetAll()) do
		if v:Frags() > prdmWinnerKC then
			prdmWinnerKC = v:Frags()
			prdmWinner = v:Name()
			prdmWinnerENT = v
		end
	end
	
	-- Print out winner and winner's kills
	timer.Simple(3, function()
		-- If winner got more than 1 kill
		if prdmWinnerKC > 1 then
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, prdmWinner .. " won ", WF_TC_WHITE, "PRDM with ", WF_TC_RED, prdmWinnerKC .. " kills", WF_TC_WHITE, "!")
			end
			--PrintMessage( HUD_PRINTTALK, prdmWinner .. " won PRDM with " .. prdmWinnerKC .. " kills!" )
		-- If winner only got 1 kill
		elseif prdmWinnerKC == 1 then
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, prdmWinner .. " won ", WF_TC_WHITE, "PRDM with ", WF_TC_RED, prdmWinnerKC .. " kill", WF_TC_WHITE, "!")
			end
			--PrintMessage( HUD_PRINTTALK, prdmWinner .. " won PRDM with " .. prdmWinnerKC .. " kill!" )
		-- If no one won PRDM
		else
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, "No one won ", WF_TC_WHITE, "PRDM!")
			end
			--PrintMessage( HUD_PRINTTALK, "No one won PRDM!" )
		end
		-- Give winner points. 1 kill = 25 points
		prdmWinnerENT:PS_Notify("You've been given ", (25 * prdmWinnerKC), " points for winning PRDM!")
		prdmWinnerENT:PS_GivePoints(25 * prdmWinnerKC)
	end )

end )

hook.Add("PlayerDeath", "PrintDeaths", function(victim, weapon, attacker)
	
	-- Check if PRDM and attacker and victim are players and valid
	if prdmState == true and IsValid(victim) and IsValid(attacker) and victim:IsPlayer() and attacker:IsPlayer() then
		
		-- Suicide
		if (victim == attacker) then
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, victim:Name(), WF_TC_WHITE, " commited suicide.")
			end
			--PrintMessage( HUD_PRINTTALK, victim:Name() .. " committed suicide." )
		-- Actual kill
		else
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, victim:Name(), WF_TC_WHITE, " was killed by ", WF_TC_RED, attacker:Name(), WF_TC_WHITE, ".")
			end
			--PrintMessage( HUD_PRINTTALK, victim:Name() .. " was killed by " .. attacker:Name() .. "." )
			-- Frag checker. Use if broken somehow
			--attacker:ChatPrint(attacker:Frags() + 1)
			attacker:AddFrags(1)
		end
		
	end
	
end )

function prdmRespawn()
	--RunConsoleCommand("ulx", "csay", "It's post-round deathmatch time!")
		for k, v in pairs(player.GetAll()) do
			
			-- Intializing random weapon vars
			local randWepCategory = math.random(1,100)
			local randPistol = math.random(1,100)
			local randRifle = math.random(1,100)
			local randSpecial = math.random(1,100)
			local wepID = ""
			local wepName = ""
			
			-- Handling weapon IDs and names
			-- Category: Pistol
			if randWepCategory <= 45 then
				if randPistol <= 50 then
					-- Five-SeveN
					wepID = "pistol"
					wepName = "Five-SeveN"
				elseif randPistol > 50 and randPistol <= 75 then
					wepID = "magnum"
					wepName = "Magnum"
				elseif randPistol > 75 then
					-- Deagle
					wepID = "revolver"
					wepName = "Desert Eagle"
				end
			-- Category: Rifle/Shotgun
			elseif randWepCategory > 45 and randWepCategory <= 90 then
				if randRifle <= 10 then
					wepID = "m16"
					wepName = "M16"
				elseif randRifle > 10 and randRifle <= 20 then
					-- Scout
					wepID = "rifle"
					wepName = "Scout"
				elseif randRifle > 20 and randRifle <= 30 then
					wepID = "ak47"
					wepName = "AK47"
				elseif randRifle > 30 and randRifle <= 40 then
					wepID = "galil"
					wepName = "Galil"
				elseif randRifle > 40 and randRifle <= 50 then
					wepID = "famas"
					wepName = "Famas"
				elseif randRifle > 50 and randRifle <= 60 then
					wepID = "m3"
					wepName = "M3"
				elseif randRifle > 60 and randRifle <= 70 then
					wepID = "p90"
					wepName = "P90"
				elseif randRifle > 70 and randRifle <= 80 then
					wepID = "sg552"
					wepName = "SG552"
				elseif randRifle > 80 and randRifle <= 90 then
					-- XM1014
					wepID = "shotgun"
					wepName = "XM1014"
				elseif randRifle > 90 and randRifle <= 100 then
					-- HUGE
					wepID = "sledge"
					wepName = "useless piece of sh- I mean a H.U.G.E-249"
				end
			-- Category: Special
			else
				if randSpecial <= 30 then
					wepID = "awp"
					wepName = "AWP"
				elseif randSpecial > 30 and randSpecial <= 50 then
					wepID = "dragonsbreath"
					wepName = "Dragon's Breath"
				elseif randSpecial > 50 and randSpecial <= 80 then
					wepID = "medgun"
					wepName = "Med-Gun"
				elseif randSpecial > 80 then
					wepID = "jihad"
					wepName = "Bill- I mean a Jihad Bomb"
				end
			end
				
			-- PointShop perma weapon checker
			local permWepCount = v:PS_NumItemsEquippedFromCategory('Weapons')
			
			-- The actual respawn
			if !v:Alive() and IsValid(v) then
				-- Find corpse
				local corpse = corpse_find(v)
				if corpse then corpse_remove(corpse) end
				
				-- RESPAWN
				v:SpawnForRound()
				
				-- Give random weapon
				-- zm IDs
				if permWepCount == 0 then
					if wepID == "pistol" or wepID == "revolver" or wepID == "rifle" or wepID == "shotgun" or wepID == "sledge" then
						v:Give("weapon_zm_" .. wepID)
						v:SelectWeapon("weapon_zm_" .. wepID)
					-- ttt IDs
					else
						v:Give("weapon_ttt_" .. wepID)
						v:SelectWeapon("weapon_ttt_" .. wepID)
					end
					-- Print out weapon received
					v:PrintColor(WF_TC_WHITE, "You've been given a ", WF_TC_RED, wepName, WF_TC_WHITE, "!")
				end
			end
		end
end

end


Would this be causing a crash somehow? My server only tends to crash during end round phases, which is when this script is running.
Before, you ask, it’s not “PrintColor”.

Well, this place isn’t really for a “Here my code, is crash server?”.
Do some debugging, add some prints in different places with different texts.
Try running the server without it e.t.c.
If neither help you then try adding the script back in, in parts, not all at the same time(Obviously in parts that will work independently)

I kindly asked for someone to a do a once-over on my code to check if I did anything that might cause G-Mod to die because it’s outdated. I don’t need to be attacked for that.

Nothing obvious, you’d probably see an error if it was this script screwing up somewhere. Newjorciks was only giving some correct advice.

Your best bet would be to put some prints throughout the script such as at the beginning and end of statements, then when it crashes you should be able to determine the point that it is crashing. If you can see every run made it to the end of the path then it wont be this script.

He wasn’t attacking you, he is correct. Do some debugging and commenting out to find the specific cause of the crash. Also, Garry’s Mod being “outdated” would not be the cause.

If you aren’t interested in trying to debug your code, we should we? We’re all busy people with our own problems, just because he didn’t instantly help you doesn’t mean he was attacking you.

I didn’t tell anyone to debug my code, again I asked for a once-over because G-Mod doesn’t like working correctly with a lot of things.

I didn’t state that his advice was flawed either. “again I asked for a once-over because G-Mod doesn’t like working correctly with a lot of things.”

EDIT:
“Well, this place isn’t really for a “Here my code, is crash server?”.”
If that isn’t attacking me, I don’t know what is. If that wasn’t his intention, then I apologize for misconceiving his words.

[editline]14th January 2017[/editline]

That’s the thing, the server doesn’t always crash at every single end round. Would that mean the script isn’t doing it? I don’t see this happening on any other G-Mod TTT servers.

Likely not.

Do you have many other addons or plugins?

There should be some crash dumps in the server directory, if you upload the latest one to http://dumps.metastruct.uk.to/ you can get some more info on what caused the crash.

I ran a dumbed down version of the script above and my server still crashed. The script isn’t likely to be the issue here.

I have other addons running on my server, along with other custom scripts.

Thanks for the info about the crash dumps, I may possibly be able to get them from my host. Thanks for the assistance too. :stuck_out_tongue:

Also, if you’re interested…here’s a list of the addons: https://gyazo.com/ada1f0fe092f1a3df3eafd166a4c6875

Turns out the script was crashing the server. Hmm. Wonder why.