Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
|
01-17-2021
, 13:49
Re: [TF2] Problem with Bot Creation Plugin
|
#3
|
Quote:
Originally Posted by PC Gamer
Are you trying to create Puppet Bots? I'm already running Bots on my server. When I use the code above the new Bot is created and it just stands there without moving. The server console will display "Cannot verify load for invalid steam ID [A:1 415:1]".
Anyway... I was able to reproduce and correct the Engineer error. I'm certainly no expert but I believe the SourceMod GetRandomInt function is to blame in this case. It started working correctly when I replaced it with GetRandomUInt. The invalid steam ID problem still exists.
Edited code:
PHP Code:
#include <sourcemod> #include <tf2_stocks>
public void OnPluginStart() { RegAdminCmd("sm_bot", Command_Bot, ADMFLAG_CHEATS, "Create a bot"); }
public Action Command_Bot(int iClient, int iArgs) { TFTeam team = TF2_GetRandomTeam(); TFClassType class = TF2_GetRandomClass(); if (iArgs > 0) { /* Get the first argument */ char sArg1[32]; GetCmdArg(1, sArg1, sizeof(sArg1)); team = TF2_GetTeamFromString(sArg1); if (team < TFTeam_Red) { ReplyToCommand(iClient, "[SM] Invalid team specified!"); return Plugin_Handled; }
if (iArgs > 1) { /* Get the second argument */ char sArg2[32]; GetCmdArg(2, sArg2, sizeof(sArg2)); class = TF2_GetClassFromString(sArg2); if (class == TFClass_Unknown) { ReplyToCommand(iClient, "[SM] Invalid class specified!"); return Plugin_Handled; } } }
ReplyToCommand(iClient, "[SM] team == %d", team); ReplyToCommand(iClient, "[SM] class == %d", class);
char sTeam[32], sClass[32]; TF2_GetTeamName(team, sTeam, sizeof(sTeam)); TF2_GetClassName(class, sClass, sizeof(sClass));
CapitalizeFirstLetter(sTeam); CapitalizeFirstLetter(sClass);
char sName[MAX_NAME_LENGTH]; Format(sName, sizeof(sName), "%s %s #%i", sTeam, sClass, TF2_GetBotCount(team, class)); if (!TF2_CreateBot(sName, team, class)) { ReplyToCommand(iClient, "[SM] Failure creating bot!"); return Plugin_Handled; }
ReplyToCommand(iClient, "[SM] Successfully created bot!"); return Plugin_Handled; }
stock TFTeam TF2_GetRandomTeam() { return view_as<TFTeam>(GetRandomUInt(2, 3)); }
stock TFClassType TF2_GetRandomClass() { return view_as<TFClassType>(GetRandomUInt(1, 9)); }
stock TFTeam TF2_GetTeamFromString(const char[] sBuffer) { if (StrEqual(sBuffer, "1", false) || StrEqual(sBuffer, "spectator", false)) { return TFTeam_Spectator; }
if (StrEqual(sBuffer, "2", false) || StrEqual(sBuffer, "red", false)) { return TFTeam_Red; }
if (StrEqual(sBuffer, "3", false) || StrEqual(sBuffer, "blue", false)) { return TFTeam_Blue; }
return TFTeam_Unassigned; }
stock void TF2_GetTeamName(TFTeam team, char[] sBuffer, int iMaxlength) { switch (team) { case TFTeam_Unassigned: { Format(sBuffer, iMaxlength, "unassigned"); }
case TFTeam_Spectator: { Format(sBuffer, iMaxlength, "spectator"); }
case TFTeam_Red: { Format(sBuffer, iMaxlength, "red"); }
case TFTeam_Blue: { Format(sBuffer, iMaxlength, "blue"); } } }
// This is basically TF2_GetClass() but it works better stock TFClassType TF2_GetClassFromString(const char[] sBuffer) { if (StrEqual(sBuffer, "scout", false)) { return TFClass_Scout; }
if (StrEqual(sBuffer, "soldier", false)) { return TFClass_Soldier; }
if (StrEqual(sBuffer, "pyro", false)) { return TFClass_Pyro; }
if (StrEqual(sBuffer, "demoman", false)) { return TFClass_DemoMan; }
if (StrEqual(sBuffer, "heavy", false)) { return TFClass_Heavy; }
if (StrEqual(sBuffer, "engineer", false)) { return TFClass_Engineer; }
if (StrEqual(sBuffer, "medic", false)) { return TFClass_Medic; }
if (StrEqual(sBuffer, "sniper", false)) { return TFClass_Sniper; }
if (StrEqual(sBuffer, "spy", false)) { return TFClass_Spy; }
return TFClass_Unknown; }
stock void TF2_GetClassName(TFClassType class, char[] sBuffer, int iMaxlength) { switch (class) { case TFClass_Scout: { Format(sBuffer, iMaxlength, "scout"); }
case TFClass_Soldier: { Format(sBuffer, iMaxlength, "soldier"); }
case TFClass_Pyro: { Format(sBuffer, iMaxlength, "pyro"); }
case TFClass_DemoMan: { Format(sBuffer, iMaxlength, "demoman"); }
case TFClass_Heavy: { Format(sBuffer, iMaxlength, "heavy"); }
case TFClass_Engineer: { Format(sBuffer, iMaxlength, "engineer"); }
case TFClass_Medic: { Format(sBuffer, iMaxlength, "medic"); }
case TFClass_Sniper: { Format(sBuffer, iMaxlength, "sniper"); }
case TFClass_Spy: { Format(sBuffer, iMaxlength, "spy"); }
case TFClass_Unknown: { Format(sBuffer, iMaxlength, "unknown"); } } }
stock int TF2_GetBotCount(TFTeam team, TFClassType class) { int iCount = 1; for (int i = 1; i <= MaxClients; i++) { if (IsClientInGame(i) && IsFakeClient(i) && TF2_GetClientTeam(i) == team && TF2_GetPlayerClass(i) == class) { iCount++; } }
return iCount; }
stock bool TF2_CreateBot(const char[] sName, TFTeam team, TFClassType class) { int iBot = CreateFakeClient(sName); PrintToChatAll("Debug: Creating %s, %s, %s", sName, team, class); if (iBot != 0) { TF2_ChangeClientTeam(iBot, team); TF2_SetPlayerClass(iBot, class); TF2_RespawnPlayer(iBot); return true; }
return false; }
stock void CapitalizeFirstLetter(char[] sBuffer) { sBuffer[0] = CharToUpper(sBuffer[0]); }
int GetRandomUInt(int min, int max) { return RoundToFloor(GetURandomFloat() * (max - min + 1)) + min; }
|
Hello,
Thank you for the reply! That did the trick, thanks! Yeah, the bots are intended to not be able to move. Out of curiosity, what made the issue occur with the GetRandomInt() function? Is it something to do with caching or along those lines?
Thank you,
Grant
Last edited by ThatKidWhoGames; 01-17-2021 at 13:50.
|
|