Quote:
Originally Posted by cidra
I know, but if i add some controls before return Plugin_Handled; it should block the usage of the command only in specific circumstances, am i right? So what if someone select "auto-select team" (So basically types jointeam auto in console)?
Just asking: why can't i use HookEvent to prevent team changes while i can do that to prevent class changes? 
|
Something people overlook way too often is that a command listener does work similar to a command in the idea that it can read arguments that are sent. Arguements do get sent in jointeam. teamid is usually one of these.
Using this obtuse information, we could further implement a case-by-case basis on how hard we want to bone people.
Soooo, something like this is what I use in one of my plugins. Clearly a modifimidicated version of jointeam. If this doesn't help you at all, then well sorry for wasting your time lol.
You'll see something like "teamJoinAuth" in the code. I use GetRandomInt to generate that at plugin start. Ideally a pseudo anti-bypass or something.
PHP Code:
public Action:joinListener(client, const String:command[], args)
{
if(g_bLive)
{
CPrintToChat(client, "%s You are currently unable to switch teams.", CHATTAG);
return Plugin_Handled;
}
if(!g_bSwitch[client])
{
decl String:sTeam[32];
GetCmdArg(1, sTeam, sizeof(sTeam));
new newTeam = StringToInt(sTeam);
if(args == 1)
{
new Handle:dataPack = CreateDataPack();
WritePackCell(dataPack, GetClientUserId(client));
WritePackCell(dataPack, newTeam);
g_bSwitch[client] = true;
CreateTimer(5.0, teamJoin, dataPack);
CPrintToChat(client, "%s Waiting five seconds to join another team...", CHATTAG);
return Plugin_Handled;
}
else if(args == 2) //Jointeam function
{
decl String:sAuth[32];
GetCmdArg(2, sAuth, sizeof(sAuth));
if(StringToInt(sAuth) == teamJoinAuth)
{
g_bSwitch[client] = false;
return Plugin_Changed;
}
else return Plugin_Handled;
}
}
return Plugin_Handled;
}
public Action:teamJoin(Handle:timer, Handle:dataPack)
{
ResetPack(dataPack);
new client = GetClientOfUserId(ReadPackCell(dataPack));
new team = ReadPackCell(dataPack);
ChangeClientTeam(client, team);
if(IsPlayerAlive(client)) ForcePlayerSuicide(client);
ClientCommand(client, "jointeam %i %i", team, teamJoinAuth);
decl String:teamFmt[16];
switch(team)
{
case 0, 1: teamFmt = "Spectator";
case TEAM_COMBINE: teamFmt = "Blue";
case TEAM_REBEL: teamFmt = "Red";
}
CPrintToChatAll("%s {white}%N{default} has joined team: {white}%s{default}.", CHATTAG, client, teamFmt);
g_bSwitch[client] = false;
return Plugin_Handled;
}