Jump to content
madrussian

Detect when weapon cursor displayed (exactly)

Recommended Posts

Hi, I'm using cursorTarget to detect when player is aiming at an enemy AI, and having that enemy AI react.

 

Working well so far, currently AI is reacting any time player points cursorTarget at him.  However, turns out I only want reaction when player is pointing weapon at the AI.

 

I checked out weaponLowered command, which is useful but not right for this purpose.  Turns out, weaponLowered is really checking the state player enters when pressing the "Toggle Raise Weapon" key.

 

What we need is something more like "weapon cursor displayed".  So for instance, when player is stopped, weapon cursor is normally displayed.  Then as soon as player runs or sprints, player weapon is lowered slightly (while moving), and weapon cursor disappears.  Then as player presses the "Combat Pace Toggle" button, even while moving (non-sprint), player raises or lowers gun slightly and the weapon cursor appears and disappears.

 

Ok, the related questions:

 

How to detect when "weapon cursor displayed" (or not displayed)?

How to detect "Combat Pace Toggle" state?

 

^ If it turns out either or both of these are impossible, what's the best workaround?  Thanks!

 

Edit: Also, curious if there is an equivalent to cursorTarget, but for where player's weapon is pointing?

 

Share this post


Link to post
Share on other sites

Try with cursorObject instead for cursorTarget.  (keep in mind that the primary weapon of an alive unit is an object different from the unit itself. That can be important depending on what you want to script with that).

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi Madrussian,

Those are all defined on each animation in cfgMovesMaleSdr:

getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "weaponLowered")
getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "showWeaponAim")

There are some discrepancies though, e.g. sprint returns weaponLowered = 0 when visually the weapon is lowered, and showWeaponAim returns = 1 when running with rifle raised but there's no cursor.

 

6 hours ago, madrussian said:

How to detect when "weapon cursor displayed" (or not displayed)?

disableWeapons seems to be the most reliable for your case:

getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "disableWeapons")

 

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks guys, really good insights.

 

5 hours ago, pierremgi said:

Try with cursorObject instead for cursorTarget.

 

I just took a closer look at both of these (in 3rd person using free-look & looking around):

 

Standing still, cursorTarget seems to get the object your weapon is pointed at, whereas cursorObject seems to get the object your player camera is looking at.  Also turns out cursorObject is very precise, in terms of the cursor ray hitting it's target.  Miss by a smidge and it returns objNull (or the next obj behind).  On the other hand cursorTarget uses a "softer" more forgiving detection.  Then like you said cursorObject has ability to get unit's weapon, whereas cursorTarget does not.  Both are no doubt extremely useful, depending on what you're looking for.

 

Seems like for this purpose... I probably want cursorTarget.

 

48 minutes ago, RCA3 said:

disableWeapons seems to be the most reliable for your case:


getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "disableWeapons")

 

 

Wow, totally nailed it!  Just tested out & seems to work perfectly in all my relevant cases.  I was off on a big-time tangent, lol measuring the angle between the camera dir and weapon dir, which was turning out to be very expensive CPU-wise (using 5 vector commands plus aTan2 every time).  This is waaay better!

 

  • Like 2

Share this post


Link to post
Share on other sites

Why not just the following for testing if weapon raised?

(animationState player) find "sras" >= 0

 

Share this post


Link to post
Share on other sites
11 hours ago, johnnyboy said:

Why not just the following for testing if weapon raised?


(animationState player) find "sras" >= 0

 

 

That would likely work and I did consider this.  I always dislike parsing animationState though, as it seems like whatever I do misses a bunch of important cases (because there are sooo many of those animations).  Like for my current purpose, I don't think find on "sras" will catch while player is healing, etc.  Checking disableWeapon in the config, on the other hand (at least for this), seems to catch every single relevant case I can think of.

 

Also, checking disableWeapon is likely way less expensive CPU-wise, and I've got to call this on a short loop that's always running.  Seems like find on a long animationState string has to do a lot of checking (at each position in whole string).

 

Anyhow, yes good idea. 😉

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×