Server crashing

My server is crashing with no errors. I’m writing a gamemode and fixed some functions that were being called incorrectly, and now the server crashes when a player dies.

I’m not sure what’s causing it. I’ve tried throwing debug.Trace()'s at the start of all of my functions and server is printing nothing.

How can I figure out what’s crashing the game?

Could you post all of your custom PlayerDeath and related functions and hooks?

Uh, yea I can, but I’m not certain if it’s the player DYING that’s causing it, or the subsequent “round end” shit that’s causing it.

[editline]11th November 2017[/editline]



hook.Add( "PostPlayerDeath", "fullteameliminationchecker", function( vic, info, att )
    debug.Trace() --Is not print before server crash
    print("PostPlayerDeath hook called") --Is not print before server crash
    GAMEMODE:RoundCheck( vic )
end )



function GM:RoundCheck( lostPly )
    debug.Trace() --Is not print before server crash
    print("GM:RoundCheck called ") --Is not print before server crash
    --PrintTable(team.GetAllTeams())
    if not self.gameInProgress or not self.roundInProgress then return end

    table.Empty(self.alivePlayers[1])
    table.Empty(self.alivePlayers[2])
    table.Empty(self.alivePlayers[3])
    for teamNumber, teamData in pairs( team.GetAllTeams() ) do
        for key, ply in pairs(team.GetPlayers(teamNumber)) do
            if (teamNumber == 1 or teamNumber == 2 or teamNumber == 3) and ply:Alive() then
                table.insert(self.alivePlayers[teamNumber], ply)
            end
        end
    end

    if self.soloMode then
        if #self.alivePlayers[3] == 1 then
            self:RoundEnd(3)
            return
        end
    end

    if #self.alivePlayers[lostPly:Team()] > 1 then
        return
    elseif #self.alivePlayers[lostPly:Team()] == 1 then
        net.Start( "LastAlive" )
        net.Send(self.alivePlayers[lostPly:Team()])
    elseif #self.alivePlayers[lostPly:Team()] == 0 then
        if lostPly:Team() == 1 and #self.alivePlayers[2] > 0 then
            self:RoundEnd(2)
            return
        elseif lostPly:Team() == 2 and #self.alivePlayers[1] > 0 then
            self:RoundEnd(1)
            return
        end
        self:RoundEnd(0)
    end
end




--Game finishes, restart round if needed and deliver rewards
function GM:RoundEnd( roundVictor )
    debug.Trace() --Is not print before server crash
    print("GM:RoundEnd called") --Is not print before server crash
    if timer.Exists( "Time Countdown" ) then
        timer.Remove( "Time Countdown" )
    end
    
    self.winningTeam = roundVictor
    self.winningTeamColor = Color(0, 0, 0)
    self.roundInProgress = false

    if roundvictor == 1 then
        self.redTeam.Wins = self.redTeam.Wins + 1
        self.winningTeamName = team.GetName( 1 )
        self.winningTeamColor = Color( 100, 15, 15 )

        for k, v in pairs( team.GetPlayers( 1 ) ) do
            self:AddRewards( v, SCORECOUNTS.ROUND_WON )
        end
        for k, v in pairs( team.GetPlayers( 2 ) ) do
            self:AddRewards( v, SCORECOUNTS.ROUND_LOST )
        end
    elseif roundvictor == 2 then
        self.blueTeamWins = self.blueTeamWins + 1
        self.winningTeamName = team.GetName( 2 )
        self.winningTeamColor = Color( 30, 80, 180 )

        for k, v in pairs( team.GetPlayers( 1 ) ) do
            self:AddRewards( v, SCORECOUNTS.ROUND_LOST )
        end
        for k, v in pairs( team.GetPlayers( 2 ) ) do
            self:AddRewards( v, SCORECOUNTS.ROUND_WON )
        end
    end
    --ULib.tsayColor( nil, true, GAMEMODE.winningTeamColor, GAMEMODE.winningTeamName, Color( 255, 255, 255 ), " has won round " .. GAMEMODE.Round .. "." )

    if self:IsGameWon() then --Might need to add "winner" parameter
        print( "Game has been won" ) --Is not print before server crash
        self.gameType = nil
        self.gameInProgress = false
        self.roundInProgress = false
        SetGlobalInt( "RoundTime", 0 )

        hook.Call( "GameEnd", self, roundvictor )
        net.Start( "GameEnd" )
            net.WriteString( tostring( roundvictor ) )
        net.Broadcast()
        --ULib.tsayColor( nil, true, winnercolor, winnername, Color( 255, 255, 255 ), " has won the game." )

        for k, v in pairs( team.GetPlayers( roundvictor ) ) do
            self:AddRewards( v, SCORECOUNTS.GAME_WON )
        end
        if roundvictor == 1 then losingteam = 2 elseif roundvictor == 2 then losingteam = 1 end
        for k, v in pairs( team.GetPlayers( losingteam ) ) do
            self:AddRewards( v, SCORECOUNTS.GAME_LOST )
        end
    else
        debug.Trace() --Is not print before server crash
        print( "Nobody's won the game yet." ) --Is not print before server crash
        timer.Simple( 15, function()
            self:StartRound( self.Round + 1 )
        end )
        local leadingteam
        if self.redTeam.Wins > self.blueTeam.Wins then leadingteam = 1 elseif self.blueTeam.Wins > self.redTeam.Wins then leadingteam = 2 else leadingteam = 0 end
        hook.Call( "RoundEnd", self, round, roundvictor, leadingteam )
        net.Start( "RoundEnd" )
            net.WriteString( tostring( roundvictor ) )
            net.WriteString( tostring( leadingteam ) )
        net.Broadcast()
    end
end




function GM:IsGameWon()
    debug.Trace() --Is not print before server crash
    if self.redTeam.Wins >= self.modes[self.gameType].Rounds or self.blueTeam.Wins >= self.modes[self.gameType].Rounds then
        return true
    end
    return false
end


I realize after copy+pasting all of the " --Is not print before server crash" that I mis-spelled printed. Oh well.

If you have comments to make about my style, I’m open to them. Otherwise, I think this is all of the code that is ran with player death that I think would cause a crash.

Something I should point out is that I have hooks and net messages named the same thing. Is that bad? I figured it wouldn’t matter because their different but I’m the one with the problem here, so…

Big 'ol bump-eroo, because I’m still entirely unable to find what the problem is and need as much help as possible.

Could it be that I’m using hooks and net messages with the same name?

[editline]13th November 2017[/editline]

I do have a minor update:

It is not killing the player that is causing the crashing. It is my own, written functions running the server into the ground. After commenting out "GAMEMODE:RoundCheck(vic) in the PostPlayerDeath hook, I can kill bots aplenty.