Raised This Month: $ Target: $400
 0% 

[HELP] Bug Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-24-2014 , 18:09   Re: [HELP] Bug Plugin
Reply With Quote #1

The thing with menu_additem is that all the values are saved behind the scenes in the form of bytes instead of cells (4 bytes).
If signed that means -128 to 127, and unsigned 0 to 255. PAWN doesn't have unsigned values.
You either lower the price, bit shift the value into multiple cells or convert it to a string.

I prefer the bitshifting because it's a predefined size that doesn't require parsing by natives, but it is also the most complicated one.

But performance is not an issue in the case of menus, you can just make it a string. Your data variable is already 5 cells, which is enough for 4 numbers and null.

Here's how to do it with strings:
Code:
Data[0] = CONST_MENU_DATA[i][mPRICE]
-->
Code:
num_to_str(CONST_MENU_DATA[i][mPRICE], Data, charsmax(Data));


Code:
if(g_Frags[id] < Data[0])
-->
Code:
if(g_Frags[id] < str_to_num(Data))


Code:
g_Frags[id] -= Data[0]
-->
Code:
g_Frags[id] -= str_to_num(Data)




Edit:
You could also apply the same logic as done with the hitzone string message
Code:
client_print(id, print_chat, "Raz3r.- Ahora haces danio en %s", CONST_MENU_DATA[item][mHITZONE])
Since "item" will match the array enumeration, you could use that for the frags cost as well.
This would be the preferred method as it saves all the getinfo native calls.
__________________

Last edited by Black Rose; 06-24-2014 at 18:25.
Black Rose is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 21:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode