I've been trying to hook the player_team event and change the players team to a different one, if what they are changing to is not what I want.
To experiment, I've been using the event to disable team changing by automatically switching the player back to their original team if they do switch, granted they are not switching to spec or disconnecting, and if they are just joining a team I automatically place them on CT.
I have this code, which should work, but for some reason it doesn't want to. Anybody know how to make this happen?
PHP Code:
new Handle:SwitchTimers[25]
public OnPluginStart()
{
HookEvent("player_team", evPlayerTeam, EventHookMode_Post)
RegAdminCmd("sm_teamit",TeamIt, ADMFLAG_BAN)
}
public evPlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"))
new oldteam = GetEventInt(event, "oldteam")
new Handle:pack
WritePackCell(pack, client)
WritePackCell(pack, oldteam)
SwitchTimers[client] = CreateTimer(0.1, SwitchPlayer, pack)
}
public Action:SwitchPlayer(Handle:timer, Handle:pack)
{
new client, oldteam
ResetPack(pack)
client = ReadPackCell(pack)
oldteam = ReadPackCell(pack)
if (oldteam == 0 || oldteam == 1)
{
oldteam = 3
}
CS_SwitchTeam(client, oldteam)
CS_RespawnPlayer(client)
PrintToChat(client, "[SM] Sorry, team changing is disabled!")
SwitchTimers[client] = INVALID_HANDLE
}