Whats wrong with onplayerdeath? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Whats wrong with onplayerdeath? (
/showthread.php?tid=426661)
Whats wrong with onplayerdeath? -
Admigo - 29.03.2013
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
Re: Whats wrong with onplayerdeath? -
Vince - 29.03.2013
Improperly coded hook/include.
Re: Whats wrong with onplayerdeath? -
Konstantinos - 29.03.2013
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!
Re: Whats wrong with onplayerdeath? -
Admigo - 29.03.2013
I cant find anything whats wrong.
Re: Whats wrong with onplayerdeath? -
Konstantinos - 29.03.2013
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
}