Raised This Month: $42 Target: $400
 10% 

Solved Invalid index -1 (count: 100)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BeNq!
Senior Member
Join Date: Mar 2009
Old 10-24-2020 , 22:10   Invalid index -1 (count: 100)
Reply With Quote #1

Hello,

Please help me with this error:

Code:
L 10/25/2020 - 00:04:52: [SM] Exception reported: Invalid index -1 (count: 100)
L 10/25/2020 - 00:04:52: [SM] Blaming: sbpp_lastplayer.smx
L 10/25/2020 - 00:04:52: [SM] Call stack trace:
L 10/25/2020 - 00:04:52: [SM]   [0] ArrayList.Erase
L 10/25/2020 - 00:04:52: [SM]   [1] Line 63, C:\Users\****\sbpp_lastplayer.sp::OnClientPostAdminCheck
Plugin:

PHP Code:
#include <sourcemod>
#include <adminmenu>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "2.0"
#define TAG "[SM]"

Handle g_hTopMenu null;

ConVar gcv_iArraySize null;

ArrayList ga_Names;
ArrayList ga_SteamIds;
ArrayList ga_Ips;

int g_ownReasons[MAXPLAYERS 1] = false;

char g_temp_Steam[MAXPLAYERS 1][128], g_temp_Minutes[MAXPLAYERS 1][128], g_temp_Name[MAXPLAYERS 1][128], g_temp_IP[MAXPLAYERS 1][128];

public 
Plugin myinfo =
{
    
name "Last Player List",
    
author "DC",
    
description "Allows you to ban players who have disconnected from the server",
    
version PLUGIN_VERSION,
};

public 
void OnPluginStart()
{
    
CreateConVar("sm_last_version"PLUGIN_VERSION"Headline's last player"FCVAR_DONTRECORD);
    
    
gcv_iArraySize CreateConVar("sm_bandisconnected_max""100""List size of ban disconnected players menu");
    
    
RegAdminCmd("sm_lastban"Command_BanDisconnectedADMFLAG_BAN"Ban a player after they have disconnected!");
    
RegAdminCmd("sm_last"Command_ListDisconnectedADMFLAG_BAN"List all disconnected players!");
    
    
RegConsoleCmd("say"ChatHook);
    
RegConsoleCmd("say_team"ChatHook);
    
    
HookEvent("player_disconnect"Event_PlayerDisconnectEventHookMode_Pre);
    
    
Handle topmenu;
    if(
LibraryExists("adminmenu") && ((topmenu GetAdminTopMenu()) != INVALID_HANDLE))
    {
        
OnAdminMenuReady(topmenu);
    }
    
    
LoadADTArray();
}

public 
void OnClientPostAdminCheck(int client)
{
    
char sSteamID[32];
    
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

    if (
FindStringInArray(ga_SteamIdssSteamID) != -1)
    {
        
ga_Names.Erase(ga_SteamIds.FindString(sSteamID));
        
ga_SteamIds.Erase(ga_SteamIds.FindString(sSteamID));
        
ga_Ips.Erase(ga_SteamIds.FindString(sSteamID));
    }
}

public 
void OnClientDisconnect(int client)
{
    
g_ownReasons[client] = false;

    
g_temp_Steam[client] = NULL_STRING;
    
g_temp_Minutes[client] = NULL_STRING;
    
g_temp_Name[client] = NULL_STRING;
    
g_temp_IP[client] = NULL_STRING;
}

public 
Action Event_PlayerDisconnect(Event hEventchar[] namebool bDontBroadcast)
{
    
int client GetClientOfUserId(hEvent.GetInt("userid"));
    if (
IsValidClient(client))
    {
        
char sName[MAX_NAME_LENGTH];
        
GetClientName(clientsNamesizeof(sName));
        
        
char sDisconnectedSteamID[32];
        
GetClientAuthId(clientAuthId_Steam2sDisconnectedSteamIDsizeof(sDisconnectedSteamID));
        
        
char sDisconnectedIP[32];
        
GetClientIP(clientsDisconnectedIPsizeof(sDisconnectedIP));
        
        if (
FindStringInArray(ga_SteamIdssDisconnectedSteamID) == -1)
        {
            
PushToArrays(sNamesDisconnectedSteamIDsDisconnectedIP);
        }
    }
}

void PushToArrays(const char[] clientName, const char[] clientSteam, const char[] clientIP)
{    
    if (
ga_Names.Length == 0)
    {
        
ga_Names.PushString(clientName);
        
ga_SteamIds.PushString(clientSteam);
        
ga_Ips.PushString(clientIP);
    }
    else
    {
        
ga_Names.ShiftUp(0);
        
ga_SteamIds.ShiftUp(0);
        
ga_Ips.ShiftUp(0);
        
        
ga_Names.SetString(0clientName);
        
ga_SteamIds.SetString(0clientSteam);
        
ga_Ips.SetString(0clientIP);
    }
    
    
/* Trucate Arrays */
    
if (ga_Names.Length >= gcv_iArraySize.IntValue && gcv_iArraySize.IntValue 0)
    {
        
ga_Names.Resize(gcv_iArraySize.IntValue);
        
ga_SteamIds.Resize(gcv_iArraySize.IntValue);
        
ga_Ips.Resize(gcv_iArraySize.IntValue);
    }
}

// COMMAND CODE //

public Action ChatHook(int clientint args)
{
    
// is this player preparing to ban someone
    
if (g_ownReasons[client])
    {
        
// get the reason
        
char reason[512];
        
GetCmdArgString(reasonsizeof(reason));
        
StripQuotes(reason);
        
        
g_ownReasons[client] = false;
        
        
CheckAndPerformBan(clientg_temp_Steam[client], StringToInt(g_temp_Minutes[client]), reasong_temp_Name[client], g_temp_IP[client]);
        
        
// block the reason to be sent in chat
        
return Plugin_Handled;
    }
    return 
Plugin_Continue;
}

public 
Action Command_BanDisconnected(int clientint args)
{
    if (
args != 3)
    {
        
ReplyToCommand(client" %sUsage: sm_bandisconnected <\"steamid\"> <minutes|0> [\"reason\"] <name> <ip>"TAG);
        return 
Plugin_Handled;
    }
    else
    {
        
char steamid[20], minutes[10], reason[256], name[128], ip[20];
        
GetCmdArg(1steamidsizeof(steamid));
        
GetCmdArg(2minutessizeof(minutes));
        
GetCmdArg(3reason,  sizeof(reason));
        
GetCmdArg(4name,  sizeof(name));
        
GetCmdArg(5ip,  sizeof(ip));
        
CheckAndPerformBan(clientsteamidStringToInt(minutes), reasonnameip);
    }
    return 
Plugin_Handled;
}

public 
Action Command_ListDisconnectedint clientint args )
{
    if ( 
ga_Names.Length >= 10 )
    {
        
PrintToConsoleclient"************ OSTATNIE 10 ROZLACZONYCH GRACZY *****************" );
        
        for ( 
int i 0<= 10i++ )
        {
            
char sName[MAX_TARGET_LENGTH], sSteamID[32], sIP[32];
            
            
ga_Names.GetString(isNamesizeof(sName));
            
ga_SteamIds.GetString(isSteamIDsizeof(sSteamID));
            
ga_Ips.GetString(isIPsizeof(sIP));
            
            
PrintToConsole(client"NAME : %s  STEAMID : %s IP : %s"sNamesSteamIDsIP);
        }
        
        
PrintToConsoleclient"************ OSTATNIE 10 ROZLACZONYCH GRACZY *****************" );
    }
    else
    {
        if ( 
ga_Names.Length == )
        {
            
PrintToConsole(client"%s Nie ma jeszcze rozlaczonych graczy!"TAG);
        }
        else
        {
            
PrintToConsole(client"************ OSTATNIE %i ROZLACZONYCH GRACZY *****************"GetArraySize(ga_Names) - 1);
            
            for (
int i 0ga_Names.Lengthi++)
            {
                
char sName[MAX_TARGET_LENGTH], sSteamID[32], sIP[32];
                
                
ga_Names.GetString(isNamesizeof(sName));
                
ga_SteamIds.GetString(isSteamIDsizeof(sSteamID));
                
ga_Ips.GetString(isIPsizeof(sIP));
                
                
PrintToConsole(client"** %s | %s - %s **"sNamesSteamIDsIP);
            }
            
PrintToConsole(client"************ OSTATNIE %i ROZLACZONYCH GRACZY *****************"GetArraySize(ga_Names) - 1);
        }
    }
    return 
Plugin_Handled;
}

void CheckAndPerformBan(int clientchar[] steamidint minuteschar[] reasonchar[] namechar[] ip)
{
    
AdminId admClient GetUserAdmin(client);
    
AdminId admTarget;
    if ((
admTarget FindAdminByIdentity(AUTHMETHOD_STEAMsteamid)) == INVALID_ADMIN_ID || CanAdminTarget(admClientadmTarget))
    {
        
bool hasRoot GetAdminFlag(admClientAdmin_Root);
        
SetAdminFlag(admClientAdmin_Roottrue);
        
char temp[1024];
        
Format(tempsizeof(temp), "%s [Ban Offline]"reason);
        
FakeClientCommand(client"sm_addban \"%d\" \"%s\" \"%s\" \"%s\" \"%s\""minutessteamidtempnameip);
        
SetAdminFlag(admClientAdmin_RoothasRoot);
    }
    else
    {
        
ReplyToCommand(client" %s Nie mozesz zbanowac admina, ktory ma wyzszy immunitet od ciebie!"TAG);
    }
}

public 
void OnAdminMenuReady(Handle hTopMenu)
{
    if(
hTopMenu == g_hTopMenu)
    {
        return;
    }
    
    
g_hTopMenu hTopMenu;
    
    
TopMenuObject MenuObject AddToTopMenu(g_hTopMenu"last_pl"TopMenuObject_CategoryAdminMenu_BanINVALID_TOPMENUOBJECT"sm_lastban"ADMFLAG_BAN);
    if(
MenuObject == INVALID_TOPMENUOBJECT)
    {
        return;
    }
    
    
AddToTopMenuhTopMenu"sm_lastban"TopMenuObject_ItemAdminMenu_Ban_itemMenuObject"sm_lastban"ADMFLAG_BAN"Rozlaczeni gracze" );
}

public 
void AdminMenu_Ban(Handle topmenuTopMenuAction actionTopMenuObject topobj_idint iClientchar[] bufferint maxlength)
{
    if(
action == TopMenuAction_DisplayOption || action == TopMenuAction_DisplayTitle)
    {
        
Format(buffermaxlength"Rozlaczeni gracze" );
    }
}

public 
void AdminMenu_Ban_item(Handle hTopMenuTopMenuAction actionTopMenuObject object_idint paramchar[] bufferint maxlength)
{
    
g_ownReasons[param] = false;
    
    if (
action == TopMenuAction_DisplayOption)
    {
        
Format(buffermaxlength"Zbanuj rozlaczonego gracza");
    }
    else if (
action == TopMenuAction_SelectOption)
    {
        
DisplayTargetsMenu(paramtrue);
    }
}

public 
void DisplayTargetsMenu(int clientbool exitback
{
    if (
ga_SteamIds.Length == 0)
    {
        
ReplyToCommand(client"%s Nie ma jeszcze rozlaczonych graczy!"TAG);
        return;
    }
    
    
Menu MainMenu = new Menu(TargetsMenu_CallBackMenuAction_Select MenuAction_End); 
    
MainMenu.SetTitle("Wybierz gracza do zbanowania:"); 
    
    
char sDisplayBuffer[128], sSteamID[32], sName[MAX_NAME_LENGTH], temp[3];
    
    for (
int i 0ga_SteamIds.Lengthi++)
    {
        
ga_Names.GetString(isNamesizeof(sName));
        
ga_SteamIds.GetString(isSteamIDsizeof(sSteamID));
        
        
Format(sDisplayBuffersizeof(sDisplayBuffer), "%s [ %s ]"sNamesSteamID);
        
        
IntToString(itempsizeof(temp));
        
MainMenu.AddItem(tempsDisplayBuffer);
    }
    
    
SetMenuExitBackButton(MainMenuexitback);
    
DisplayMenu(MainMenuclientMENU_TIME_FOREVER); 
}

public 
int TargetsMenu_CallBack(Menu MainMenuMenuAction actionint param1int param2
{
    switch (
action)
    {
        case 
MenuAction_Select:
        {
            
char sInfo[128];
            
GetMenuItem(MainMenuparam2sInfosizeof(sInfo));
            
            
DisplayBanTimeMenu(param1sInfo);
        }
        case 
MenuAction_Cancel:
        {
            if (
param2 == MenuCancel_ExitBack && g_hTopMenu != INVALID_HANDLE)
            {
                
DisplayTopMenu(g_hTopMenuparam1TopMenuPosition_LastCategory);
            }
        }
        case 
MenuAction_End:
        {
            
CloseHandle(MainMenu);
        }
    }
}

public 
void DisplayBanTimeMenu(int clientchar[] sInfo)
{
    
Menu BanTimeMenu = new Menu(BanTime_CallBackMenuAction_Select MenuAction_End); 
    
BanTimeMenu.SetTitle("Wybierz czas bana:"); 
    
char sInfoBuffer[128];
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,0"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"Permanenty");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,30"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"30 Minut");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,60"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"1 Godzina");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,120"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"2 Godziny");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,240"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"4 Godziny");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,480"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"8 Godzin");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,720"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"12 Godzin");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,1440"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"1 Dzien");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,10080"sInfo);
    
BanTimeMenu.AddItem(sInfoBuffer"1 Tydzien");
    
    
SetMenuExitBackButton(BanTimeMenutrue);
    
DisplayMenu(BanTimeMenuclientMENU_TIME_FOREVER); 
}

public 
int BanTime_CallBack(Handle BanTimeMenuMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_Select:
        {
            
char sInfo[128];
            
GetMenuItem(BanTimeMenuparam2sInfosizeof(sInfo));
            
            
DisplayBanReasonMenu(param1sInfo);
        }
        case 
MenuAction_Cancel:
        {
            if (
param2 == MenuCancel_ExitBack && g_hTopMenu != INVALID_HANDLE)
            {
                
DisplayTopMenu(g_hTopMenuparam1TopMenuPosition_LastCategory);
            }
        }
        case 
MenuAction_End:
        {
            
CloseHandle(BanTimeMenu);
        }
    }
}

void DisplayBanReasonMenu(int clientchar[] sInfo)
{
    
Menu BanReasonMenu = new Menu(BanReason_CallBackMenuAction_Select MenuAction_End); 
    
BanReasonMenu.SetTitle("Wybierz Powod:"); 
    
char sInfoBuffer[128];
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,Cheatowanie"sInfo);
    
BanReasonMenu.AddItem(sInfoBuffer"Cheatujesz");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,Wallhack"sInfo);
    
BanReasonMenu.AddItem(sInfoBuffer"Wallhack");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,Aimbot"sInfo);
    
BanReasonMenu.AddItem(sInfoBuffer"Aimbot");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,Skryptowanie"sInfo);
    
BanReasonMenu.AddItem(sInfoBuffer"Skryptowanie");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,Obrazanie graczy"sInfo);
    
BanReasonMenu.AddItem(sInfoBuffer"Obrazanie graczy");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,Obraza admina"sInfo);
    
BanReasonMenu.AddItem(sInfoBuffer"Obraza admina");
    
    
Format(sInfoBuffersizeof(sInfoBuffer), "%s,Inny powod"sInfo);
    
BanReasonMenu.AddItem(sInfoBuffer"Inny powod [ wlasny ]");
    
    
SetMenuExitBackButton(BanReasonMenutrue);
    
DisplayMenu(BanReasonMenuclientMENU_TIME_FOREVER);
}

public 
int BanReason_CallBack(Handle BanReasonMenuMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_Select:
        {
            
char sInfo[128], sTempArray[3][64];
            
            
GetMenuItem(BanReasonMenuparam2sInfosizeof(sInfo));
            
ExplodeString(sInfo","sTempArray364);
            
            
int temp StringToInt(sTempArray[0]);
            
            
char steamid[128], name[128], ip[128];
            
            
ga_SteamIds.GetString(tempsteamidsizeof(steamid));
            
ga_Names.GetString(tempnamesizeof(name));
            
ga_Ips.GetString(tempipsizeof(ip));
            
            if (
StrEqual("Inny powod"sTempArray[2]))
            {
                
g_temp_Steam[param1] = steamid;
                
g_temp_Minutes[param1] = sTempArray[1];
                
g_temp_Name[param1] = name;
                
g_temp_IP[param1] = ip;
                
                
g_ownReasons[param1] = true;
                
PrintToChat(param1"[FG-SBANS] Proszę wpisać powód bana w czacie oraz potwierdzić przyciskiem Enter.");
                return;
            }
            
            
CheckAndPerformBan(param1steamidStringToInt(sTempArray[1]), sTempArray[2], nameip);
        }
        case 
MenuAction_Cancel:
        {
            if (
param2 == MenuCancel_ExitBack && g_hTopMenu != INVALID_HANDLE)
            {
                
DisplayTopMenu(g_hTopMenuparam1TopMenuPosition_LastCategory);
            }
        }
        case 
MenuAction_End:
        {
            
CloseHandle(BanReasonMenu);
        }
    }
}

void LoadADTArray()
{
    
ga_Names = new ArrayList(MAX_TARGET_LENGTH);
    
ga_SteamIds = new ArrayList(32);
    
ga_Ips =  new ArrayList(32);
}

bool IsValidClient(int clientbool bAllowBots falsebool bAllowDead true)
{
    if(!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
    {
        return 
false;
    }
    return 
true;


Last edited by BeNq!; 11-06-2020 at 17:11.
BeNq! is offline
bklol
Junior Member
Join Date: May 2019
Location: on my chair
Old 10-25-2020 , 00:29   Re: Invalid index -1 (count: 100)
Reply With Quote #2

PHP Code:
public void OnClientPostAdminCheck(int client)
{
    if(!
IsValidClient(client))
        return;
    
char sSteamID[32];
    
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

    if (
FindStringInArray(ga_SteamIdssSteamID) != -1)
    {
        
ga_Names.Erase(ga_SteamIds.FindString(sSteamID));
        
ga_SteamIds.Erase(ga_SteamIds.FindString(sSteamID));
        
ga_Ips.Erase(ga_SteamIds.FindString(sSteamID));
    }
}

stock bool IsValidClientint client )
{
    if ( 
client || client MaxClients ) return false;
    if ( !
IsClientConnectedclient )) return false;
    if ( !
IsClientInGameclient )) return false;
    if ( 
IsFakeClient(client)) return false;
    return 
true;

bklol is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 10-25-2020 , 09:17   Re: Invalid index -1 (count: 100)
Reply With Quote #3

The problem is the order of the Erase statements. You are deleting it from ga_SteamIds and a line below you try to access that entry you just deleted. Just swap the last 2 Erase statements.

Although you probably want to cache the value of .FindString temporarily instead of calling .FindString 3 times.

Last edited by xerox8521; 10-25-2020 at 09:19.
xerox8521 is offline
BeNq!
Senior Member
Join Date: Mar 2009
Old 10-25-2020 , 17:26   Re: Invalid index -1 (count: 100)
Reply With Quote #4

@bklol not exist.

Quote:
Originally Posted by xerox8521 View Post
You are deleting it from ga_SteamIds and a line below you try to access that entry you just deleted. Just swap the last 2 Erase statements.
Thank you. Solved.

Last edited by BeNq!; 11-06-2020 at 17:12.
BeNq! 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 00:20.


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