Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Please post any questions about developing your plugin here. Please use the search function before posting!
inf
Junior Member
Posts: 20
Joined: Mon Aug 07, 2017 2:46 am

Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby inf » Tue Dec 05, 2017 8:25 am

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

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby L'In20Cible » Tue Dec 05, 2017 11:07 am

Syntax: Select all

player.angles = Vector(my_val_x, my_val_y, 0.0)
Doesn't works?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby iPlayer » Tue Dec 05, 2017 8:16 pm

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

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby iPlayer » Tue Dec 05, 2017 8:42 pm

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.
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
inf
Junior Member
Posts: 20
Joined: Mon Aug 07, 2017 2:46 am

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby inf » Tue Dec 05, 2017 9:10 pm

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

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby L'In20Cible » Wed Dec 06, 2017 2:12 am

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)
inf
Junior Member
Posts: 20
Joined: Mon Aug 07, 2017 2:46 am

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby inf » Wed Dec 06, 2017 4:16 am

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

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby L'In20Cible » Wed Dec 06, 2017 4:51 am

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.
inf
Junior Member
Posts: 20
Joined: Mon Aug 07, 2017 2:46 am

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby inf » Wed Dec 06, 2017 4:59 am

Yes, still crashes :(
User avatar
L'In20Cible
Project Leader
Posts: 1060
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby L'In20Cible » Wed Dec 06, 2017 5:07 am

Did you try player.teleport(angles=your_angles) or simply player.set_view_angles(your_angles)?
inf
Junior Member
Posts: 20
Joined: Mon Aug 07, 2017 2:46 am

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby inf » Wed Dec 06, 2017 5:17 am

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

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby L'In20Cible » Wed Dec 06, 2017 5:37 am

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
User avatar
Ayuto
Project Leader
Posts: 1847
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby Ayuto » Wed Dec 06, 2017 5:42 pm

The serverplugin_empty example contains an example on how to controll bots:
https://github.com/alliedmodders/hl2sdk ... in_bot.cpp

Basically, you just retrieve the bot controller and use it to set the bot's movement in an OnTick listener.
inf
Junior Member
Posts: 20
Joined: Mon Aug 07, 2017 2:46 am

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby inf » Wed Dec 06, 2017 6:32 pm

Ayuto wrote:The serverplugin_empty example contains an example on how to controll bots:
https://github.com/alliedmodders/hl2sdk ... in_bot.cpp

Basically, you just retrieve the bot controller and use it to set the bot's movement in an OnTick listener.



I have tried this, encountered a server crash when setting the bot's movement with the controller. In20cible said something about outdated structures?
User avatar
Ayuto
Project Leader
Posts: 1847
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby Ayuto » Wed Dec 06, 2017 6:51 pm

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.
inf
Junior Member
Posts: 20
Joined: Mon Aug 07, 2017 2:46 am

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby inf » Wed Dec 06, 2017 9:56 pm

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.
User avatar
Ayuto
Project Leader
Posts: 1847
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Can't set user_cmd.view_angles in a OnPlayerRunCommand listener

Postby Ayuto » Sat Dec 09, 2017 4:58 pm

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/ReplayBot

It'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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests