I think the only benefit of this extension is
I can get the client id of survivor bot, instead of "FakeClient" id
For my example code,
PHP Code:
RegConsoleCmd("sm_join", JoinTeam, "Spawn a bot and Attempt to join");
without ext.
Spoiler
PHP Code:
public Action JoinTeam(int client,int args)
{
int fakeclient = CreateFakeClient("FakeClient");
if(fakeclient != 0)
{
ChangeClientTeam(fakeclient, TEAM_SURVIVORS)
if(DispatchKeyValue(fakeclient, "classname", "survivorbot") == true)
{
// spawn the client
if(DispatchSpawn(fakeclient) == true)
{
//do something
}
}
}
//Kick the "FakeClient" so it becomes a regular bot
KickClient(fakeclient);
int fakebot = FindBotToTakeOver(); //search fake bot again
SDKCall(hSetHumanSpec, fakebot, client); //take over the bot, "@_ZN11SurvivorBot17SetHumanSpectatorEP13CTerrorPlayer"
return Plugin_Handled;
}
int FindBotToTakeOver()
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
if (IsFakeClient(i) && GetClientTeam(i)==2 && !HasIdlePlayer(i) && IsPlayerAlive(i))
return i;
}
}
return 0;
}
bool HasIdlePlayer(int bot)
{
if(HasEntProp(bot, Prop_Send, "m_humanSpectatorUserID"))
{
int client = GetClientOfUserId(GetEntProp(bot, Prop_Send, "m_humanSpectatorUserID"));
if(client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && IsClientObserver(client))
{
return true;
}
}
return false;
}
with ext
Spoiler
PHP Code:
public Action JoinTeam(int client,int args)
{
int index = CreateSurvivorBot();
if(index > 0 && IsClientInGame(index))
SDKCall(hSetHumanSpec, index, client);
return Plugin_Handled;
}
__________________