Error last kills - 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: Error last kills (
/showthread.php?tid=645233)
Error last kills -
RedGun2015 - 23.11.2017
Hello guys, I have a problem with my command where I use to see all my kills and deaths I get this error in server_log and on server says: SERVER: Unknown command.
Код:
[18:13:19] [debug] Run time error 4: "Array index out of bounds"
[18:13:19] [debug] AMX backtrace:
[18:13:19] [debug] #0 00189bb8 in GetWeaponNameEx (id=255, name[]=@015ac334 "Combat Shotgun", len=126) at D:\gamemode\gamemodes\exgaming.pwn:24232
[18:13:19] [debug] #1 001fae04 in public cmd_last (playerid=1, params[]=@0157052c "kills neg 153") at D:\gamemode\gamemodes\exgaming.pwn:31324
[18:13:19] [debug] #2 native CallLocalFunction () from samp03svr
[18:13:19] [debug] #3 00039f0c in public OnPlayerCommandText (playerid=1, cmdtext[]=@015704dc "/last kills neg 153") at D:\gamemode\pawno\include\zcmd.inc:108
Command:
https://pastebin.com/iJKXNkEi
GetWeaponNameEx:
Код:
stock GetWeaponNameEx(id, name[], len) return format(name,len, "%s", GunNames[id]);
Can someone help me?
Re: Error last kills -
pollo97 - 23.11.2017
What is the size of this array?
Re: Error last kills -
RedGun2015 - 24.11.2017
Quote:
Originally Posted by pollo97
What is the size of this array?
|
55.
new GunNames[55][] =
Re: Error last kills -
pollo97 - 24.11.2017
You're passing id=255 to function GetWeaponNameEx, this is why Array index out of buonds.
Check your code inside cmd:last
Re: Error last kills -
RedFusion - 24.11.2017
Quote:
Originally Posted by pollo97
You're passing id=255 to function GetWeaponNameEx, this is why Array index out of buonds.
Check your code inside cmd:last
|
As pollo97 is saying the index 255 is out of bounds.
You need to check the ID before accessing arrays. ID 255 is used when the player dies of unknown reason, for example if their health is set to 0.
Here's an example on how to check the ID
pawn Код:
switch(weaponid) {
case 0..46: { // Valid Weapon
GetWeaponNameEx(id, wepname, sizeof wepname);
}
case 255: { // Unknown death reason
wepname = "Death";
}
}
Re: Error last kills -
RedGun2015 - 26.11.2017
Thanks, that was the problem.
Thanks guys for help.