Page 1 of 1
Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Tue Dec 05, 2017 8:25 am
by inf
I'm having trouble setting user_cmd.view_angles in an OnPlayerRunCommand listener. I've tried both
Syntax: Select all
@OnPlayerRunCommand
def run_cmd(player, user_cmd):
user_cmd.view_angles.x = my_val_x
user_cmd.view_angles.y = my_val_y
and
Syntax: Select all
@OnPlayerRunCommand
def run_cmd(player, user_cmd):
user_cmd.view_angles = QAngle(my_val_x, my_val_y, 0.0)
In both cases, when tested in game the player's view angle seems to snap to <0.0, 0.0, 0.0>. I am trying to force the view angle of bots btw.
CS:GO, Linux
Thanks
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Tue Dec 05, 2017 11:07 am
by L'In20Cible
Syntax: Select all
player.angles = Vector(my_val_x, my_val_y, 0.0)
Doesn't works?
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Tue Dec 05, 2017 8:16 pm
by iPlayer
There's also other stuff in UserCmd, like mouse_dx, mouse_dy (something like that). Try replicating those properties too, because they should probably take part in determining player's view.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Tue Dec 05, 2017 8:42 pm
by iPlayer
23:35 - inf: mousedx and mousedy dont have any effect on bots either, strange
I think this might be a bug in
OnPlayerRunCommand listener.
According to Ayuto, In CS:GO UserCmd stucture is different from BotCmd. But the listener never makes BotCmd objects, it always makes UserCmd objects, despite it fires for bots, too.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Tue Dec 05, 2017 9:10 pm
by inf
L'In20Cible wrote:Syntax: Select all
player.angles = Vector(my_val_x, my_val_y, 0.0)
Doesn't works?
Does not seem to work... Working through this issue with iPlayer and I've been told about the differences between user_cmd and bot_cmd.
I'm wondering about players.bots.BotController, how would I obtain an instance of this?
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 2:12 am
by L'In20Cible
The difference between UserCmd and BotCmd should not matter here because they are used for different functions. OnPlayerRunCommand is correct to returns a UserCmd even for bots because this is what the original hooked method is called with. You could try any of the following, I guess:
Syntax: Select all
from players.bots import bot_manager
controller = bot_manager.get_bot_controller(player.edict)
controller.set_abs_anges(angles)
controller.local_angles = angles
bot_cmd = BotCmd()
bot_cmd.view_angles = angles
controller.run_player_move(bot_cmd)
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 4:16 am
by inf
L'In20Cible wrote:The difference between UserCmd and BotCmd should not matter here because they are used for different functions. OnPlayerRunCommand is correct to returns a UserCmd even for bots because this is what the original hooked method is called with. You could try any of the following, I guess:
Syntax: Select all
from players.bots import bot_manager
controller = bot_manager.get_bot_controller(player.edict)
controller.set_abs_anges(angles)
controller.local_angles = angles
bot_cmd = BotCmd()
bot_cmd.view_angles = angles
controller.run_player_move(bot_cmd)
This crashes the server right when run_player_move is called. If I comment it out, set_abs_angles and setting local angles on the bot controller also don't seem to work.
I know I said before that the view angles of the bot seem to snap to 0,0 in game, but I'm now noticing that the angles move to where the bot's AI wants it to look. Strange.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 4:51 am
by L'In20Cible
It probably crashes because the BotCmd is not initialized. Does calling bot_cmd.reset() prior to setting the view_angles also crashes? If so, it might be the structures that is outdated for that engine.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 4:59 am
by inf
Yes, still crashes :(
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 5:07 am
by L'In20Cible
Did you try player.teleport(angles=your_angles) or simply player.set_view_angles(your_angles)?
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 5:17 am
by inf
L'In20Cible wrote:Did you try player.teleport(angles=your_angles) or simply player.set_view_angles(your_angles)?
Yes teleporting every frame does work, delayed by one tick to prevent the server from crashing, but the bots movement is quite choppy. In SM implementations of what I'm trying to achieve such as this
https://github.com/peace-maker/botmimic the bot's movements are perfectly smooth, as if the bot is just a regular player. In peace-maker's code he only teleports the bot on certain frames, everything else seems to be done by changing the bot's command.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 5:37 am
by L'In20Cible
Well, you can see in his code that he is also hooking the Teleport method to ensure that only his calls are passed to the engine:
https://github.com/peace-maker/botmimic ... #L701-L709
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 5:42 pm
by Ayuto
The serverplugin_empty example contains an example on how to controll bots:
https://github.com/alliedmodders/hl2sdk ... in_bot.cppBasically, you just retrieve the bot controller and use it to set the bot's movement in an OnTick listener.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 6:32 pm
by inf
I have tried this, encountered a server crash when setting the bot's movement with the controller. In20cible said something about outdated structures?
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 6:51 pm
by Ayuto
There is no outdated structure. It's just that CBotCmd and CUserCmd are different on CS:GO, but that doesn't matter, because you don't need them. You can use the bot controller to set the values.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Wed Dec 06, 2017 9:56 pm
by inf
Ayuto wrote:There is no outdated structure. It's just that CBotCmd and CUserCmd are different on CS:GO, but that doesn't matter, because you don't need them. You can use the bot controller to set the values.
Ok, I see. Either way setting angles with a bot controller didn't work so I'll just force the angles on the player object every frame for now.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Sat Dec 09, 2017 4:58 pm
by Ayuto
I was curious why the controller didn't work for you, so I wrote a little test plugin. However, this was quite funny, so the little test plugin grew up to a little (unfinished) API:
https://github.com/Ayuto/ReplayBotIt's not using a single hook and works perfectly smooth. The key for creating smooth movements is to use bot_manager.create_bot() instead of normal bots. create_bot() returns an "empty" bot. This bot is not controlled by the server and does noting unless you instruct him to do something.
PS: I have only tested this with CS:S.
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Fri May 29, 2020 8:02 am
by Speed0x
when i use the replaybot script and the bot interacts ( kill , weapon etc ) - the server crashes ? (movement seems to work without crash )
is there an outdated structure ? maybe somone can test on their server ? just use ayutos script and then !record !stop !play
here is the last log i could receive before crashing. probably not useful... can i use something else besides
to debug the crash?
![logbotplay.jpg](./download/file.php?id=371&sid=f90291400e0a98a5ae9cf0773c84c2b4)
- logbotplay.jpg (34.08 KiB) Viewed 15600 times
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Sat May 30, 2020 1:11 am
by Speed0x
the simplest way to crash the server with the underlying issue is this:
start any map ( i tested in dust2 deathmatch )
"bot kick"
join game
run
Code: Select all
replay_bot_edict = bot_manager.create_bot("TEST")
switch team and respawn
-- crash happens --
Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener
Posted: Sun Sep 06, 2020 5:05 pm
by Speed0x
i want to update on this post. btw i am testing this in csgo.
when i set spawnflags by "bot.flags = 8192" (or 256 etc) right before spawning the mentioned crash doesn't happen. why is that ? but then the controller doesn't work. aka any changes via the controller in botcmd doesn't change anything while in usercmd and OnPlayerRunCommand some actions can be injected ( but not all ). jumping will work, attack will not work.
what is going on here? i've tried to resolve this issue many times now and can't find a solution