Page 1 of 1

CVEngineServer::CreateFakeClient

Posted: Mon Nov 07, 2016 11:54 pm
by quartata
Hello again,

I'm trying to use the memory module to call CVEngineServer::CreateFakeClient (since currently I am using the bot console command to spawn bots which is ugly since console commands don't block and I don't get an index or anything back). I have the vtable index (54), but I can't find anywhere in SourcePython where the global IVEngineServer instance is exposed. How would I do this?

Re: CVEngineServer::CreateFakeClient

Posted: Tue Nov 08, 2016 12:38 am
by L'In20Cible
https://github.com/Source-Python-Dev-Te ... p.cpp#L314

Syntax: Select all

from engines.server import engine_server

fake_client = engine_server.create_fake_client('Bob')

Re: CVEngineServer::CreateFakeClient

Posted: Tue Nov 08, 2016 1:50 am
by quartata
Well shoot, I didn't realize it was already exported. Awkward...

Re: CVEngineServer::CreateFakeClient

Posted: Tue Nov 08, 2016 9:37 am
by iPlayer
I personally used this code (simplified)

Syntax: Select all

from engines.server import execute_server_command
from listeners import OnClientActive
from players.entity import Player


_requested_bots = []


@OnClientActive
def listener_on_client_active(index):
player = Player(index)

if player.steamid != "BOT":
return

callback = _requested_bots.pop(0)

if callback is not None:
callback(player)


def spawn_bot(callback):
_requested_bots.append(callback)
execute_server_command("bot_add_t")


def bot_request_callback(player):
# Do something with the bot
player.name = "Bot #{}".format(player.userid)


request_bot(bot_request_callback)


Because if I'm not mistaken, CreateFakeClient spawns a bot without bot behavior. It just joins spectators.

Edit: execute_server_command actually can be considered blocking, unlike queue_server_command which adds the command to command queue. But the above code will work with both of them.

Re: CVEngineServer::CreateFakeClient

Posted: Tue Nov 08, 2016 5:44 pm
by quartata
iPlayer wrote:Because if I'm not mistaken, CreateFakeClient spawns a bot without bot behavior.


Yes; this is what I want.

Good to know about the difference between execute and queue though, thanks.

Re: CVEngineServer::CreateFakeClient

Posted: Wed Nov 09, 2016 3:45 pm
by quartata
So something seems not to be working. I have the following very simple snippet in my code:

Syntax: Select all

self.player = Player(index_from_edict(engine_server.create_fake_client(Bot.names.pop())))

self.player.set_team(2 if team == -1 else 3)
self.player.spawn()


The bot joins the appropriate team but it never spawns, even if I do mp_forcerespawnplayers. (This is TF2 on Linux)

Re: CVEngineServer::CreateFakeClient

Posted: Wed Nov 09, 2016 3:47 pm
by iPlayer
What about selecting class? For TF2 it may occur essential for them to be somebody.

Try this:

Syntax: Select all

self.player.set_property_int('m_iClass', 1)    # Spawn as Scout

Re: CVEngineServer::CreateFakeClient

Posted: Thu Nov 10, 2016 1:12 am
by quartata
iPlayer wrote:What about selecting class? For TF2 it may occur essential for them to be somebody.

Try this:

Syntax: Select all

self.player.set_property_int('m_iClass', 1)    # Spawn as Scout



I did self.player.set_property_uchar("m_PlayerClass.m_iClass", 1), no change.

Re: CVEngineServer::CreateFakeClient

Posted: Thu Nov 10, 2016 2:05 am
by L'In20Cible
You cannot spawn fake clients as they have no AI bound to them.

Re: CVEngineServer::CreateFakeClient

Posted: Thu Nov 10, 2016 1:37 pm
by iPlayer
L'In20Cible wrote:You cannot spawn fake clients as they have no AI bound to them.

How do third-party bots work though? Like Botrix. If I'm not mistaken, they spawn fake clients and then control them.

Re: CVEngineServer::CreateFakeClient

Posted: Thu Nov 10, 2016 5:35 pm
by Ayuto
They probably implement the AI. IRC, the official SDK includes a project called serverpluginempty or something like that, which also implements a basic bot.

Re: CVEngineServer::CreateFakeClient

Posted: Thu Nov 10, 2016 6:33 pm
by quartata
This was the code I was looking at for the default bot implementation in the SDK: https://github.com/ValveSoftware/source ... t_temp.cpp

As far as I can see, there's nothing special going on (Bot_RunAll is called from GameFrame in a plugin). What are they doing different?

Re: CVEngineServer::CreateFakeClient

Posted: Thu Nov 10, 2016 6:35 pm
by quartata
Wait, now I'm confused.... would this even work with ClientPutInServer commented out??