Raised This Month: $ Target: $400
 0% 

Help with array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NiQu
Veteran Member
Join Date: Nov 2009
Old 11-26-2011 , 07:24   Help with array
Reply With Quote #1

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.
__________________
My Projects
  • RoTAPI V0.0.1 ------- Private
    • Progress - [||||||||||]
  • CashMod V0.0.6 ----- Public
    • Progress - [||||||||||]
  • CashMod V0.0.7 ----- Public
    • Progress - [||||||||||]
NiQu is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-26-2011 , 11:37   Re: Help with array
Reply With Quote #2

Create another cell array to hold the item levels.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
NiQu
Veteran Member
Join Date: Nov 2009
Old 11-26-2011 , 11:49   Re: Help with array
Reply With Quote #3

Quote:
Originally Posted by Emp` View Post
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 ?
__________________
My Projects
  • RoTAPI V0.0.1 ------- Private
    • Progress - [||||||||||]
  • CashMod V0.0.6 ----- Public
    • Progress - [||||||||||]
  • CashMod V0.0.7 ----- Public
    • Progress - [||||||||||]

Last edited by NiQu; 11-26-2011 at 12:02.
NiQu is offline
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

Forum Jump


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


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