AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   destroy dispenser (https://forums.alliedmods.net/showthread.php?t=338603)

yagami 07-16-2022 00:39

destroy dispenser
 
I have this function here where the admin can destroy the dispenser of other players, I wanted to pass this function to another dispenser, but this function is very strange to me the way it was made so I could not
Someone could at least try to separate only the function where admin can destroy the dispenser of another player



PHP Code:

public disppp_menuid )
{
    if ( !
g_iPlayerDispenserid ] && !gIsAdminid ] )
    {
        
client_print_coloridprint_team_red,  MSG_NO_DISP );
        return 
HAM_IGNORED;
    }

    new 
szItem[128];
    new 
szItem1[128];
    new 
msentry_item menu_createMENU_REMOVE"cl_mendisp" );
    new 
iOwner;

    new 
ent = -1;

    while ((
ent find_ent_by_class(entgDispenserClassname)))
    {
        if(
pev_valid(ent))
        {
            
iOwner peventDISPENSER_OWNER );

            if( 
iOwner != id && !gIsAdminid ] )
            {
                continue;
            }

            new 
iLevel pev entDISPENSER_LEVEL );
            new 
iHealth pev entpev_health );

            
format(szItem127"%d"ent);

            if ( 
gIsAdminid ] )
            {
                
format(szItem1127MENU_ITEMADMentgPlayerNameiOwner ], iLeveliHealth);
            }
            else
            {
                
format(szItem1127MENU_ITEMentiLeveliHealth);
            }
            
menu_additemmsentry_itemszItem1szItem0);
        }
    }

    
menu_setprop(msentry_itemMPROP_EXITMEXIT_ALL);
    
menu_setprop(msentry_itemMPROP_EXITNAMEMENU_QUIT );
    
menu_display(idmsentry_item0);

    return 
PLUGIN_HANDLED;
}

public 
cl_mendispidmenuitem )
{
    new 
s_Data[6], s_Name[64], i_Accessi_Callback;

    
menu_item_getinfo(menuitemi_Accesss_Datacharsmax(s_Data), s_Namecharsmax(s_Name), i_Callback);

    new 
i_Key str_to_num(s_Data);

    
menu_destroy(menu);

    if(
i_Key == 0) return 0;

    if ( !
is_valid_ent i_Key ) ) return 0;

    
touchdisp[id] = i_Key;
    
disp_menu_func(id);

    return 
1;
}

public 
disp_menu_funcid )
{
    if(!
g_iPlayerDispenserid ] && !gIsAdminid ])
    {
        
client_print_coloridprint_team_red,  MSG_NO_DISP );
        return 
HAM_IGNORED;
    }

    new 
szItem[128];
    new 
szItem1[128];
    new 
ent touchdisp[id];

    if(
ent==0) return PLUGIN_HANDLED;

    new 
msentry_item menu_createMENU_CHOOSE"cl_mend");

    if(
pev_valid(ent))
    {
        new 
iLevel pev entDISPENSER_LEVEL );
        new 
iHealth pev entpev_health );

        
format(szItem127"%d"ent);

        
menu_additemmsentry_itemMENU_DESTROY );
        
menu_addblankmsentry_item0);
        
menu_addblankmsentry_item0);
        
menu_addblankmsentry_item0);

        
format(szItem1127"\wID \r%d"ent);
        
menu_addtextmsentry_itemszItem1);
        
        
format(szItem1127MENU_LEVELiLevel);
        
menu_addtextmsentry_itemszItem1);

        
format(szItem1127"\w[HP \y%d\w]"iHealth);
        
menu_addtextmsentry_itemszItem1);
    }

    
menu_setprop(msentry_itemMPROP_EXITMEXIT_ALL );
    
menu_setprop(msentry_itemMPROP_EXITNAMEMENU_QUIT );
    
menu_display(idmsentry_item0);

    return 
PLUGIN_HANDLED;
}

public 
cl_mend(idmenuitem)
{
    
item++;

    new 
ent touchdisp[id];
    new 
iLevel pev entDISPENSER_LEVEL );

    
menu_destroy(menu);

    if(
item == 0) return 0;

    if(
pev_valid(ent))
    {
        switch(
item)
        {
            case 
1:
            {
                if ( !
is_valid_ent ent ) ) return 0;
                
                new 
iOwner peventDISPENSER_OWNER );

                if ( 
iOwner == id )
                {
                    
cs_set_user_moneyidcs_get_user_moneyid ) + ( cvarCVAR_DESTROY_BONUS ) / ) );
                }
                
DeleteEntityent );
                
g_iPlayerDispenseriOwner ]--;
            }
            case 
2:{
                if ( !
is_valid_ent ent ) )
                    return 
0;

                if ( 
iLevel != MAX_LEVELS )
                {
                    
client_print_coloridprint_team_red,  MSG_MAX_LEVEL );
                    return 
0;
                }

                if ( 
pev entDISPENSER_TEAM ) != _:cs_get_user_team id ) )
                    return 
0;

                new 
iCost getCostMAX_LEVELS 1gIsVipid ] ) * ( cvarCVAR_DYNAMIC_COST ) ? g_iPlayerDispenserid ] : );

                if ( 
cs_get_user_moneyid ) < iCost )
                {
                    
client_print_coloridprint_team_red,  MSG_NO_MONEYiCost );
                    return 
0;
                }

                
cs_set_user_money(idcs_get_user_moneyid ) - iCost );

                
set_peventpev_healthgetHpMAX_LEVELS ) );
            }
        }
    }
    return 
1;


@edit

Another thing is that in this new dispenser there is no variable showing the top "gPlayerName" player name

in this dispenser it is doing like this
PHP Code:

new szName[32]
            
get_user_name(idattackerszNamecharsmax(szName))

            new 
szNameOwner[32]
            
get_user_name(iOwnerszNameOwnercharsmax(szNameOwner)) 



All times are GMT -4. The time now is 15:36.

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