Raised This Month: $32 Target: $400
 8% 

Solved [L4D2] Match Vote: error in logs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tank Rush
Senior Member
Join Date: May 2019
Location: Argentina
Old 11-22-2021 , 19:28   [L4D2] Match Vote: error in logs
Reply With Quote #1

I have this error in logs, can you help me?
Code:
L 11/21/2021 - 23:33:52: SourceMod error session started
L 11/21/2021 - 23:33:52: Info (map "c2m1_highway") (file "D:\Program Files\Steam\steamapps\common\Left 4 Dead 2\left4dead2\addons\sourcemod\logs\errors_20211121.log")
L 11/21/2021 - 23:33:52: [SM] Exception reported: Invalid convar handle 21d0209 (error 3)
L 11/21/2021 - 23:33:52: [SM] Blaming: match_vote.smx
L 11/21/2021 - 23:33:52: [SM] Call stack trace:
L 11/21/2021 - 23:33:52: [SM]   [0] SetConVarInt
L 11/21/2021 - 23:33:52: [SM]   [1] Line 68, D:\Program Files\Steam\steamapps\common\Left 4 Dead 2\left4dead2\addons\sourcemod\scripting\match_vote.sp::OnPluginEnd
L 11/21/2021 - 23:33:52: Error log file session closed.
Here is the code:
PHP Code:
#include <sourcemod>
#include <builtinvotes>
//get here: https://forums.alliedmods.net/showthread.php?t=162164

#undef REQUIRE_PLUGIN
#include <confogl>
#include <colors>
#define REQUIRE_PLUGIN
//get proper version here: https://bitbucket.org/vintik/confogl-old

#define L4D_TEAM_SPECTATE    1
#define MATCHMODES_PATH        "configs/matchmodes.txt"

new Handle:g_hVote;
new 
Handle:g_hModesKV;
new 
Handle:g_hCvarPlayerLimit;
new 
Handle:g_hMaxPlayers;
new 
Handle:g_hSvMaxPlayers;
new 
String:g_sCfg[32];
new 
bool:g_bIsConfoglAvailable;
new 
bool:OnSet

public Plugin:myinfo 
{
    
name "Match Vote",
    
author "vintik, Sir",
    
description "!match !rmatch - Change Hostname and Slots while you're at it!",
    
version "1.1.3",
    
url "https://bitbucket.org/vintik/various-plugins"
}

public 
OnPluginStart()
{
    
decl String:sBuffer[128];
    
GetGameFolderName(sBuffersizeof(sBuffer));
    if (!
StrEqual(sBuffer"left4dead2"false))
    {
        
SetFailState("Plugin supports Left 4 dead 2 only!");
    }
    
g_hModesKV CreateKeyValues("MatchModes");
    
BuildPath(Path_SMsBuffersizeof(sBuffer), MATCHMODES_PATH);
    if (!
FileToKeyValues(g_hModesKVsBuffer))
    {
        
SetFailState("Couldn't load matchmodes.txt!");
    }
    
    
g_hSvMaxPlayers FindConVar("sv_maxplayers");
    
g_hMaxPlayers CreateConVar("mv_maxplayers""30""How many slots would you like the Server to be at Config Load/Unload?");
    
RegConsoleCmd("sm_match"MatchRequest);
    
RegConsoleCmd("sm_rmatch"MatchReset);
    
    
g_hCvarPlayerLimit CreateConVar("sm_match_player_limit""1""Minimum # of players in game to start the vote");
    
g_bIsConfoglAvailable LibraryExists("confogl");
}

public 
OnConfigsExecuted()
{
    if (!
OnSet)
    {
        
SetConVarInt(g_hSvMaxPlayersGetConVarInt(g_hMaxPlayers));
        
OnSet true;
    }
}

public 
OnPluginEnd()
{
    
SetConVarInt(g_hSvMaxPlayersGetConVarInt(g_hMaxPlayers));
}

public 
OnLibraryRemoved(const String:name[])
{
    if (
StrEqual(name"confogl")) g_bIsConfoglAvailable false;
}

public 
OnLibraryAdded(const String:name[])
{
    if (
StrEqual(name"confogl")) g_bIsConfoglAvailable true;
}

public 
Action:MatchRequest(clientargs)
{
    if ((!
client) || (!g_bIsConfoglAvailable)) return Plugin_Handled;
    if (
args 0)
    {
        
//config specified
        
new String:sCfg[64], String:sName[64];
        
GetCmdArg(1sCfgsizeof(sCfg));
        if (
FindConfigName(sCfgsNamesizeof(sName)))
        {
            if (
StartMatchVote(clientsName))
            {
                
strcopy(g_sCfgsizeof(g_sCfg), sCfg);
                
//caller is voting for
                
FakeClientCommand(client"Vote Yes");
            }
            return 
Plugin_Handled;
        }
    }
    
//show main menu
    
MatchModeMenu(client);
    return 
Plugin_Handled;
}

bool:FindConfigName(const String:cfg[], String:name[], maxlength)
{
    
KvRewind(g_hModesKV);
    if (
KvGotoFirstSubKey(g_hModesKV))
    {
        do
        {
            if (
KvJumpToKey(g_hModesKVcfg))
            {
                
KvGetString(g_hModesKV"name"namemaxlength);
                return 
true;
            }
        } while (
KvGotoNextKey(g_hModesKVfalse));
    }
    return 
false;
}

MatchModeMenu(client)
{
    new 
Handle:hMenu CreateMenu(MatchModeMenuHandler);
    
SetMenuTitle(hMenu"Select match mode:");
    new 
String:sBuffer[64];
    
KvRewind(g_hModesKV);
    if (
KvGotoFirstSubKey(g_hModesKV))
    {
        do
        {
            
KvGetSectionName(g_hModesKVsBuffersizeof(sBuffer));
            
AddMenuItem(hMenusBuffersBuffer);
        } while (
KvGotoNextKey(g_hModesKVfalse));
    }
    
DisplayMenu(hMenuclient20);
}

public 
MatchModeMenuHandler(Handle:menuMenuAction:actionparam1param2)
{
    if (
action == MenuAction_Select)
    {
        new 
String:sInfo[64], String:sBuffer[64];
        
GetMenuItem(menuparam2sInfosizeof(sInfo));
        
KvRewind(g_hModesKV);
        if (
KvJumpToKey(g_hModesKVsInfo) && KvGotoFirstSubKey(g_hModesKV))
        {
            new 
Handle:hMenu CreateMenu(ConfigsMenuHandler);
            
Format(sBuffersizeof(sBuffer), "Select %s config:"sInfo);
            
SetMenuTitle(hMenusBuffer);
            do
            {
                
KvGetSectionName(g_hModesKVsInfosizeof(sInfo));
                
KvGetString(g_hModesKV"name"sBuffersizeof(sBuffer));
                
AddMenuItem(hMenusInfosBuffer);
            } while (
KvGotoNextKey(g_hModesKV));
            
DisplayMenu(hMenuparam120);
        }
        else
        {
            
CPrintToChat(param1"{blue}[{default}Match{blue}] {default}No configs for such mode were found.");
            
MatchModeMenu(param1);
        }
    }
    if (
action == MenuAction_End)
    {
        
CloseHandle(menu);
    }
}

public 
ConfigsMenuHandler(Handle:menuMenuAction:actionparam1param2)
{
    if (
action == MenuAction_Select)
    {
        new 
String:sInfo[64], String:sBuffer[64];
        
GetMenuItem(menuparam2sInfosizeof(sInfo), _sBuffersizeof(sBuffer));
        if (
StartMatchVote(param1sBuffer))
        {
            
strcopy(g_sCfgsizeof(g_sCfg), sInfo);
            
//caller is voting for
            
FakeClientCommand(param1"Vote Yes");
        }
        else
        {
            
MatchModeMenu(param1);
        }
    }
    if (
action == MenuAction_End)
    {
        
CloseHandle(menu);
    }
    if (
action == MenuAction_Cancel)
    {
        
MatchModeMenu(param1);
    }
}

bool:StartMatchVote(client, const String:cfgname[])
{
    if (
GetClientTeam(client) == L4D_TEAM_SPECTATE)
    {
        
CPrintToChat(client"{blue}[{default}Match{blue}] {default}Match voting isn't allowed for spectators.");
        return 
false;
    }
    if (
LGO_IsMatchModeLoaded())
    {
        
CPrintToChat(client"{blue}[{default}Match{blue}] {default}Matchmode already loaded!");
        return 
false;
    }
    if (!
IsBuiltinVoteInProgress())
    {
        new 
iNumPlayers;
        
decl iPlayers[MaxClients];
        
//list of non-spectators players
        
for (new i=1i<=MaxClientsi++)
        {
            if (!
IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) == L4D_TEAM_SPECTATE))
            {
                continue;
            }
            
iPlayers[iNumPlayers++] = i;
        }
        if (
iNumPlayers GetConVarInt(g_hCvarPlayerLimit))
        {
            
CPrintToChat(client"{blue}[{default}Match{blue}] {default}Match vote cannot be started. Not enough players.");
            return 
false;
        }
        new 
String:sBuffer[64];
        
g_hVote CreateBuiltinVote(VoteActionHandlerBuiltinVoteType_Custom_YesNoBuiltinVoteAction_Cancel BuiltinVoteAction_VoteEnd BuiltinVoteAction_End);
        
Format(sBuffersizeof(sBuffer), "Load confogl '%s' config?"cfgname);
        
SetBuiltinVoteArgument(g_hVotesBuffer);
        
SetBuiltinVoteInitiator(g_hVoteclient);
        
SetBuiltinVoteResultCallback(g_hVoteMatchVoteResultHandler);
        
DisplayBuiltinVote(g_hVoteiPlayersiNumPlayers20);
        return 
true;
    }
    
CPrintToChat(client"{blue}[{default}Match{blue}] {default}Match vote cannot be started now.");
    return 
false;
}

public 
VoteActionHandler(Handle:voteBuiltinVoteAction:actionparam1param2)
{
    switch (
action)
    {
        case 
BuiltinVoteAction_End:
        {
            
g_hVote INVALID_HANDLE;
            
CloseHandle(vote);
        }
        case 
BuiltinVoteAction_Cancel:
        {
            
DisplayBuiltinVoteFail(voteBuiltinVoteFailReason:param1);
        }
    }
}

public 
void MatchVoteResultHandler(Handle voteint num_votesint num_clients, const int[][] client_infoint num_items, const int[][] item_info)
{
    for (new 
i=0i<num_itemsi++)
    {
        if (
item_info[i][BUILTINVOTEINFO_ITEM_INDEX] == BUILTINVOTES_VOTE_YES)
        {
            if (
item_info[i][BUILTINVOTEINFO_ITEM_VOTES] > (num_votes 2))
            {
                
DisplayBuiltinVotePass(vote"Matchmode Loaded");
                
ServerCommand("sm_forcematch %s"g_sCfg);
                return;
            }
        }
    }
    
DisplayBuiltinVoteFail(voteBuiltinVoteFail_Loses);
}

public 
Action:MatchReset(clientargs)
{
    if ((!
client) || (!g_bIsConfoglAvailable)) return Plugin_Handled;
    
//voting for resetmatch
    
StartResetMatchVote(client);
    return 
Plugin_Handled;
}

StartResetMatchVote(client)
{
    if (
GetClientTeam(client) == L4D_TEAM_SPECTATE)
    {
        
CPrintToChat(client"{blue}[{default}Match{blue}] {default}Resetmatch voting isn't allowed for spectators.");
        return;
    }
    if (!
LGO_IsMatchModeLoaded())
    {
        
CPrintToChat(client"{blue}[{default}Match{blue}] {default}No matchmode loaded.");
        return;
    }
    if (
IsNewBuiltinVoteAllowed())
    {
        new 
iNumPlayers;
        
decl iPlayers[MaxClients];
        for (new 
i=1i<=MaxClientsi++)
        {
            if (!
IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) == L4D_TEAM_SPECTATE))
            {
                continue;
            }
            
iPlayers[iNumPlayers++] = i;
        }
        if (
ConnectingPlayers() > 0)
        {
            
CPrintToChat(client"{blue}[{default}Match{blue}] {default}Resetmatch vote cannot be started. Players are connecting");
            return;
        }
        
g_hVote CreateBuiltinVote(VoteActionHandlerBuiltinVoteType_Custom_YesNoBuiltinVoteAction_Cancel BuiltinVoteAction_VoteEnd BuiltinVoteAction_End);
        
SetBuiltinVoteArgument(g_hVote"Turn off confogl?");
        
SetBuiltinVoteInitiator(g_hVoteclient);
        
SetBuiltinVoteResultCallback(g_hVoteResetMatchVoteResultHandler);
        
DisplayBuiltinVote(g_hVoteiPlayersiNumPlayers20);
        
FakeClientCommand(client"Vote Yes");
        return;
    }
    
CPrintToChat(client"{blue}[{default}Match{blue}] {default}Resetmatch vote cannot be started now.");
}

public 
void ResetMatchVoteResultHandler(Handle voteint num_votesint num_clients, const int[][] client_infoint num_items, const int[][] item_info)
{
    for (new 
i=0i<num_itemsi++)
    {
        if (
item_info[i][BUILTINVOTEINFO_ITEM_INDEX] == BUILTINVOTES_VOTE_YES)
        {
            if (
item_info[i][BUILTINVOTEINFO_ITEM_VOTES] > (num_votes 2))
            {
                
DisplayBuiltinVotePass(vote"Confogl is unloading...");
                
ServerCommand("sm_resetmatch");
                return;
            }
        }
    }
    
DisplayBuiltinVoteFail(voteBuiltinVoteFail_Loses);
}

ConnectingPlayers()
{
    new 
Clients 0;
    
    for (new 
1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i) && IsClientConnected(i))
            
        
Clients++;
    }
    return 
Clients;

I know I should post on the author's Github, but I doubt SirPlease wants to help me
Quote:
L4D2 Competitive Rework
<== IMPORTANT NOTICE DON'T IGNORE THIS OKAY?! ===>
<------------------ LINUX SUPPORT ONLY ------------------>

< The repo has some support for Windows, but I will not personally guarantee it's functionality >
My operating system is Windows 10
Attached Files
File Type: sp Get Plugin or Get Source (match_vote.sp - 69 views - 9.1 KB)
__________________
Sorry i don't speak english very well

--->My name is Source and I'm on Steam<---
Discord: Source#9382

Last edited by Tank Rush; 11-22-2021 at 23:00.
Tank Rush is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-22-2021 , 21:32   Re: [L4D2] Match Vote: error in logs
Reply With Quote #2

You can remove:

PHP Code:
public OnPluginEnd()
{
    
SetConVarInt(g_hSvMaxPlayersGetConVarInt(g_hMaxPlayers));

OnPluginEnd usually is only called when you need "unload" the plugin.
Maybe you don't need this in your scenario.
__________________
Marttt is offline
Tank Rush
Senior Member
Join Date: May 2019
Location: Argentina
Old 11-22-2021 , 23:00   Re: [L4D2] Match Vote: error in logs
Reply With Quote #3

Thanks Marttt
__________________
Sorry i don't speak english very well

--->My name is Source and I'm on Steam<---
Discord: Source#9382
Tank Rush is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:31.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode