So this tutorial is about how to add limit to any extra item in ZP50, since i saw a lot of "limiting" requests.......
So First of all,
Step 1 :-
Add a define on how much limit u want for that item
PHP Code:
#define MyItem_Limit 10 // This is just an example , put any number u want instead of 10 as limit
Step 2:-
Make a new variable to store how many times has the use bought our item
PHP Code:
new MyItemHasUser[33] // Register a new variable
Step 3:-
Find something like this : (It might differ from the function below, so jut make sure it has "zp_fw_items_select_pre")
PHP Code:
public zp_fw_items_select_pre(id, itemid, ig) //This function is called before a user has bought an extra item
And there check if the user has bought the item within the limit and show how much more he can buy beside the name of the item in the menu
Using smthing like this
First find this:
PHP Code:
if(itemid == MyRegisteredItem) // This checks whether it is our item or not
{
blablablab............. // rest of the code that restricts the item for zombies/human/neme/surv etc...
}
then in it add smthing like this:
PHP Code:
new text[32] // Make a new buffer text to add
format(text, charsmax(text), "[%d/%d]", g_flare[id],FLARE_LIMIT) // Format it to what we want
zp_items_menu_text_add(text) // add the text after the items name in the menu
After that to check the condition add this
PHP Code:
if(MyItemHasUser[id] >= MyItem_Limit) // check whether the users purchase are greater than / equal to the limit
{
return ZP_ITEM_NOT_AVAILABLE // this "return" is used to not let the use purchase the item if his purchase has reached the limit
}
So now we are done with the checking and restricting part....
Step 4:-
Find this: (Again it can differ just make sure it has "zp_fw_items_select_post")
PHP Code:
public zp_fw_items_select_post(id, itemid, ig) // this is a function called after a use selects an extra item
{
blablabla...... // the rest of the code of the function
}
In that find
PHP Code:
if(itemid == MyRegisteredItem) // This part of the code checks whether it is our item or not
{
blablab.......... // the rest of the code in this function
}
then put this part of code in it
PHP Code:
MyItemHasUser[id]++ // Increase the variable (purchase) by 1
So this will increase the variable by 1 per purchase
Step 5:-
To finally reset variables on every new spawn (new round or after becoming zombie) add this anywhere in the code
PHP Code:
public zp_fw_core_spawn_post(id)
{
MyItemHasUser[id] = 0 // To reset the variable at new spawn so that purchases become 0
}
NOTE:- Here "MyRegisteredItem", "MyItemHasUser" etc are variables so dont stick to them, in the real code they might be named different so try to find similarities between this and the code u wanna edit......... that will help u understand
Credits:-
Me
Blizzard_87 (Correcting me so that no one gets confused)
__________________