i have do something like this.
PHP Code:
int cheat_client = -1;
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
cheat_client = i;
break;
}
}
if( !L4D_GetRandomPZSpawnPosition(cheat_client,class,5,{0.0,0.0,0.0}) )//这个玩家附近的位置, 类型, 次数, 无用的vec
{
LogMessage("找位失败, 正在重新找位.");
CreateTimer(1.0,Timer_CreateInfectedBotByClass,class,TIMER_FLAG_NO_MAPCHANGE);
return;
}
int bot = CreateFakeClient("Infected Bot");
if( bot != 0 )
{
ChangeClientTeam(bot,TEAM_INFECTED);
KickClient(bot);
switch(class)
{
case CLASS_CHARGER:
CheatCommand(cheat_client, "z_spawn_old", "charger auto");
case CLASS_HUNTER:
CheatCommand(cheat_client, "z_spawn_old", "hunter auto");
case CLASS_JOCKEY:
CheatCommand(cheat_client, "z_spawn_old", "jockey auto");
case CLASS_SMOKER:
CheatCommand(cheat_client, "z_spawn_old", "smoker auto");
case CLASS_BOOMER:
CheatCommand(cheat_client, "z_spawn_old", "boomer auto");
case CLASS_SPITTER:
CheatCommand(cheat_client, "z_spawn_old", "spitter auto");
}
}
It prevent most of the issue about "couldn't find position", but sometime it happend again.
I guess that maybe check position before spawn is not perfect. Harry said that CreateFakeClient is too expensive, and usually late out in tick.
I look up some .sp file about infected_bot_control, they use SDKCall(NextBotxxxxxxx) to spawn infectedbot, and use the return value of SDKCall to check whether it spawn correctly. But "z_spawn_old" cmd has no return value.
I think DHook z_spawn_old(const CCommand *) , get and check the return value will help, but i don't know how to do this because it return a warning() func in failed and i don't know which type of return is appropriate.
Can someone give a suggestion?