Attempted to read/write array element at negative index -1
#1

Hello, i am facing problem in my script when player disconnect (/q or from menu)

Error
PHP Code:
[12:37:32] [debugRun time error 4"Array index out of bounds"
[12:37:32] [debug]  Attempted to read/write array element at negative index -1
[12:37:32] [debugAMX backtrace:
[
12:37:32] [debug#0 000137a0 in public CB_OnPlayerDisconnect (0, 1) from yo.amx
[12:37:32] [debug#1 00007df0 in public SSCANF_OnPlayerDisconnect (0, 1) from yo.amx
[12:37:32] [debug#2 00000d70 in public OnPlayerDisconnect (0, 1) from yo.amx 
OnPlayerDisconnect
PHP Code:
public OnPlayerDisconnect(playeridreason)
{
    
PlayerWait[playerid]=0;
    new 
m[512], Float:tx,Float:ty,Float:tz;
    if(
PlayerInfo[playerid][pInjured]==1){
        
PlayerInfo[playerid][pInjured]=2;
        
SavePlayer(playerid);
    }
    switch(
reason)
    {
        case 
0format(msizeof(m), "* %s left the server. (Timeout/Crashed)"PlayerICName(playerid));
        case 
1format(msizeof(m), "* %s left the server. (Leaving)",  PlayerICName(playerid));
        case 
2format(msizeof(m), "* %s left the server. (Kicked/Banned)",  PlayerICName(playerid));
    }
    for(new 
i=0i<MAX_PLAYERS;i++){
        if(
IsPlayerConnected(i)){
            if(
IsPlayerInRangeOfPoint(i30tx,ty,tz)){
                
SendClientMessage(iCOLOR_GEAR_LIGHTYELLOWm);
            }
        }
    }
    
PlayerInfo[playerid][pCash]=0;
    
CellPhone[playerid][InCall] = -1;
    
CellPhone[CellPhone[playerid][CalledBy]][InCall]= -1;
    
SendClientMessage(CellPhone[playerid][CalledBy], COLOR_GREY"Line went dead...");
    
CellPhone[CellPhone[playerid][CalledBy]][CalledBy] = -1;
    
CellPhone[playerid][PhoneRinging] = -1;
    
CellPhone[playerid][CalledTo] = -1;
    
CellPhone[playerid][CalledBy] = -1;
    
PlayerInfo[playerid][pCheckpoint] = 0;
    
GotPackages[playerid] = 0;
    
PlayerInfo[playerid][pInjured]=0;
    
phoneoff[playerid] = 0;
    
reporttimer[playerid] = 0;
    
reporttimer2[playerid] = 0;
    
// Variables reset are necessary(don't touch pls).
    
SavePlayer(playerid);
    
KillTimer(SavingTimer);
    return 
1;

Reply
#2

Code:
CellPhone[CellPhone[playerid][CalledBy]][InCall]= -1; 
SendClientMessage(CellPhone[playerid][CalledBy], COLOR_GREY, "Line went dead..."); 
CellPhone[CellPhone[playerid][CalledBy]][CalledBy] = -1;
to:
Code:
if(CellPhone[playerid][CalledBy] != -1)
{
	CellPhone[CellPhone[playerid][CalledBy]][InCall]= -1; 
	SendClientMessage(CellPhone[playerid][CalledBy], COLOR_GREY, "Line went dead..."); 
	CellPhone[CellPhone[playerid][CalledBy]][CalledBy] = -1;
}
Reply
#3

Quote:
Originally Posted by Jeffry
View Post
Code:
CellPhone[CellPhone[playerid][CalledBy]][InCall]= -1; 
SendClientMessage(CellPhone[playerid][CalledBy], COLOR_GREY, "Line went dead..."); 
CellPhone[CellPhone[playerid][CalledBy]][CalledBy] = -1;
to:
Code:
if(CellPhone[playerid][CalledBy] != -1)
{
	CellPhone[CellPhone[playerid][CalledBy]][InCall]= -1; 
	SendClientMessage(CellPhone[playerid][CalledBy], COLOR_GREY, "Line went dead..."); 
	CellPhone[CellPhone[playerid][CalledBy]][CalledBy] = -1;
}
Fixed, ty <3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)