AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Index out of bounds (https://forums.alliedmods.net/showthread.php?t=205242)

andrzN 01-08-2013 12:20

Index out of bounds
 
1 Attachment(s)
Okey, so suddenly I got this error in my error log:

PHP Code:

L 01/08/2013 17:08:34: [AMXXRun time error 4index out of bounds 
L 01
/08/2013 17:08:34: [AMXX]    [0colorchat.inc::ColorChat (line 74)
L 01/08/2013 17:08:34: [AMXX]    [1Connect.sma::Print (line 78)
L 01/08/2013 17:08:34: [AMXX]    [2Connect.sma::client_disconnect (line 68

And here is the full code

PHP Code:

//                          _______________
//_________________________/ Plugin Info() \________________________________________
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
//   AdminMenu.sma           Version 1.2           Updated: FEBRUARY/19/2012
//
//   Plugin:        Connection Messages
//   Author:         anderseN
//     Version:         1.0
//   
//   Publicity:     Private
//   Contact:         [email protected]
//     Website:         www.Gamepark.se
//
//____________________________________________________________________________________
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/

#include <amxmodx>
#include <nvault>
#include <colorchat>

#define VAULT_NAME    "Connect"
#define VAULT_KEY    "NUM"

new const Prefix[] = "[GP]";

new 
gConnectVault

new name[33][32]
new 
authid[33][32]

public 
plugin_init() 
{
    
register_plugin("Connection Messages" "1.2" "anderseN");
    
    
gConnectVault nvault_open("ConnectVault")
    
    if(
gConnectVault == INVALID_HANDLE)
    
set_fail_state("nVault failed to open")
}

public 
plugin_end()
{
    
nvault_closegConnectVault );
}

public 
client_putinserver(id)
{
    static 
szTemp] , iConnections;
    
    
get_user_name(id,name[id],31)
    
get_user_authid(id,authid[id],31)

    
iConnections nvault_getgConnectVault authid[id] );
    
    
num_to_str( ++iConnections szTemp charsmaxszTemp ) );
    
nvault_setgConnectVault authid[id] , szTemp );
    
    Print(
0"%s ^01(%s)^03 has connected.^04 [Connections: %d]"name[id], authid[id], iConnections);
    
    return 
PLUGIN_HANDLED;


public 
client_disconnect(id)
{
    
get_user_name(id,name[id],31)
    
get_user_authid(id,authid[id],31)

    Print(
0"%s ^01(%s)^04 has disconnected."name[id], authid[id]);
    
    return 
PLUGIN_HANDLED;


Print(
id, const szMessage[], any:...) 

    static 
szBuffer[192]; 
    
vformat(szBuffercharsmax(szBuffer), szMessage3); 

    
ColorChat(idGREY"^04%s^03 %s"PrefixszBuffer); 

}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1044\\ f0\\ fs16 \n\\ par }
*/ 

What could be the problem? I have never seen this error before.

rx1983 01-08-2013 12:44

Re: Index out of bounds
 
no errors for me.
Code:

//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// cm.sma
// Header size:            584 bytes
// Code size:            3040 bytes
// Data size:            10336 bytes
// Stack/heap size:      16384 bytes; max. usage is unknown, due to recursion
// Total requirements:  30344 bytes
// Done.


micapat 01-08-2013 13:04

Re: Index out of bounds
 
Upload your colorchat.inc / .sma.

AngeIII 01-08-2013 13:10

Re: Index out of bounds
 
if you got this error constantly you can just add this:
PHP Code:

public client_disconnect(id

    
log_amx("ID:%d",id);
    
get_user_name(id,name[id],31
    
get_user_authid(id,authid[id],31
    
log_amx("Name: %s AUTH: %s",name[id],authid[id]);
    Print(
0"%s ^01(%s)^04 has disconnected."name[id], authid[id]); 
    
log_amx("%s ^01(%s)^04 has disconnected."name[id], authid[id]);  
    return 
PLUGIN_HANDLED


and in standart logs you will see the problem. i think problem is with formatting:
get_user_name(id,name[id],31)
get_user_authid(id,authid[id],31)

Neeeeeeeeeel.- 01-08-2013 21:04

Re: Index out of bounds
 
Quote:

Originally Posted by rx1983 (Post 1869713)
no errors for me.
Code:

//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// cm.sma
// Header size:            584 bytes
// Code size:            3040 bytes
// Data size:            10336 bytes
// Stack/heap size:      16384 bytes; max. usage is unknown, due to recursion
// Total requirements:  30344 bytes
// Done.


He is talking about log error messages...

andrzN 01-10-2013 21:48

Re: Index out of bounds
 
Quote:

Originally Posted by AngeIII (Post 1869723)
if you got this error constantly you can just add this:
PHP Code:

public client_disconnect(id

    
log_amx("ID:%d",id);
    
get_user_name(id,name[id],31
    
get_user_authid(id,authid[id],31
    
log_amx("Name: %s AUTH: %s",name[id],authid[id]);
    Print(
0"%s ^01(%s)^04 has disconnected."name[id], authid[id]); 
    
log_amx("%s ^01(%s)^04 has disconnected."name[id], authid[id]);  
    return 
PLUGIN_HANDLED


and in standart logs you will see the problem. i think problem is with formatting:
get_user_name(id,name[id],31)
get_user_authid(id,authid[id],31)

The error doesn't come constantly, it comes just now and then, everything from 5min to 2 hours apart. So thats the weird part, why would it just give this error some times when this acton is used like all the time (each time a player disconnects).

But thanks, I will try that and come back with the results of the log.

fysiks 01-10-2013 22:31

Re: Index out of bounds
 
Looks to me like you should just remove the arrays entirely since they are never used other than immediately after they are populated.

andrzN 01-11-2013 03:17

Re: Index out of bounds
 
Quote:

Originally Posted by fysiks (Post 1871279)
Looks to me like you should just remove the arrays entirely since they are never used other than immediately after they are populated.

If I remove get_user_name and get_user_authid in client_disconnect (if thats what you meant) then how will I get the disconnected players name and steamid?

AngeIII 01-11-2013 09:32

Re: Index out of bounds
 
cache it when user connecting. (steamid doesn't change on connected-disconnected interval ...)

and cache name also if user is changing name.

fysiks 01-11-2013 14:05

Re: Index out of bounds
 
Quote:

Originally Posted by andrzN (Post 1871379)
If I remove get_user_name and get_user_authid in client_disconnect (if thats what you meant) then how will I get the disconnected players name and steamid?

I didn't say remove those functions. I said to remove the array of strings and just use a local string for name and Steam ID.


All times are GMT -4. The time now is 13:29.

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