CVEngineServer::CreateFakeClient

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

CVEngineServer::CreateFakeClient

Postby quartata » Mon Nov 07, 2016 11:54 pm

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?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: CVEngineServer::CreateFakeClient

Postby L'In20Cible » Tue Nov 08, 2016 12:38 am

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')
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: CVEngineServer::CreateFakeClient

Postby quartata » Tue Nov 08, 2016 1:50 am

Well shoot, I didn't realize it was already exported. Awkward...
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: CVEngineServer::CreateFakeClient

Postby iPlayer » Tue Nov 08, 2016 9:37 am

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: CVEngineServer::CreateFakeClient

Postby quartata » Tue Nov 08, 2016 5:44 pm

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.
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: CVEngineServer::CreateFakeClient

Postby quartata » Wed Nov 09, 2016 3:45 pm

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)
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: CVEngineServer::CreateFakeClient

Postby iPlayer » Wed Nov 09, 2016 3:47 pm

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
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: CVEngineServer::CreateFakeClient

Postby quartata » Thu Nov 10, 2016 1:12 am

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: CVEngineServer::CreateFakeClient

Postby L'In20Cible » Thu Nov 10, 2016 2:05 am

You cannot spawn fake clients as they have no AI bound to them.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: CVEngineServer::CreateFakeClient

Postby iPlayer » Thu Nov 10, 2016 1:37 pm

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: CVEngineServer::CreateFakeClient

Postby Ayuto » Thu Nov 10, 2016 5:35 pm

They probably implement the AI. IRC, the official SDK includes a project called serverpluginempty or something like that, which also implements a basic bot.
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: CVEngineServer::CreateFakeClient

Postby quartata » Thu Nov 10, 2016 6:33 pm

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?
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: CVEngineServer::CreateFakeClient

Postby quartata » Thu Nov 10, 2016 6:35 pm

Wait, now I'm confused.... would this even work with ClientPutInServer commented out??

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 25 guests