players.usercmd and PlayerRunCommand

General discussion for off-topic subjects.
Speed0x
Member
Posts: 84
Joined: Sun Feb 05, 2017 4:55 pm

players.usercmd and PlayerRunCommand

Postby Speed0x » Mon May 25, 2020 2:42 pm

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

Re: players.usercmd and PlayerRunCommand

Postby L'In20Cible » Mon May 25, 2020 6:07 pm

Could you please elaborate?
Speed0x
Member
Posts: 84
Joined: Sun Feb 05, 2017 4:55 pm

Re: players.usercmd and PlayerRunCommand

Postby Speed0x » Mon May 25, 2020 6:36 pm

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

Re: players.usercmd and PlayerRunCommand

Postby L'In20Cible » Mon May 25, 2020 7:46 pm

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.
Speed0x
Member
Posts: 84
Joined: Sun Feb 05, 2017 4:55 pm

Re: players.usercmd and PlayerRunCommand

Postby Speed0x » Mon May 25, 2020 7:50 pm

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
Speed0x
Member
Posts: 84
Joined: Sun Feb 05, 2017 4:55 pm

Re: players.usercmd and PlayerRunCommand

Postby Speed0x » Mon May 25, 2020 8:02 pm

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

Re: players.usercmd and PlayerRunCommand

Postby L'In20Cible » Tue May 26, 2020 12:39 am

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.

Return to “Whatever”

Who is online

Users browsing this forum: No registered users and 16 guests