Jump to content
Sign in to follow this  
fatty86

Polling a unit's stance

Recommended Posts

I'm looking for a command that returns a unit's stance/posture. unitPos comes close, but according to biki: "the return value is always "Auto" unless the unit has gotten a setUnitPos command." Since I want to poll a player's stance, this isn't going to help me, I don't think.

The idea is to script some pressure-activated IEDs that blow if a unit is moving in anything besides a crawl.

Thanks!

Share this post


Link to post
Share on other sites

I needed to be able to do this some time ago. Came across this thread:

http://forums.bistudio.com/showthread.php?t=81801

where Big Dawg KS explains how to figure it out. From that I produced the following function:

/*
UP DOWN OR MIDDLE, defaults to UP
*/
getStance = {  
   private ["_result","_unit","_animState","_animStateChars","_animP"];
   _unit = _this;
   _animState = animationState _unit;
   _animStateChars = toArray _animState;
   _animP = toUpper (toString [_animStateChars select 5,_animStateChars select 6,_aniMStateChars select 7]);
   _result = "UP";
   switch (_animP) do {
       case "ERC": {_result = "UP"};
       case "KNL": {_result = "MIDDLE"};
       case "PNE": {_result = "DOWN"};
       default {_result = "UP"};
   };
   _result
};

You may want to change the default or do something else instead. I just needed a stance for a less...... volatile setting :)

Share this post


Link to post
Share on other sites

Can anyone get this to work, I suck at getting functions to work so I can't tell if it's me or the script not working.

Share this post


Link to post
Share on other sites

Since it returns a result, use call.

_return = _unit1 call getStance;
hint format ["unit1 stance is %1",_return];

you will get(_return) either UP, MIDDLE OR DOWN

EDIT: there is also the boundingbox command that can be used, but i remember a long time ago that there was some talk about issues getting lying down units with that.

NOTE: a long time ago.

Edited by Demonized

Share this post


Link to post
Share on other sites

Since there is a high quality anim mod around and some prone animations don't have "pne" in their name anyway, I find that the most reliable way is:

(_unit selectionPosition "launcher" select 2)<1.2 == unit is prone

Share this post


Link to post
Share on other sites

Cheers, I have used the bounding box before but thought this would be more use since it gives you the middle position.

I tried using call and just get a generic error _return #= _unit1 call getStance;

I'll take a look at that one Celery.

Someone else on another forum was asking about it and I remembered I needed it for something as well. I just can't get functions to work, well some do but most don't as people never include their correct usage.

I got the call working now, it seems that I didn't need the compile stuff in the init.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
Since there is a high quality anim mod around and some prone animations don't have "pne" in their name anyway, I find that the most reliable way is:

(_unit selectionPosition "launcher" select 2)<1.2 == unit is prone

Wow, thats a quality tip. Thx :)

Share this post


Link to post
Share on other sites

Having fiddled with animation name strings, unitPos, boundingBox and selectionPosition, I'm using this;

(_unit selectionPosition "Neck" select 2)

It returns the altitude of the players neck. When prone it's 0.3, kneeling it's 1.0 and standing it's 1.5.

The problem with launcher as Celery suggests in #5 is that it's a proxy, so cant be relied on. Also, it changes depending on other things, if the unit is holding a weapon or not, for example. Head is also a proxy so shouldn't be used. Neck, on the other hand, is a selection within the unit model.

I've tried it with BAF, OPFOR TK and USMC units, it will work with all units that have the "Neck" named selection.

Thanks to Celery for help here and F2k Sel and Soul_Assassin over on Armastack

Edited by Tankbuster

Share this post


Link to post
Share on other sites

Cool find with the neck, personally I just looked at the "Man" class config and looked for a reasonably stable and unmoving selection, launcher being the only one I found.

Share this post


Link to post
Share on other sites

I can't take the credit, Soul_Assassin knows much more about models than me and he suggested using "Neck" after I found launcher gave odd results. Interestingly, I found using "head" as the selection name was really wacky. It consistently reported an altitude 2 metres higher than expected.

Just one little proviso though. When the player does that prone sideways roll, the neck momentarily goes as low as 0.1.

Edited by Tankbuster

Share this post


Link to post
Share on other sites

If ("ppne" in [url="http://community.bistudio.com/wiki/animationState"]animationState[/url] player) then {hint "The player is prone!"};
If ("pknl" in animationState player) then {hint "The player is kneeling!"};
If ("perc" in animationState player) then {hint "The player is standing!"};

Havn't tested it, but it might be that

"string" in "string"

only works in VBS2. If so, you'd need to find a different way of checking keywords in a unit's state. Some massive function with toArray and toString comes to mind.

Share this post


Link to post
Share on other sites
If so, you'd need to find a different way of checking keywords in a unit's state. Some massive function with toArray and toString comes to mind.

I've actually written that for an earlier version of my pvp template as a measure to prevent proning, but with custom anim packs and some official animations not following the template, it isn't very compatible.

Share this post


Link to post
Share on other sites

Further blah about my "Neck" method - when the unit concerned gets in a vehicle, you will get unexpected results. It doesn't return absolute neck altitude, but usually about 0.5. Also, when he's climbing ladders, you'll get values approximately the same as when he's standing regardless of how far up the ladder he is.

My neck check test mission has a few empty vehicles to show this.

Here's the data I got from the test mission and the results I use, values approximate and from a USMC soldier

standing 1.5 - 1.6

standing running 1.35 - 1.42

kneel 1.6 - 1.7

prone 0.33

sitting on ground 0.6 - 0.7

looking down will minus about 0.4 and look up will add about 0.3

When he's seated in a vehicle, or in a parachute, looking up or down doesn't change the value. Other odd values include 0.5 for the driver of an M1A1, but -0.1 for commander of the same vehicle.

Edited by Tankbuster

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
Sign in to follow this  

×