Command SOMETIMES returning 0?
#1

Hey guys. I'm working on two different parts of script and I'm having issues with them both. One is a /want command and the other is wanting a killer on death.

Want command SOMETIMES works I don't know the parameters of what it works but sometimes it does but most of the time when I type the correct usage. /want 0 6 Test I get return 0. But sometimes it'll work.

This is my debug code for the warn command.
Код:
[08:26:14] [debug] Run time error 4: "Array index out of bounds"
[08:26:14] [debug]  Attempted to read/write array element at negative index -1
[08:26:14] [debug] AMX backtrace:
[08:26:14] [debug] #0 001539f0 in public cmd_want (1, 24698196) from vR.amx
[08:26:14] [debug] #1 native CallLocalFunction () from samp03svr
[08:26:14] [debug] #2 000008a8 in public OnPlayerCommandText (1, 24698124) from vR.amx
Here is the want code.
PHP код:
CMD:want(playerid,params[])
{
    new 
id,lvl,reason[32],string[128],org;
    new 
org1=PlayerInfo[playerid][OrgID];
    
org=PlayerInfo[id][OrgID];
    if(
PlayerInfo[playerid][Rules] == 0) return SendClientMessage(playeridCOLOR_RED"You need to accept rules using /rules!");
    if(!
IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Error: Player is not online");
    if(
PlayerInfo[playerid][OrgID] == -1) return SendClientMessage(playerid,COLOR_RED,"Error: You aren't in an organization!");
    if(
sscanf(params"dds[32]"id,lvl,reason)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /want [PlayerID] [Wanted Level] [Reason]");
    if(
PlayerInfo[id][pInJail] == 1) return SendClientMessage(playerid,COLOR_RED,"Error: this player is in jail");
    if(
oInfo[org1][Type] != 1) return SendClientMessage(playerid,COLOR_RED,"Error: Not Law");
    if(
GetPVarInt(playerid,"Oskin") == 0) return SendClientMessage(playerid,COLOR_RED,"You are not on Duty!");
    if(
LoggedIn[id] == 0) return SendClientMessage(playeridCOLOR_RED"Error: Player hasn't logged in.");
    if(
GetPVarInt(id,"spawned") == 0) return SendClientMessage(playerid,COLOR_RED,"Error: Player not spawned");
    if(
GetPVarInt(id,"Oskin") == && oInfo[org][Type]==1) return SendClientMessage(playerid,COLOR_RED,"Error: You can't want on duty officers");
    if(
id == playerid) return SendClientMessage(playerid,COLOR_RED,"Error: You can't want yourself!");
    if(
lvl || lvl >6) return SendClientMessage(playerid,COLOR_RED,"Error: Invalid Wanted Level");
    if(
IsPlayerConnected(id))
    {
        
SetPlayerWantedLevel(id,lvl);
        
PlayerInfo[id][WantedLvl]=lvl;
        
format(string,sizeof(string),"%s's wanted level has been set to %d by %s, Reason: %s",GetName(id),lvl,GetName(playerid),reason);
        if(
lvl == 0)
        {
            
format(string,sizeof(string)," %s's wanted level has been unset by %s",GetName(id),GetName(playerid));
            
SendClientMessageToAll(COLOR_WHITE,string);
        }
        else
        {
            
SendClientMessageToAll(COLOR_LIGHTBLUE,string);
        }
    }
    return 
1;

The other part is on player death. I want to want the person who killed the player +1 wanted level if they aren't 'oskined' however. The issue is. That it will only want players that are in an existing org so their OrgID won't be equal to -1. So basically; If players OrgID == 3 they will get wanted for killing player, but if OrgID == -1 (Default) they won't get wanted.

PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
killerid == INVALID_PLAYER_ID)
    {
        new 
ce=cell_ref[playerid];
        
PlayerInfo [playerid] [pSkin] = GetPlayerSkin(playerid);
        
SetPVarInt(playerid,"spawned",0);
        
ResetPlayerWeapons(playerid);
        
SetPVarInt(playerid,"Weps",0);
        
SaveAccountStats(playerid);
        
GameTextForPlayer(playerid,"~r~~h~WASTED",8000,1);
        
PlayerTextDrawHide(playeridSpeedoText[playerid]);
        
SendDeathMessageEx(playeridkilleridreason);
        
SetPVarInt(playerid"Dead"1);
        
TextDrawHideForPlayer(playerid,txtTimeDisp);
        
PlayerTextDrawHide(playeridTxtZones[playerid]);
        
SetPlayerWantedLevel(playerid,0);
        if(
IsPlayerInAnyVehicle(playerid))
        {
            
PlayerTextDrawHide(playeridSpeedoText[playerid]);
        }
        
PlayerInfo[playerid][WantedLvl]=0;
        if(
gPlayerUsingLoopingAnim[playerid])
        {
            
gPlayerUsingLoopingAnim[playerid] = 0;
            
TextDrawHideForPlayer(playerid,txtAnimHelper);
        }
        
GetPlayerClosestHospital(playerid);
        
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid), PlayerInfo[playerid][pXPos],PlayerInfo[playerid][pYPos],PlayerInfo[playerid][pZPos],PlayerInfo[playerid][pAPos], 000000);
        if(
GetPVarInt(playerid,"Jailed") == 1)
        {
            
SetSpawnInfo(playeridNO_TEAM,42,cellInfo[ce][cellx],cellInfo[ce][celly],cellInfo[ce][cellz],cellInfo[ce][cella], 000000);
            
SetPlayerInterior(playerid,5);
            
SetPlayerWantedLevel(playerid,0);
            
PlayerInfo[playerid][WantedLvl]=0;
        }
    }
    if(
IsPlayerInAnyVehicle(playerid))
    {
        
PlayerTextDrawHide(playeridSpeedoText[playerid]);
    }
    new 
org;
    new 
ce=cell_ref[playerid];
    
org=PlayerInfo[killerid][OrgID];
    
PlayerInfo [playerid][pSkin] = GetPlayerSkin(playerid);
    
SetPVarInt(playerid,"spawned",0);
    
ResetPlayerWeapons(playerid);
    
SetPVarInt(playerid,"Weps",0);
       
GameTextForPlayer(playerid,"~r~~h~WASTED",10000,1);
    
SendDeathMessageEx(playeridkilleridreason);
    
SetPVarInt(playerid"Dead"1);
    
TextDrawHideForPlayer(playerid,txtTimeDisp);
    
PlayerTextDrawHide(playeridTxtZones[playerid]);
    
PlayerTextDrawHide(playeridSpeedoText[playerid]);
    if(
gPlayerUsingLoopingAnim[playerid])
    {
        
gPlayerUsingLoopingAnim[playerid] = 0;
        
TextDrawHideForPlayer(playerid,txtAnimHelper);
    }
    if(
GetPVarInt(killerid,"Jailed") == 0)
    {
        new 
string[100];
        if(
GetPlayerWantedLevel(killerid) == 6)
        {
            
format(string,sizeof(string),"[CRIME]%s has murdered %s, and remains a highly wanted player, Wanted Level:%d",GetName(killerid),GetName(playerid),PlayerInfo[killerid][WantedLvl]);
            
SendClientMessageToAll(COLOR_LIGHTBLUE,string);
        }
        else
        {
            if(
oInfo[org][Type] == && GetPVarInt(killerid,"Oskin") == 0) return 1;
            
SetPlayerWantedLevel(killeridGetPlayerWantedLevel(killerid) + 1);
            
PlayerInfo[killerid][WantedLvl]=GetPlayerWantedLevel(killerid);
            
format(stringsizeof(string), "[CRIME] %s has been Wanted for the murder of %s,Wanted Level:%d",GetName(killerid),GetName(playerid),PlayerInfo[killerid][WantedLvl]);
            
SendClientMessageToAll(COLOR_LIGHTBLUE,string);
        }
    }else
    {
        new 
string[100];
        
format(string,sizeof(string),"[JAIL]%s's sentence has been extended due to the murder of %s in prison",GetName(killerid),GetName(playerid));
        
SendClientMessageToAll(COLOR_YELLOW,string);
        
KillTimer(JailTimer[killerid]);
        
PlayerInfo[killerid][pInJailTime] += 2;
        
format(string,sizeof(string),"Your time has been extended due to your crimes within Prison, New Time:%d Minutes",PlayerInfo[killerid][pInJailTime]);
        
SendClientMessage(killerid,COLOR_YELLOW,string);
        
JailTimer[killerid]= SetTimerEx("UnjailTimer",60000,false,"ii",killerid,PlayerInfo[killerid][pInJailTime]);
    } 
Reply
#2

Your public OnPlayerDeath(playerid, killerid, reason) doesn't return anything.

Try add:

return 1;
}

at the end.
Reply
#3

It does. I just didn't post the whole code because it's not needed.
Reply
#4

Hello.

The problem is that your variable org (or org1) is -1 (you are not in a organisation) and want to use this value (-1) in the array.
Then your server crash. You must to write it to another way.
Reply
#5

OnPlayerDeath does not handle returns... there's no difference either way.

PHP код:
 if(oInfo[org1][Type] != 1
If 'org1' is negative (-1 by default as you said), then you will get this error:
Код:
[debug]  Attempted to read/write array element at negative index -1
You need to check if the index is valid before using it in an array. You should also be checking if 'id' is a valid player before using it in arrays such as LoggedIn[id] or PlayerInfo[id][pInJail].

PHP код:
CMD:want(playeridparams[])
{
    if(
PlayerInfo[playerid][Rules] == 0) return SendClientMessage(playeridCOLOR_RED"You need to accept rules using /rules!");
    if(
PlayerInfo[playerid][OrgID] == -1) return SendClientMessage(playeridCOLOR_RED"Error: You aren't in an organization!");
    if(
GetPVarInt(playerid"Oskin") == 0) return SendClientMessage(playeridCOLOR_RED"You are not on Duty!");
    new 
idlvlreason[32];
    if(
sscanf(params"uds[32]"idlvlreason)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /want [PlayerID] [Wanted Level] [Reason]");
    if(!
IsPlayerConnected(id)) return SendClientMessage(playeridCOLOR_RED"Error: Player is not online");
    if(
id == playerid) return SendClientMessage(playeridCOLOR_RED"Error: You can't want yourself!");
    if(
lvl || lvl 6) return SendClientMessage(playeridCOLOR_RED"Error: Invalid Wanted Level");
    if(
PlayerInfo[id][pInJail] == 1) return SendClientMessage(playeridCOLOR_RED"Error: this player is in jail");
    if(
oInfo[PlayerInfo[playerid][OrgID]][Type] != 1) return SendClientMessage(playeridCOLOR_RED"Error: Not Law");
    if(
LoggedIn[id] == 0) return SendClientMessage(playeridCOLOR_RED"Error: Player hasn't logged in.");
    if(
GetPVarInt(id"spawned") == 0) return SendClientMessage(playeridCOLOR_RED"Error: Player not spawned");
    if(
GetPVarInt(id"Oskin") == && PlayerInfo[id][OrgID] >= && oInfo[PlayerInfo[id][OrgID]][Type] == 1) return SendClientMessage(playeridCOLOR_RED"Error: You can't want on duty officers");

    new 
string[128];
    
SetPlayerWantedLevel(idlvl);
    
PlayerInfo[id][WantedLvl] = lvl;
    if(
lvl == 0)
    {
        
format(stringsizeof(string), " %s's wanted level has been unset by %s"GetName(id), GetName(playerid));
        
SendClientMessageToAll(COLOR_WHITEstring);
    }
    else
    {
        
format(stringsizeof(string), "%s's wanted level has been set to %d by %s, Reason: %s"GetName(id), lvlGetName(playerid), reason);
        
SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    }
    return 
1;

I'm sure you can figure out the next issue by yourself. It sounds like more of a request than a cry for help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)