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_menu( id )
{
if ( !g_iPlayerDispenser[ id ] && !gIsAdmin[ id ] )
{
client_print_color( id, print_team_red, MSG_NO_DISP );
return HAM_IGNORED;
}
new szItem[128];
new szItem1[128];
new msentry_item = menu_create( MENU_REMOVE, "cl_mendisp" );
new iOwner;
new ent = -1;
while ((ent = find_ent_by_class(ent, gDispenserClassname)))
{
if(pev_valid(ent))
{
iOwner = pev( ent, DISPENSER_OWNER );
if( iOwner != id && !gIsAdmin[ id ] )
{
continue;
}
new iLevel = pev ( ent, DISPENSER_LEVEL );
new iHealth = pev ( ent, pev_health );
format(szItem, 127, "%d", ent);
if ( gIsAdmin[ id ] )
{
format(szItem1, 127, MENU_ITEMADM, ent, gPlayerName[ iOwner ], iLevel, iHealth);
}
else
{
format(szItem1, 127, MENU_ITEM, ent, iLevel, iHealth);
}
menu_additem( msentry_item, szItem1, szItem, 0);
}
}
menu_setprop(msentry_item, MPROP_EXIT, MEXIT_ALL);
menu_setprop(msentry_item, MPROP_EXITNAME, MENU_QUIT );
menu_display(id, msentry_item, 0);
return PLUGIN_HANDLED;
}
public cl_mendisp( id, menu, item )
{
new s_Data[6], s_Name[64], i_Access, i_Callback;
menu_item_getinfo(menu, item, i_Access, s_Data, charsmax(s_Data), s_Name, charsmax(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_func( id )
{
if(!g_iPlayerDispenser[ id ] && !gIsAdmin[ id ])
{
client_print_color( id, print_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_create( MENU_CHOOSE, "cl_mend");
if(pev_valid(ent))
{
new iLevel = pev ( ent, DISPENSER_LEVEL );
new iHealth = pev ( ent, pev_health );
format(szItem, 127, "%d", ent);
menu_additem( msentry_item, MENU_DESTROY );
menu_addblank( msentry_item, 0);
menu_addblank( msentry_item, 0);
menu_addblank( msentry_item, 0);
format(szItem1, 127, "\wID \r%d", ent);
menu_addtext( msentry_item, szItem1);
format(szItem1, 127, MENU_LEVEL, iLevel);
menu_addtext( msentry_item, szItem1);
format(szItem1, 127, "\w[HP \y%d\w]", iHealth);
menu_addtext( msentry_item, szItem1);
}
menu_setprop(msentry_item, MPROP_EXIT, MEXIT_ALL );
menu_setprop(msentry_item, MPROP_EXITNAME, MENU_QUIT );
menu_display(id, msentry_item, 0);
return PLUGIN_HANDLED;
}
public cl_mend(id, menu, item)
{
item++;
new ent = touchdisp[id];
new iLevel = pev ( ent, DISPENSER_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 = pev( ent, DISPENSER_OWNER );
if ( iOwner == id )
{
cs_set_user_money( id, cs_get_user_money( id ) + ( cvar( CVAR_DESTROY_BONUS ) / 2 ) );
}
DeleteEntity( ent );
g_iPlayerDispenser[ iOwner ]--;
}
case 2:{
if ( !is_valid_ent ( ent ) )
return 0;
if ( iLevel != MAX_LEVELS )
{
client_print_color( id, print_team_red, MSG_MAX_LEVEL );
return 0;
}
if ( pev ( ent, DISPENSER_TEAM ) != _:cs_get_user_team ( id ) )
return 0;
new iCost = getCost( MAX_LEVELS - 1, gIsVip[ id ] ) * ( cvar( CVAR_DYNAMIC_COST ) ? g_iPlayerDispenser[ id ] : 1 );
if ( cs_get_user_money( id ) < iCost )
{
client_print_color( id, print_team_red, MSG_NO_MONEY, iCost );
return 0;
}
cs_set_user_money(id, cs_get_user_money( id ) - iCost );
set_pev( ent, pev_health, getHp( MAX_LEVELS - 1 ) );
}
}
}
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(idattacker, szName, charsmax(szName))
new szNameOwner[32]
get_user_name(iOwner, szNameOwner, charsmax(szNameOwner))
|