OnPlayerStateChange Problem
#1

When ANY player joins the server, this appears:
pawn Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 999 past array upper bound 500
[debug] AMX backtrace:
[debug] #0 000661e8 in public OnPlayerStateChange () from EG-RP.amx
This is a big part of the OnPlayerStateChange:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate != 2) NOPTrigger[playerid] = 0;
    if(IsPlayerNPC(playerid))
    {
        if(newstate == PLAYER_STATE_SPECTATING)
        {
            TogglePlayerSpectating(playerid, false);
        }
        return 1;
    }
    if(GettingSpectated[playerid] != 999)
    {
        new spectator = GettingSpectated[playerid];
        if(!IsPlayerConnected(spectator))
        {
            GettingSpectated[playerid] = 999;
            Spectate[spectator] = 999;
        }

        if(newstate == PLAYER_STATE_DRIVER && PlayerInfo[spectator][pAdmin] >= 2 || newstate == PLAYER_STATE_PASSENGER && PlayerInfo[spectator][pAdmin] >= 2)
        {
            TogglePlayerSpectating(spectator, true);
            new carid = GetPlayerVehicleID( playerid );
            PlayerSpectateVehicle( spectator, carid );
            SetPVarInt(spectator, "SpecState", newstate);
        }
        else if(newstate == PLAYER_STATE_ONFOOT && PlayerInfo[spectator][pAdmin] >= 2)
        {
            TogglePlayerSpectating(spectator, true);
            PlayerSpectatePlayer( spectator, playerid );
            SetPlayerInterior( spectator, GetPlayerInterior( playerid ) );
            SetPVarInt(spectator, "SpecState", newstate);
        }
    }
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(Audio_IsClientConnected(playerid))
        {
            Audio_Stop(playerid, stationidp[playerid]);
            stationidp[playerid] = 0;
        }
       
       
        new spectator = GettingSpectated[playerid];
        if(PlayerInfo[spectator][pAdmin] >= 2) {
            // Preventing possible buffer overflows with the arrays
            TogglePlayerSpectating(spectator, true);
            PlayerSpectatePlayer( spectator, playerid );
            SetPlayerInterior( spectator, GetPlayerInterior( playerid ) );
            SetPVarInt(spectator, "SpecState", newstate);
            SetPlayerInterior( spectator, GetPlayerInterior( playerid ) );
            SetPlayerVirtualWorld( spectator, GetPlayerVirtualWorld( playerid ) );
        }

        if(oldstate == PLAYER_STATE_DRIVER)
        {
            SetPlayerWeaponsEx(playerid);
        }
        else if(oldstate == PLAYER_STATE_PASSENGER) SetPlayerWeaponsEx(playerid);

        if(ConnectedToPC[playerid] == 1337)//mdc
        {
            SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "* You are now logged off the MDC.");
            ConnectedToPC[playerid] = 0;
        }
        if(TransportDuty[playerid] > 0)
        {
            if(TransportDuty[playerid] == 1)
            {
                TaxiDrivers -= 1;
            }
            else if(TransportDuty[playerid] == 2)
            {
                BusDrivers -= 1;
            }
            TransportDuty[playerid] = 0;
            new string[42];
            format(string, sizeof(string), "* You are now off duty and earned $%d.", TransportMoney[playerid]);
            SendClientMessageEx(playerid, COLOR_LIGHTBLUE, string);
            GivePlayerCash(playerid, TransportMoney[playerid]);
            ConsumingMoney[playerid] = 1; TransportValue[playerid] = 0; TransportMoney[playerid] = 0;
            SetPlayerColor(playerid, TEAM_HIT_COLOR);
            TransportTime[playerid] = 0;
            TransportCost[playerid] = 0;
        }
        if(TransportDriver[playerid] < 999)
        {
            new string[128];
            TransportMoney[TransportDriver[playerid]] += TransportCost[playerid];
            format(string, sizeof(string), "~w~The ride cost~n~~r~$%d",TransportCost[playerid]);
            GameTextForPlayer(playerid, string, 5000, 3);
            format(string, sizeof(string), "~w~Passenger left the taxi.~n~~g~Earned $%d",TransportCost[playerid]);
            GameTextForPlayer(TransportDriver[playerid], string, 5000, 3);
            GivePlayerCash(playerid, -TransportCost[playerid]);

            new ip[32], ipex[32];
            GetPlayerIp(playerid, ip, sizeof(ip));
            GetPlayerIp(TransportDriver[playerid], ipex, sizeof(ipex));
            TaxiWarn[playerid][TransportDriver[playerid]] += TransportCost[playerid];
            if(TaxiWarn[playerid][TransportDriver[playerid]] >= 10000)
            {
                format(string, sizeof(string), "%s (IP:%s) has taxied %s (IP:%s) $%d in this session.", GetPlayerNameEx(playerid), ip, GetPlayerNameEx(TransportDriver[playerid]), ipex, TaxiWarn[playerid][TransportDriver[playerid]]);
                Log("logs/pay.log", string);
                ABroadCast(COLOR_YELLOW, string, 2);
            }
            TransportTime[TransportDriver[playerid]] = 0;
            TransportCost[TransportDriver[playerid]] = 0;
            TransportCost[playerid] = 0;
            TransportTime[playerid] = 0;
            TransportDriver[playerid] = 999;
        }
        TelePos[playerid][0] = 0.0;
        TelePos[playerid][1] = 0.0;
    }
and hope someone helps and thanks
Reply
#2

Try reducing those

GettingSpectated[playerid] = 499;
Spectate[spectator] = 499;
TransportDriver[playerid] = 499;
Reply
#3

Now this appears:
pawn Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 999 past array upper bound 500
[debug] AMX backtrace:
[debug] #0 000661e8 in public OnPlayerStateChange () from EG-RP.amx
Reply
#4

pawn Код:
GettingSpectated[playerid] = 999;
Spectate[spectator] = 999;
But why on earth do you have to use three digit numbers on variables that could only contain only one digit number ?

pawn Код:
GettingSpectated[playerid] = 9;
Spectate[spectator] = 9;
That's just ridiculous.
Reply
#5

use -1
Reply
#6

The issue is because you're setting the variables to 999 if the person is not connected and such, and seeing as the array you're using probably is the size of MAX_PLAYERS (500), if you're checking for 999 then its going out of bounds, you need to reduce the number to be in bounds OR have a check IE, if(X == 999)
Reply
#7

@lelemaster: Doesn't work and still same error

@Unte99: Doesn't work also and still same error

@PrawkC: Do you mean there must be 999 players to not get this error ?!
Reply
#8

try using -1
Reply
#9

Doesn't work also and by the way the code i posted in the first post ISN'T ALL THE OnPlayerStateChange this is only a big part of it
Reply
#10

so why not post all code?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)