• [Help] Server Bug (Gamemode Changing)
    5 replies, posted
Hi, I'm experiencing a bug on my server, that happens at random times whenever the gamemode/mapvote comes up. The server pretty much just freezes at the voting screen. The gamemode is 'PropHunt'. Heres what the server console tells me: [CODE][ERROR] gamemodes/fretta/gamemode/sv_gmchanger.lua:37: attempt to index a nil value 1. GetNumberOfGamemodeMaps - gamemodes/fretta/gamemode/sv_gmchanger.lua:37 2. StartMapVote - gamemodes/fretta/gamemode/sv_gmchanger.lua:263 3. unknown - gamemodes/fretta/gamemode/sv_gmchanger.lua:327 Timer Failed! [Simple][@gamemodes/fretta/gamemode/sv_gmchanger.lua (line 327)] [/CODE] After a while, the voting screen goes away, and when a player tries to join a team, the game doesn't start or spawn them. I'm new at working with Garry's Mod servers, and with .lua, still trying to figure it all out. Used to host CS:GO servers before, and it's kinda the same, but not really. I would really appreciate some help :dogwow: Thanks! -[I]Koga73[/I]. [editline]16th May 2016[/editline] [code]/* sv_gmchanger.lua - Gamemode Changer (server side) ----------------------------------------------------- Most of the internal stuff for the votes is here and contains stuff you really don't want to override. */ local g_PlayableGamemodes = {} fretta_votesneeded = CreateConVar( "fretta_votesneeded", "0.75", { FCVAR_ARCHIVE } ) fretta_votetime = CreateConVar( "fretta_votetime", "20", { FCVAR_ARCHIVE } ) fretta_votegraceperiod = CreateConVar( "fretta_votegraceperiod", "30", { FCVAR_ARCHIVE } ) local function SendAvailableGamemodes( ply ) net.Start("PlayableGamemodes") net.WriteTable(g_PlayableGamemodes) net.Send(ply) end function GetRandomGamemodeName() return table.Random( g_PlayableGamemodes ).name end function GetRandomGamemodeMap( gm ) return table.Random( g_PlayableGamemodes[ gm or GAMEMODE.FolderName ].maps ) end function GetNumberOfGamemodeMaps( gm ) return table.Count( g_PlayableGamemodes[ gm or GAMEMODE.FolderName ].maps ) end hook.Add( "PlayerInitialSpawn", "SendAvailableGamemodes", SendAvailableGamemodes ) local AllMaps = file.Find( "maps/*.bsp", "GAME" ) for key, map in pairs( AllMaps ) do AllMaps[ key ] = string.gsub( map, ".bsp", "" ) end local GameModes = engine.GetGamemodes() for _, gm in pairs( engine.GetGamemodes() ) do local info = file.Read( "gamemodes/"..gm.name.."/"..gm.name..".txt", "MOD" ) if ( info ) then local info = util.KeyValuesToTable( info ) if ( info.selectable == 1 ) then g_PlayableGamemodes[ gm.name ] = {} g_PlayableGamemodes[ gm.name ].name = gm.title g_PlayableGamemodes[ gm.name ].label = info.title g_PlayableGamemodes[ gm.name ].description = info.description g_PlayableGamemodes[ gm.name ].author = info.author_name g_PlayableGamemodes[ gm.name ].authorurl = info.author_url g_PlayableGamemodes[ gm.name ].maps = {} if ( info.fretta_maps ) then for _, mapname in pairs( AllMaps ) do mapname = string.lower(mapname) for _, p in pairs( info.fretta_maps ) do if ( string.sub( mapname, 1, #p ) == p ) then table.insert( g_PlayableGamemodes[ gm.name ].maps, mapname ) end end end else g_PlayableGamemodes[ gm.name ].maps = AllMaps end if ( info.fretta_maps_disallow ) then for key, mapname in pairs( g_PlayableGamemodes[ gm.name ].maps ) do mapname = string.lower(mapname) for _, p in pairs( info.fretta_maps_disallow ) do if ( string.sub( mapname, 1, #p ) == p ) then g_PlayableGamemodes[ gm.name ].maps[ key ] = nil end end end end end end end GameModes = nil function GM:IsValidGamemode( gamemode, map ) if ( g_PlayableGamemodes[ gamemode ] == nil ) then return false end if ( map == nil ) then return true end for _, mapname in pairs( g_PlayableGamemodes[ gamemode ].maps ) do if ( mapname == map ) then return true end end return false end local gVotes = {} function GM:VotePlayGamemode( ply, gamemode ) if ( !gamemode ) then return end if ( GAMEMODE.WinningGamemode ) then return end if ( !GAMEMODE:InGamemodeVote() ) then return end if ( !GAMEMODE:IsValidGamemode( gamemode ) ) then return end ply:SetNWString( "Wants", gamemode ) end concommand.Add( "votegamemode", function( pl, cmd, args ) GAMEMODE:VotePlayGamemode( pl, args[1] ) end ) function GM:VotePlayMap( ply, map ) if ( !map ) then return end if ( !GAMEMODE.WinningGamemode ) then return end if ( !GAMEMODE:InGamemodeVote() ) then return end if ( !GAMEMODE:IsValidGamemode( GAMEMODE.WinningGamemode, map ) ) then return end ply:SetNWString( "Wants", map ) end concommand.Add( "votemap", function( pl, cmd, args ) GAMEMODE:VotePlayMap( pl, args[1] ) end ) function GM:GetFractionOfPlayersThatWantChange() local Humans = player.GetHumans() local NumHumans = #Humans local WantsChange = 0 for k, player in pairs( Humans ) do if ( player:GetNWBool( "WantsVote" ) ) then WantsChange = WantsChange + 1 end // Don't count players that aren't connected yet if ( !player:IsConnected() ) then NumHumans = NumHumans - 1 end end local fraction = WantsChange / NumHumans return fraction, NumHumans, WantsChange end function GM:GetVotesNeededForChange() local Fraction, NumHumans, WantsChange = GAMEMODE:GetFractionOfPlayersThatWantChange() local FractionNeeded = fretta_votesneeded:GetFloat() local VotesNeeded = math.ceil( FractionNeeded * NumHumans ) return VotesNeeded - WantsChange end function GM:CountVotesForChange() if ( CurTime() >= GetConVarNumber( "fretta_votegraceperiod" ) ) then // can't vote too early on if ( GAMEMODE:InGamemodeVote() ) then return end fraction = GAMEMODE:GetFractionOfPlayersThatWantChange() if ( fraction > fretta_votesneeded:GetFloat() ) then GAMEMODE:StartGamemodeVote() return false end end return true end function GM:VoteForChange( ply ) if ( GetConVarNumber( "fretta_voting" ) == 0 ) then return end if ( ply:GetNWBool( "WantsVote" ) ) then return end ply:SetNWBool( "WantsVote", true ) local VotesNeeded = GAMEMODE:GetVotesNeededForChange() local NeedTxt = "" if ( VotesNeeded > 0 ) then NeedTxt = ", Color( 80, 255, 50 ), [[ (need "..VotesNeeded.." more) ]] " end if ( CurTime() < GetConVarNumber( "fretta_votegraceperiod" ) ) then // can't vote too early on local timediff = math.Round( GetConVarNumber( "fretta_votegraceperiod" ) - CurTime() ); BroadcastLua( "chat.AddText( Entity("..ply:EntIndex().."), Color( 255, 255, 255 ), [[ voted to change the gamemode]] )" ) else BroadcastLua( "chat.AddText( Entity("..ply:EntIndex().."), Color( 255, 255, 255 ), [[ voted to change the gamemode]] "..NeedTxt.." )" ) end Msg( ply:Nick() .. " voted to change the gamemode\n" ) timer.Simple( 5, function() GAMEMODE:CountVotesForChange() end ) end concommand.Add( "VoteForChange", function( pl, cmd, args ) GAMEMODE:VoteForChange( pl ) end ) timer.Create( "VoteForChangeThink", 10, 0, function() if ( GAMEMODE ) then GAMEMODE.CountVotesForChange( GAMEMODE ) end end ) function GM:ClearPlayerWants() for k, ply in pairs( player.GetAll() ) do ply:SetNWString( "Wants", "" ) end end function GM:StartGamemodeVote() if( !GAMEMODE.m_bVotingStarted ) then if ( fretta_voting:GetBool() ) then GAMEMODE:ClearPlayerWants() BroadcastLua( "GAMEMODE:ShowGamemodeChooser()" ); SetGlobalBool( "InGamemodeVote", true ) else GAMEMODE.WinningGamemode = GAMEMODE.FolderName return GAMEMODE:StartMapVote() end timer.Simple( fretta_votetime:GetFloat(), function() GAMEMODE:FinishGamemodeVote( true ) end ) SetGlobalFloat( "VoteEndTime", CurTime() + fretta_votetime:GetFloat() ) GAMEMODE.m_bVotingStarted = true; end end function GM:StartMapVote() // If there's only one map, let the 'random map' thing choose it if ( G
g_PlayableGamemodes[whatever].maps is nil.
[QUOTE=code_gs;50334378]g_PlayableGamemodes[whatever].maps is nil.[/QUOTE] Sorry, might need a little help here, what can/should i do with this? g_PlayableGamemodes[ gm.name ].maps[ key ] = nil
I think this bug happens whenever no one is voting.
Anyone who can help a mate out? :-)
[QUOTE=Koga73;50350670]Anyone who can help a mate out? :-)[/QUOTE] Make some debug prints, check where things are called, when. When the vote ends or whenever it errors, print the amount of players voted. If that is the case, do a check and end the vote.
Sorry, you need to Log In to post a reply to this thread.