Jump to content
Sign in to follow this  
roguetrooper

Check if head under water?

Recommended Posts

Is there a way to check whether a unit's / the player's head is under water? It must work with ponds, not necessarily with the ocean. Unfortunately "surfaceiswater" does not work with ponds.

Since you can't fire when you're diving, there must be a way to check this...

Edited by RogueTrooper

Share this post


Link to post
Share on other sites

In the Armory scripts under Tryout\secchals there is a script named swimDist.sqf

Part of that script is to check if the player is swimming. This is done with this section:

private ["_isSwimmingFunction"];
_isSwimmingFunction = 
{
private ["_pos", "_isSwimming"];
_pos = position _veh;
_isSwimming = false;

if ((surfaceIsWater _pos) && ((_pos select 2) < 0.5) && (!_isChar || ((animationState player) in ["aswmpercmwlksnonwnondf", "aswmpercmsprsnonwnondf", "aswmpercmrunsnonwnondf", "aswmpercmstpsnonwnondnon", "aswmpercmrunsnonwnondf_aswmpercmstpsnonwnondnon", "aswmpercmstpsnonwnondnon_aswmpercmrunsnonwnondf", "aswmpercmstpdnon", "aswmpercmstpdnon_aswmpercmstpdf", "aswmpercmstpdf_aswmpercmstpdnon", "aswmpercmstpsnonwnondf"]))) then 
{
	_isSwimming = true;
};

_isSwimming
};

Maybe this can help you out, or be changed to suit your needs...

Share this post


Link to post
Share on other sites

Thank you for your efforts. But this does not seem to be able to help. Maybe the word 'diving' in my initial post was not a good choice. I want to check for situations on land in knee/hip deep water, where you are able to stand when you are upright, but submerge completely, when you kneel or crouch.

Share this post


Link to post
Share on other sites

I have not done alot of ops in these ponds, but does your animation state change when you "submerge" as you wish?

I was thinking once submerged, the character started swimming, but again, I have not tested in ponds.

Maybe use of selectionPosition?

_submergedHead = player selectionposition "head_hit";

but I don't think you could then get the position ASL of _submergedHead, and use this to check, as these ponds may be located on land above sea level?

Do you hold your breath while in this position, or is your mouth/nose still above water?

Sorry to be beating this to death Rogue Trooper, but does checking for these ponds work with

_imInaPond = nearestLocations [getPos player, ["NameMarine"], 15]; // or change distance for check

If so, you could verify the player was in one first then do your other checks...

Edited by panther42

Share this post


Link to post
Share on other sites

Actually all this here is about the swampy area in Staszow, IronFront 44, where hundreds (?) of little ponds are. I'm just asking here because I think the player/mapper base of OA is bigger than of IF44.

I don't think that ASL and the usual things that have to do with "water" work. Further, these ponds (as every pond in Chernarus and Takistan) are treated like land. The unit's animation doesn't change and nothing else happens (no drowning although the unit can't breath from a logical/physical point of view). Since you can't fire or run (depends on the water depth), the engine must be able to check whether a unit is in a pond (i.e. "non-ocean"-water).

I basically want a script that makes a player drown, when his head is under water constantly for x seconds. There wouldn't be a problem if I was able to figure out a head-under-(pond)water-check...

Share this post


Link to post
Share on other sites
Since you can't fire when you're diving, there must be a way to check this...

There is no guarantee that there will be an available scripting command... it could be hardcoded in the engine...

:dummy:

Share this post


Link to post
Share on other sites

what you can do is attachTo an invisible object (empty helipad ? HeliHempty) to the soldier's head (selection "hlava" : see ArmA: Selection Translations for more example) then detect if this object is underwater, all this independant of the animation state.

_h = "HeliHempty" createVehicle getPosATL player;
_h attachTo [player, [0,0,0], "hlava"];

waitUntil { (getPos _h select 2) < 0; };
hint "glub glub";

I can't give it a try since I'm @ work but give me a feedback if this works :)

Share this post


Link to post
Share on other sites

Thanks for the hint.

But it does not work this way. The attached object does not alter its height, when the unit kneels or crouches.

Further,

 object attachTo [player, [0,0,0], "hlava"]; 

does not work. I have used a red dummy sphere (which might the globally hideobject'ed later, because I think a helipad is always on the ground, no matter how high it is setpos'ed or attached) to have a visible object for testing purposes, but it does not attach to the head. Nevertheless [0,0,1.75] could be used (don't know right now whether the second or third coord is the hight in attachto).

Checking for the animation/move stuff might be successful:

_moves  = configfile >> gettext ( configfile >> "CfgVehicles" >> typeof player >> "moves" );
_state  = (_moves >> "Actions" >> gettext ( _moves >> "States" >> animationstate player >> "actions" ) >> "upDegree");
_number = getnumber _state;
if ( ((position _unit select 2) < 0) and (_number in [1,2,...]) ) then { }; ----> loop or repeatable trigger or whatever

Don't know the "_numbers" right now, but "_number" are the returned numbers for: [kneeling unarmed, crouching unarmed,kneeling with pistol, kneeling with rifle, kneeling with bazooka, crouching with pistol, crouching with rifle].....

I'm too lazy at the moment of posting this to dig further ;)

Edited by RogueTrooper

Share this post


Link to post
Share on other sites
Further,
 object attachTo [player, [0,0,0], "hlava"]; 

does not work.

it might be

 object attachTo [player, [0,0,0], "[b]head[/b]"]; 

attachTo "Lhand" works, I don't see why head wouldn't work, unless attachTo doesn't process upper-body animation.

I check that at home and let you know.

Share this post


Link to post
Share on other sites

They both work but neither seem very reliable. You have to watch the offset as it can be several meters above or below the head when attached at [0,0,0]

Head works better than hlava but I found neck gives the best result as it's not moving all the time.

Using the small redlight attached

object attachTo [player, [0,0,.2], "neck"];

object hideobject true;

As for it working in ponds I have no idea if it will work.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

did test with

enableSaving [false, false];
_obj = "Sign_sphere25cm_EP1" createVehicle getPos player;
_obj attachTo [player, [0, 0, 0.1], "neck"];
waitUntil {
sleep .1 ;
_alt = getPos _obj select 2 ;
_toHint = format["POS: %1\nATL: %2\nASL: %3", _alt, getPosATL _obj select 2, getPosASL _obj select 2] ;
if (_alt < 0) then { hint _toHint; } else { hintSilent _toHint; };
FALSE ;
};

it works for sea, but as soon as you put your head under pond water getPos gives same result as getPosATL (above pond water, data is different)

enableSaving [false, false];
_obj = "Sign_sphere25cm_EP1" createVehicle getPos player;
_obj attachTo [player, [0, 0, 0.1], "neck"];

_obj2 = "Sign_sphere25cm_EP1" createVehicle getPos player;

waitUntil {
sleep .1 ;

_obj2 setPos[ getPos _obj select 0, getPos _obj select 1, getPos _obj select 2];

_alt = getPos _obj select 2 ;
_toHint = format[
	"POS: %1\nATL: %2\nASL: %3\n\naltDiff: %4\nwater: %5",
	_alt,
	getPosATL _obj select 2,
	getPosASL _obj select 2,
	abs( (getPosASL _obj2 select 2) - (getPosASL _obj select 2)),
	surfaceIsWater getPos _obj
] ;
if (_alt < 0) then { hint _toHint; } else { hintSilent _toHint; };
FALSE ;
};

helps to detail the problem, but at the moment I didn't find any way to detect head under pond water. on its track, looking for it!

Share this post


Link to post
Share on other sites

There appears to be a serious plroblem checking the height when in a pound.

In deep water getposASL it's fine and returns a constant number eg 77.xx but as soon as the unit can stand it drops to 75.xx when in fact it should rise and if you walk up a hill it does.

I was trying to do a comparison between neck and object placed on the water and check them both with getposASL.

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  

×