SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 23/11/2017, 03:19 PM   #1
RedGun2015
Huge Clucker
 
RedGun2015's Avatar
 
Join Date: Sep 2015
Location: Romania
Posts: 281
Reputation: 0
Default Error last kills

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.

Code:
[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:
Code:
stock GetWeaponNameEx(id, name[], len) return format(name,len, "%s", GunNames[id]);
Can someone help me?
RedGun2015 is offline   Reply With Quote
Old 23/11/2017, 07:17 PM   #2
pollo97
Big Clucker
 
pollo97's Avatar
 
Join Date: Sep 2011
Location: Italy
Posts: 83
Reputation: 4
Default Re: Error last kills

What is the size of this array?

Code:
GunNames[id]
pollo97 is offline   Reply With Quote
Old 24/11/2017, 03:42 PM   #3
RedGun2015
Huge Clucker
 
RedGun2015's Avatar
 
Join Date: Sep 2015
Location: Romania
Posts: 281
Reputation: 0
Default Re: Error last kills

Quote:
Originally Posted by pollo97 View Post
What is the size of this array?

Code:
GunNames[id]
55.

new GunNames[55][] =
RedGun2015 is offline   Reply With Quote
Old 24/11/2017, 05:18 PM   #4
pollo97
Big Clucker
 
pollo97's Avatar
 
Join Date: Sep 2011
Location: Italy
Posts: 83
Reputation: 4
Default Re: Error last kills

You're passing id=255 to function GetWeaponNameEx, this is why Array index out of buonds.
Check your code inside cmd:last
pollo97 is offline   Reply With Quote
Old 24/11/2017, 07:07 PM   #5
RedFusion
Gangsta
 
RedFusion's Avatar
 
Join Date: Nov 2009
Location: Sweden
Posts: 920
Reputation: 330
Default Re: Error last kills

Quote:
Originally Posted by pollo97 View Post
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 Code:
switch(weaponid) {
    case 0..46: { // Valid Weapon
        GetWeaponNameEx(id, wepname, sizeof wepname);
    }
    case 255: { // Unknown death reason
        wepname = "Death";
    }
}
__________________
Also known as fusez
RedFusion is offline   Reply With Quote
Old 26/11/2017, 06:42 PM   #6
RedGun2015
Huge Clucker
 
RedGun2015's Avatar
 
Join Date: Sep 2015
Location: Romania
Posts: 281
Reputation: 0
Default Re: Error last kills

Thanks, that was the problem.

Thanks guys for help.
RedGun2015 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GetWeaponNameEx ScIrUsna Scripting Help 3 01/04/2016 12:46 PM
error 017: undefined symbol,fatal error 107: too many error messages on one line Slicebook Scripting Help 11 04/05/2014 08:30 PM
An error has occured. (Error ID: 1064, You have an error in your SQL syntax; check the manual that corresponds.... rati555 Scripting Help 1 14/09/2012 07:45 PM
Registered plate stock error 'error 076: syntax error in the expression, or invalid function call' Deal-or-die Scripting Help 2 25/06/2012 03:12 PM
I get tagmismatch error, But i cant find any error error Swiftz Help Archive 1 16/04/2011 04:31 AM


All times are GMT. The time now is 02:16 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.