PDA

View Full Version : Block menu to spectators and terrorists.


rodrigo286
02-17-2012, 07:47
The menu of my plugin need to have blocked access for terrorists and spectators, I've tried several codes like the below, the terrorists are locked but viewers can still access the menu:

public Action:ConsoleCmd(client, args)
{
if(GetClientTeam(client) != CS_TEAM_CT)
{
PrintToChat( client, "\x03[\x04CSS\x03]\x01 Only CTs!" );
return Plugin_Continue;
}

new Handle:menu = CreateMenu(MenuHandler1);
SetMenuTitle(menu, "MENU TEST");
AddMenuItem(menu, "a", "Buy 1");
AddMenuItem(menu, "b", "Buy 2");
SetMenuExitButton(menu, true);
SetMenuExitBackButton(menu, false);
DisplayMenu(menu, client, 0);

return Plugin_Handled;
}


public Action:ConsoleCmd(client, args)
{
if(GetClientTeam(client) == CS_TEAM_T || !IsPlayerAlive(client))
{
PrintToChat( client, "\x03[\x04CSS\x03]\x01 Only CTs!" );
return Plugin_Continue;
}

new Handle:menu = CreateMenu(MenuHandler1);
SetMenuTitle(menu, "MENU TEST");
AddMenuItem(menu, "a", "Buy 1");
AddMenuItem(menu, "b", "Buy 2");
SetMenuExitButton(menu, true);
SetMenuExitBackButton(menu, false);
DisplayMenu(menu, client, 0);

return Plugin_Handled;
}

Anyone know any way to do this and work?

Thanks!

Despirator
02-17-2012, 08:23
public Action:ConsoleCmd(client, args)
{
switch (GetClientTeam(client))
{
case CS_TEAM_CT :
{
new Handle:menu = CreateMenu(MenuHandler1);
SetMenuTitle(menu, "MENU TEST");
AddMenuItem(menu, "a", "Buy 1");
AddMenuItem(menu, "b", "Buy 2");
SetMenuExitButton(menu, true);
SetMenuExitBackButton(menu, false);
DisplayMenu(menu, client, 0);
}
default :
{
PrintToChat( client, "\x03[\x04CSS\x03]\x01 Only CTs!" );
}
}

return Plugin_Handled;
}

rodrigo286
02-17-2012, 08:39
Thanks, works perfectly!

iGENIUS
02-17-2012, 09:31
an if/else statement should be used in this case, afaik switch is commonly used for anything that exceeds 2 options, might be a personal thought.

Powerlord
02-17-2012, 09:49
if(GetClientTeam(client) == CS_TEAM_T || !IsPlayerAlive(client))Shouldn't that be
if(GetClientTeam(client) == CS_TEAM_T && IsPlayerAlive(client))

rodrigo286
02-17-2012, 18:03
Thanks for others responses.

But I've got.