AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optymalization code. (https://forums.alliedmods.net/showthread.php?t=82802)

GoGoGo 12-30-2008 07:01

Optymalization code.
 
PHP Code:

/* Start menu admin */

public actionTestMenu(idkey)
{
    switch (
key)
    {
        case 
7:
        {
            ++
g_menuOption[id]
            
            
g_menuOption[id] %= ArraySize(g_Testsettings);
            
            
g_menuSettings[id] = ArrayGetCell(g_Testsettingsg_menuOption[id]);
            
            
displayTestMenu(idg_menuPosition[id]);
        }
        case 
8: {
        if(
gr_menu2[id]){
        return 
PLUGIN_HANDLED
        
}
        
displayTestMenu(id, ++g_menuPosition[id])
        }
        case 
9: {
        if(
gr_menu2[id]){
        return 
PLUGIN_HANDLED        
        
}
        
displayTestMenu(id, --g_menuPosition[id])
            }
        default:
        {
        new 
m_player g_menuPlayers[id][g_menuPosition[id] * key
        new 
m_name2[32]
        new 
m_authid[32], m_authid2[32], m_name[32]
            
            
get_user_name(m_playerm_name231)

            if (!
is_user_alive(m_player))
            {
                
client_print(idprint_chat"dead?")
                
displayTestMenu(idg_menuPosition[id])
                return 
PLUGIN_HANDLED
            
}



            
get_user_authid(idm_authid31)
            
get_user_authid(m_playerm_authid231)
            
get_user_name(idm_name31)

            if (!
g_menuOption[id])
            {
            
            
client_cmd(id,"slot10"
            
m_plejer m_player 
            
            
if(!is_user_alive(m_plejer ))
            return 
PLUGIN_HANDLED    
            
            
//do something?
            /*---------*/
            
return PLUGIN_HANDLED            
            
            
            
}

            
displayTestMenu(idg_menuPosition[id])
        }
    }
    
    return 
PLUGIN_HANDLED
}

displayTestMenu(idpos)
{
    if (
pos 0)
        return

    
get_players(g_menuPlayers[id], g_menuPlayersNum[id])

    new 
menuBody[1024]
    new 
0
    
new i
    
new name[32], team[4]
    new 
start pos 7

    
if (start >= g_menuPlayersNum[id])
        
start pos g_menuPosition[id] = 0

    
new len format(menuBody1023,  "\yTest Admin Menu %d/%d\w^n^n"pos 1, (g_menuPlayersNum[id] / + ((g_menuPlayersNum[id] % 7))))
    new 
end start 7
    
new keys MENU_KEY_0|MENU_KEY_8

    
if (end g_menuPlayersNum[id])
        
end g_menuPlayersNum[id]

    for (new 
startend; ++a)
    {
        
g_menuPlayers[id][a]
        
get_user_name(iname31)
        
        
/*if (g_cstrike)
        {
            if (cs_get_user_team(i) == CS_TEAM_T)
            {
                copy(team, 3, "TE")
            }
            else if (cs_get_user_team(i) == CS_TEAM_CT)
            {
                copy(team, 3, "CT")
            } else {
                get_user_team(i, team, 3)
            }
        } else {
            get_user_team(i, team, 3)
        }*/

        
if (is_user_alive(i))
        {
            
            
keys |= (1<<b)
                
            if (
is_user_admin(i))
                
len += format(menuBody[len], 1023-len"\r%d. \w%s \r* \w   ^n", ++bname)
            else
                
len += format(menuBody[len], 1023-len"\r%d. \w%s   ^n", ++bname)
        }else if(!
is_user_alive(i)){

            
            if (
is_user_admin(i))
                
len += format(menuBody[len], 1023-len"\d%d. %s \r* \w   ^n\w", ++bname)
            else
                
len += format(menuBody[len], 1023-len"\d%d. %s    ^n\w", ++bname)
        }
    }
    


    if (
end != g_menuPlayersNum[id])
    {
        
format(menuBody[len], 1023-len"^n9. %L...^n0. %L"id"MORE"idpos "BACK" "EXIT")
        
keys |= MENU_KEY_9
    
}
    else
        
format(menuBody[len], 1023-len"^n0. %L"idpos "BACK" "EXIT")
        
        
    
//menu_setprop(menuBody[len], MPROP_PERPAGE, 7);

    
show_menu(idkeysmenuBody, -1"Admin Menu")
}

public 
cmdTestMenu(idlevelcid)
{
    
//if (!cmd_access(id, level, cid, 1))
        //return PLUGIN_HANDLED

    
g_menuOption[id] = 0

        
// should never happen, but failsafe
    
g_menuSettings[id] = 0
    
//menu_setprop(displayTestMenu, MPROP_PERPAGE, 7);
    
displayTestMenu(idg_menuPosition[id] = 0)

    return 
PLUGIN_HANDLED


Hi,

I have problem, I made code like this but is strange/dirty/unoptymized code can somebody help me to change it? I got this code from some plugin try to do something but you can see it is not good code.

Coksnuss 12-30-2008 11:56

Re: Optymalization code.
 
Maybe you should check out this:
http://forums.alliedmods.net/showthread.php?t=6481

GoGoGo 01-01-2009 14:14

Re: Optymalization code.
 
Thakns, but not names are bad but whole code :)

(I will give you +k )


All times are GMT -4. The time now is 09:11.

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