Page 1 of 1

players.usercmd and PlayerRunCommand

Posted: Mon May 25, 2020 2:42 pm
by Speed0x
if i assign "players.usercmd" to a variable, who does that usercmd refer to exactly ? noone? is it "empty"? do i have to bind it to a player to work? in PlayerRunCommand this happens automatically, correct?

thanks anybody for clarification

Re: players.usercmd and PlayerRunCommand

Posted: Mon May 25, 2020 6:07 pm
by L'In20Cible
Could you please elaborate?

Re: players.usercmd and PlayerRunCommand

Posted: Mon May 25, 2020 6:36 pm
by Speed0x
ok, i am in csgo.

i do create_fake_client

Code: Select all

   newfakeclient = engines.server.engine_server.create_fake_client(name)
   bot_ptr = entities.helpers.pointer_from_edict(newfakeclient)
   bot = memory.make_object(players.entity.Player, bot_ptr)

i spawn the "Player"

Code: Select all

bot.spawn()

then i listen in on

Code: Select all

   @OnPlayerRunCommand
   def PlayerRunCommand(player, ucmd):
      if player.is_bot():
         ucmd.buttons = random.choice([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,PlayerButtons.JUMP])

the issue:

1) this command "seems to work" with playerbuttons.JUMP. but if i replace "JUMP with PlayerButtons.ATTACK, it will not always works.
2) moreover, if i reload the script the ucmd doesn't work at all. ( so it basically only works for the first scriptload after i started the server and only after an unknown amount of time ).

ive found that
https://github.com/Source-Python-Dev-Te ... n.cpp#L360
(on scriptload)

is when the runcommandlistener gets assigned to the player
https://github.com/Source-Python-Dev-Te ... s.cpp#L194

but i don't know where that usercmd
https://github.com/Source-Python-Dev-Te ... s.cpp#L190

comes from, so i am wondering , if i have to initiate/assign a usercmd from sourcepython for the newly create fake_client object.

but idk if the issue is with the usercmd at all.
in the end all i'd want is for @OnPlayerRunCommand to work with create_fake_client correctly.

Re: players.usercmd and PlayerRunCommand

Posted: Mon May 25, 2020 7:46 pm
by L'In20Cible
Fake clients created by engine_server.create_fake_client are empty shells. They are CCSPlayer instances rather than CCSBot meaning they won't do anything unless they are instructed to do so. If your goal is to force a fake client to perform actions, you need to use a controller. For example:

Syntax: Select all

from players.bots import BotCmd
from players.bots import bot_manager
from players.constants import PlayerButtons

edict = bot_manager.create_bot('Foo')

bcmd = BotCmd()
bcmd.buttons |= PlayerButtons.ATTACK

controller = bot_manager.get_bot_controller(edict)
controller.run_player_move(bcmd)


Now that bot should attack until instructed to do otherwise. Changing the buttons into a OnPlayerRunCommand callback is most likely too late to override some actions. Besides, they are more than likely broken and incomplete and you may have more success by using real bots and override their think methods.

Re: players.usercmd and PlayerRunCommand

Posted: Mon May 25, 2020 7:50 pm
by Speed0x
i am pretty sure i have tried that too. ayuto had a replay bot that used a controller with botcmd. but when i tried using the bcmd and controller nothing happened. i will try that route again and report back. thank you for now

Re: players.usercmd and PlayerRunCommand

Posted: Mon May 25, 2020 8:02 pm
by Speed0x
oh i see. i found my mistake.
i have to call

Code: Select all

controller.run_player_move(bcmd)
for every tick i want to play the altered bcmd in. i previously only changed the .buttons per tick and then tried to access it via onplayerruncommand but that dropped me into a recursive loop crash.

thank you. i think it works now this way.

Re: players.usercmd and PlayerRunCommand

Posted: Tue May 26, 2020 12:39 am
by L'In20Cible
A good example would be the plugin samples shipped with the sdk: ../utils/serverplugin_sample/serverplugin_bot.cpp. Tho most likely outdated and broken on recent games.