Whats wrong with onplayerdeath?
#1

Heey all,

I have made a code that if a player dies he loses some % of his money.
Everything works fine but i see that the crashdetect has detect an error in the code.
pawn Код:
[14:13:57] [debug] Run time error 4: "Array index out of bounds"
[14:13:57] [debug]  Accessing element at index 65535 past array upper bound 499
[14:13:57] [debug] AMX backtrace:
[14:13:57] [debug] #0 0007b2dc in public itm_OnPlayerDeath () from acnr_lv2.amx
[14:13:57] [debug] #1 native CallLocalFunction () [00471c30] from samp-server.exe
[14:13:57] [debug] #2 00037598 in public OnPlayerDeath () from acnr_lv2.amx
[14:13:57] [death] Admigo died 255
[14:14:23] [debug] Run time error 4: "Array index out of bounds"
[14:14:23] [debug]  Accessing element at index 65535 past array upper bound 499
[14:14:23] [debug] AMX backtrace:
[14:14:23] [debug] #0 0007b2dc in public itm_OnPlayerDeath () from acnr_lv2.amx
[14:14:23] [debug] #1 native CallLocalFunction () [00471c30] from samp-server.exe
[14:14:23] [debug] #2 00037598 in public OnPlayerDeath () from acnr_lv2.amx
[14:14:23] [death] Admigo died 255
pawn Код:
if(GetPlayerMoney(playerid)>=15000)
    {
        new DeathMoney = floatround( floatmul( GetPlayerMoney(playerid), 0.35 ), floatround_ceil );
        GivePlayerMoney(playerid,-DeathMoney);
    }
    else if(GetPlayerMoney(playerid)>=3000 && GetPlayerMoney(playerid)<15000)
    {
        new DeathMoney = floatround( floatmul( GetPlayerMoney(playerid), 0.50 ), floatround_ceil );
        GivePlayerMoney(playerid,-DeathMoney);
    }
    else if(GetPlayerMoney(playerid)>=1500 && GetPlayerMoney(playerid)<3000)
    {
        new DeathMoney = floatround( floatmul( GetPlayerMoney(playerid), 0.60 ), floatround_ceil );
        GivePlayerMoney(playerid,-DeathMoney);
    }
    else if(GetPlayerMoney(playerid)<1000)
    {
        ResetPlayerMoney(playerid);
    }
How can i fix this?

Admigo
Reply
#2

Код:
itm_OnPlayerDeath
Improperly coded hook/include.
Reply
#3

Quote:

Accessing element at index 65535 past array upper bound 499

I believe that instead of accessing an element at index with 499 (MAX_PLAYERS 500), it's trying to access 65535 (INVALID_PLAYER_ID). Check if the killerid is not invalid id and be sure!
Reply
#4

I cant find anything whats wrong.
Reply
#5

I just told you..

Quote:
Important Note: You MUST check whether killerid equals INVALID_PLAYER_ID before using it in an array, as it will cause the script to stop.

pawn Код:
if(killerid != INVALID_PLAYER_ID) // Valid killer
{
    // Decrease money
}
else
{
    // Decrease money
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)