Error last kills
#1

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?
Reply
#2

What is the size of this array?

Код:
GunNames[id]
Reply
#3

Quote:
Originally Posted by pollo97
Посмотреть сообщение
What is the size of this array?

Код:
GunNames[id]
55.

new GunNames[55][] =
Reply
#4

You're passing id=255 to function GetWeaponNameEx, this is why Array index out of buonds.
Check your code inside cmd:last
Reply
#5

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";
    }
}
Reply
#6

Thanks, that was the problem.

Thanks guys for help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)