AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can't understand the code (https://forums.alliedmods.net/showthread.php?t=128471)

eNz0 06-01-2010 13:55

Can't understand the code
 
Hey, can someone explain me how does this menu work? (it's from gunxp mod by xBatista)

PHP Code:

public item_upgrades(id)
{
    
display_item_upgrades(idg_menuPosition[id] = 0);
    return 
PLUGIN_HANDLED;
}

public 
display_item_upgrades(idpos)
{    
    if(!
is_user_alive(id)) 
        return;

    static 
menuBody[510], len;
    
len 0

    
if(pos 0
    {
        return;
    }
    
    new 
start pos 8
    
if(start >= g_numberofitems
    {
        
start pos g_menuPosition[id]
    }

    
len += formatex(menuBody[len], sizeof menuBody len"%L"LANG_SERVER"TITLE_MENU_SHOP"get_user_xp(id), get_user_max_level(id))
    
    new 
end start 8
    
new keys MENU_KEY_0

    
if(end g_numberofitems
    {
        
end g_numberofitems
    
}
    
    new 
0
    
for(new startend; ++a
    {
        new 
1
        
new money

        money 
get_user_xp(id)

        if( 
money g_itemcost[i] ) 
        {
            if( 
g_PlayerItem[id][i] ) 
            {
                
len += formatex(menuBody[len], sizeof menuBody len,"%L"id"INACTIVE_MENU_SHOP_BOUGHT", ++bg_itemname[i], g_itemcost[i])
            }
            else
            {
                
len += formatex(menuBody[len], sizeof menuBody len,"%L"id"INACTIVE_MENU_SHOP", ++bg_itemname[i], g_itemcost[i])
            }
        } 
        else if( 
g_PlayerItem[id][i] ) 
        {
            
len += formatex(menuBody[len], sizeof menuBody len,"%L"id"INACTIVE_MENU_SHOP_BOUGHT", ++bg_itemname[i], g_itemcost[i])
        } 
        else 
        {
            
keys |= (1<<b)

            
len += formatex(menuBody[len], sizeof menuBody len,"%L"id"ACTIVE_MENU_SHOP", ++bg_itemname[i], g_itemcost[i])
        }
    }

    if(
end != g_numberofitems)
    {
        
len += formatex(menuBody[len], sizeof menuBody len"^n\r9. \w%L\r^n0. \w%L"id"NEXT_MENU"idpos "BACK_MENU" "EXIT_MENU")
        
keys |= MENU_KEY_9
    
}
    else
    {
        
len += formatex(menuBody[len], sizeof menuBody len"^n\r0. \w%L"idpos "BACK_MENU" "EXIT_MENU")
    }
    
    
show_menu(idkeysmenuBody, -1"Unlocks Shop")
}

public 
action_item_upgrades(idkey)
{
    switch(
key
    {
        case 
8display_item_upgrades(id, ++g_menuPosition[id]);
        case 
9display_item_upgrades(id, --g_menuPosition[id]);
        default:
        {
            if(!
is_user_alive(id)) 
            {
                return 
PLUGIN_HANDLED;
            }
            
            ++
key
            
new money
            
new plugin_id g_itemindex[g_menuPosition[id] * key]
            new 
item_id g_menuPosition[id] * key
            
new func get_func_id("gxm_item_enabled"plugin_id)

            
money get_user_xp(id)
            new 
cost g_itemcost[item_id]

            if(
money >= cost)
            {
                
callfunc_begin_i(funcplugin_id)
                
callfunc_push_int(id)
                
callfunc_end()

                
g_PlayerItem[id][item_id] = true

                
new overall money cost
                set_user_xp
(idoverall)

                
client_printcolor(id"/yItem Bought Successfully, Item: /g%s."g_itemname[item_id])
                
client_printcolor(id"/yDescription:/g%s."g_itemdesc[item_id])
                
display_item_upgrades(idg_menuPosition[id]);
            }
        }
    }
    return 
PLUGIN_HANDLED;



infek 06-01-2010 16:19

Re: Can't understand the code
 
alright do you see stuff like

BACK_MENU, NEXT_MENU, EXIT_MENU, ITEM_LIST???

well in gunxpmod theres a folder cstrike/data/lang/gunxpmod.txt

inside that txt it will show you what BACK_MENU and all those other things mean

eNz0 06-02-2010 03:59

Re: Can't understand the code
 
I know how %L function works, i just can't understand how is this menu handled.

Sylwester 06-02-2010 08:42

Re: Can't understand the code
 
It's a menu with multiple pages. You store all menu items in an array and display only several of them at any time. With page number (stored in global variable) and key number (menu handler argument) you can retrieve item index and perform adequate operations.


All times are GMT -4. The time now is 05:18.

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