Help with array
Hi, I'm having some issues with arrays. I have a menu where people can buy items such as Extra Health and Armor etc and these items have multiple levels and the higher level the more Health/Armor you get.
How would i be able to save the item level to a variable specificly for that user and that item ?
Variables, init etc:
PHP Code:
enum _:ItemData {
ItemName[64],
ItemDesc[257],
ItemStartCost,
ItemMaxLevel,
ItemMaxAmount,
ItemSaveName[33],
ItemCostInterval,
ItemAmountInterval,
ItemExeWhen[33],
ItemSubMenu[33]
};
new Array:AllItems; //Array of all the items
new ItemLevel[33][256]; //The level of items
public plugin_init() {
AllItems = ArrayCreate( ItemData );
}
Menu:
PHP Code:
ShowDynamicMenu(id, iPage=0, SubMenu[]="NONE") {
new iSize = ArraySize( AllItems );
if( !iSize )
{
return PLUGIN_HANDLED;
}
new data[ItemData];
formatex(g_replace_text, sizeof(g_replace_text) - 1, "%L\R\yby %s", id, "MODAPI_MENU_TITLE", PLUGIN_AUTHOR);
mapi_replace(id, "NONE", P_NULL, P_NULL);
new menu = menu_create( g_replace_text, "HandleDynamicMenu" );
new num[8];
new cost;
for( new i = 0; i < iSize; i++ )
{
//The menu code, left out because its big.
}
menu_display( id, menu, iPage );
return PLUGIN_CONTINUE;
}
Menu Handler:
PHP Code:
public HandleDynamicMenu(id, menu, item) {
if( item == MENU_EXIT )
{
menu_destroy( menu );
CMD_Shop(id); //Main shop menu
return PLUGIN_HANDLED;
}
new num[6];
new callback;
new access;
menu_item_getinfo( menu, item, access, num, 5, _, _, callback );
new chosen = str_to_num( num );
new data[ItemData];
ArrayGetArray( AllItems, chosen, data );
new iAfterCurrency = iCurrency[id] - mapi_get_item_cost(id, data[ItemSaveName]);
if( iAfterCurrency < 0 ) {
Mapi_Print(id, "^x04[%s]^x01You don't have enough %s to buy that!", PluginPrefix, CurrencyName);
ShowDynamicMenu(id, 0, data[ItemSubMenu]);
} else if(ItemLevel[id][data[ItemSaveName]] >= data[ItemMaxLevel]) {
Mapi_Print(id, "You already have the max level of this item!");
ShowDynamicMenu(id, 0, data[ItemSubMenu]);
} else {
iCurrency[id] = iAfterCurrency;
new iReturn;
ItemLevel[id][data[ItemSaveName]] += 1; //This is where the problem is i think!
ShowDynamicMenu(id, 0, data[ItemSubMenu]);
}
menu_destroy( menu );
return PLUGIN_HANDLED;
}
I think that's all the code for it. The problem is, when two item have the same first character in ItemSaveName, it gets saved to the same ItemLevel.
I've tried fixing it for a long time but i never got it to work.
So, can anyone see any problem with the code ?
If more code is needed that i've forgotten to provide, tell me and ill provide it.
|