View Full Version : Could bots work?

24-01-2016, 01:32 AM
I'm trying to figure out if it's feasible to make bots in Angelscript. I didn't get very far because I can't spawn a fake player.

In EntityManager.as there is a function called "AddFakeClient" that seems to do what I want. It looks like it was never finished though, since it fails before Spawn() is called. This adds a new client in the player list, but no player is spawned.

I tried creating a player using g_EntityFuncs.Create("player", origin, angles, false, pEdict), which seems to have worked, but the game quits immediately with these errors in the console:

Host_Error: WriteDest_Parm: not a client
Netchan_Clear() : reliable length not 0, reliable_sequence: 22, incoming_reliable_acknowledged: 1
Netchan_Clear() : reliable length not 0, reliable_sequence: 15, incoming_reliable_acknowledged: 1
ERROR: Angelscript: Active module was not set to null!

So I downloaded the source code for an old version of RCBot (http://rcbot.bots-united.com/downloads/rcbot_svencoop_45_src.zip) to see how metamod coders created bots, and it looks like they use some functions which are not available in AS:

pEdict = (*g_engfuncs.pfnCreateFakeClient)( gBotGlobals.m_Bots[iBotIndex].m_Profile.m_szBotName );

if (FNullEnt( pEdict ))
BotMessage( pEntity, 0, "Maximum Players Reached, Can't Create Another Bot!");

char ptr[128]; // allocate space for message from ClientConnect
char *sInfoBuffer; // Bots infobuffer
int index; // bots edict index

pEdict->v.frags = 0; // reset his frag count

CALL_GAME_ENTITY(PLID,"player",VARS(pEdict)); // Olo
// create the player entity by calling MOD's player function
// (from LINK_ENTITY_TO_CLASS for player object)

player( VARS(pEdict) );

index = ENTINDEX( pEdict );

sInfoBuffer = (*g_engfuncs.pfnGetInfoKeyBuffer)( pEdict );

// pointer to new bot
pBot = &gBotGlobals.m_Bots[iBotIndex];


(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "rate", "3500");
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "cl_updaterate", "20");
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "cl_lw", "1");
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "cl_lc", "1");
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "cl_dlmax", "128");

if ( !gBotGlobals.IsMod(MOD_TS) )
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "_vgui_menus", "0");
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "_vgui_menus", "1");

(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "_ah", "0");
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "dm", "0");
(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "tracker", "0");
//(*g_engfuncs.pfnSetClientKeyValue)(index, sInfoBuffer, "name", gBotGlobals.m_Bots[iBotIndex].m_Profile.m_szBotName);


// update joining clients because metamod wont call engine client connect?
MDLL_ClientConnect( pEdict, szName, "", ptr );
ClientConnect( pEdict, szName, "", ptr );

MDLL_ClientPutInServer( pEdict );
ClientPutInServer( pEdict );

ClientConnect( pEdict, szName, "", ptr );
// Pieter van Dijk - use instead of DispatchSpawn() - Hip Hip Hurray!
ClientPutInServer( pEdict );

The ones that seem interesting are "ClientConnect", "ClientPutInServer", and whatever "pfnSetClientKeyValue" could be (I assume there are some client-related functions that aren't exposed).

Is is possible to add fake players in 5.0?

25-01-2016, 05:22 AM
Sorry for the late reply:
The AddFakeClient command is a bare bones usage of the engine function used to create fake clients.
Creating players directly is not supported and should be avoided.

Support for bots can be added directly if that's needed. Then all you'd have to do is something like g_PlayerFuncs.CreateBot. We'll look into this when there's time.

25-01-2016, 01:46 PM
I don't know yet if players can be controlled with AS (i.e. press their fire button for them), but that would a ton of fun to play with. Thanks for the reply.

01-02-2016, 09:50 AM
I've removed CEngineFuncs::CreateFakeClient and added CPlayerFuncs::CreateBot and BotDisconnect. These methods, combined with CEngineFuncs::RunPlayerMove, are all you need to create bots. I made a simple implementation that makes bots move in random directions, randomly fire their weapons, and has their model colors change randomly.

The next update will have all of this.

01-02-2016, 01:57 PM
Seriously!? I can't wait to try this out. Thank you!