AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with array (https://forums.alliedmods.net/showthread.php?t=172801)

NiQu 11-26-2011 07:24

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 ArrayCreateItemData );


Menu:
PHP Code:

ShowDynamicMenu(idiPage=0SubMenu[]="NONE") {
    new 
iSize ArraySizeAllItems );
    
    if( !
iSize )
    {
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[ItemData];
    
    
formatex(g_replace_textsizeof(g_replace_text) - 1"%L\R\yby %s"id"MODAPI_MENU_TITLE"PLUGIN_AUTHOR);
    
mapi_replace(id"NONE"P_NULLP_NULL);
    new 
menu menu_createg_replace_text"HandleDynamicMenu" );
    
    new 
num[8];
    new 
cost;
    
    for( new 
0iSizei++ )
    {
        
//The menu code, left out because its big.
    
}
    
    
menu_displayidmenuiPage );
    
    return 
PLUGIN_CONTINUE;


Menu Handler:
PHP Code:

public HandleDynamicMenu(idmenuitem) {
    if( 
item == MENU_EXIT )
    {
        
menu_destroymenu );
        
CMD_Shop(id); //Main shop menu
        
        
return PLUGIN_HANDLED;
    }
    
    new 
num[6];
    new 
callback;
    new 
access;
    
    
menu_item_getinfomenuitemaccessnum5__callback );
    new 
chosen str_to_numnum );
    
    new 
data[ItemData];
    
ArrayGetArrayAllItemschosendata );
    
    new 
iAfterCurrency iCurrency[id] - mapi_get_item_cost(iddata[ItemSaveName]);
    
    if( 
iAfterCurrency ) {
        
Mapi_Print(id"^x04[%s]^x01You don't have enough %s to buy that!"PluginPrefixCurrencyName);
        
ShowDynamicMenu(id0data[ItemSubMenu]);
    } else if(
ItemLevel[id][data[ItemSaveName]] >= data[ItemMaxLevel]) {
        
Mapi_Print(id"You already have the max level of this item!");
        
ShowDynamicMenu(id0data[ItemSubMenu]);
    } else {
        
iCurrency[id] = iAfterCurrency;
        new 
iReturn;

        
ItemLevel[id][data[ItemSaveName]] += 1//This is where the problem is i think!
        
ShowDynamicMenu(id0data[ItemSubMenu]);
    }
    
    
menu_destroymenu );
    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.

Emp` 11-26-2011 11:37

Re: Help with array
 
Create another cell array to hold the item levels.

NiQu 11-26-2011 11:49

Re: Help with array
 
Quote:

Originally Posted by Emp` (Post 1603043)
Create another cell array to hold the item levels.

I tried but with no success, I'm probably to inexperienced when it comes to arrays.
Could you provide an example ?


All times are GMT -4. The time now is 08:32.

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