I'm writing a plugin that executes client commands, but I'm still new to SourcePawn. I wrote segments of code for executing commands on individual players, a team, or everyone, but I'm having trouble with pretty much every part except for executing commands on individual players. That's the only one I got right. This code executes a client command on the CT team in Counter-Strike: Source:
Code:
public Action:Command_Exec_CT(client, args) // Executes on CTs
{
if (args != 1) // Must have one argument, otherwise won't work
{
ReplyToCommand(client, "[SM] Syntax: sm_exec_ct <command>")
return Plugin_Handled
}
new String:TheCommand[64] // String to hold command, first argument
GetCmdArg(1, TheCommand, sizeof(TheCommand)) // Get argument
/**
* This loop goes through each of the players, and determines if that
* player is a CT. If so, execute the client command. If not, move on.
* NumPlayers is equal to GetMaxClients(), and index is the player index
*/
for(new index=1; index<=NumPlayers; index++)
{
if (!IsClientConnected(index))
{
continue
}
if (IsFakeClient(index))
{
continue
}
if (GetClientTeam(index) == 3) // 3 is for CT
{
FakeClientCommand(index, TheCommand) // Execute
}
}
return Plugin_Handled // Finish executing
}
The problem with this code is that when I type this:
Code:
sm_exec_ct "say hey"
Nothing happens to the CTs. The problem is probably something very simple. Any help would be appreciated. Thanks.