A way to "get" if the player is crouched

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: Developers

A way to "get" if the player is crouched

Postby Enjay » Sun Aug 05, 2012 2:02 pm

It would be useful if there was a way for ACS to find out if the player was crouched or not.

The player tends to be crouched for longer periods of time than say, when he is jumping, and so there are a number of things I can think of where it would be useful for ACS to be able to find out if the player is crouched.

Unfortunately (as far as this is concerned) there are two ways for crouching to be controlled "crouch" (ie crouch-while-button-is-pressed) or crouch-toggle. So a GetPlayerInput can't be used because if the player is using crouch-toggle (as I tend to do), he won't be holding the button down for the entire time that he is crouched.

The most recent example I have where this would be useful is in a situation where ACS is being used as the "engine" behind a flashlight mod. The scripts concerned would need to know if the player was crouched or not before it could spawn the flashlight effect at the correct height. If the player is using crouch (rather than crouch-toggle) this can work because the button press can be detected. If he is using crouch-toggle, however, it doesn't work because ACS has no way of knowing that the player is crouched.

This is not the only example. I've had ideas about making the player harder to spot when crouched and other things too but not being able to reliably get the crouching information via ACS has scuppered the idea.

Any chance something could be done?
User avatar
Enjay
The Force is strong with this one.
 
Joined: 15 Jul 2003
Location: Scotland

Re: A way to "get" if the player is crouched

Postby Jimmy » Sun Aug 05, 2012 2:07 pm

I think GetActorViewHeight will fit your needs in this situation. :)
User avatar
Jimmy
º~u~º
 
Joined: 10 Apr 2006
Location: Perth, WA

Re: A way to "get" if the player is crouched

Postby Enjay » Sun Aug 05, 2012 2:40 pm

Oooh, I don't have time to check that right now but, assuming it changes when the player crouches as the Wiki says, it could well be exactly what I needed. Thanks.
User avatar
Enjay
The Force is strong with this one.
 
Joined: 15 Jul 2003
Location: Scotland

Re: A way to "get" if the player is crouched

Postby Nash » Sun Aug 05, 2012 3:47 pm

Code: Select allExpand view
// player view height
#libdefine PLAYER_VIEWHEIGHT 60

// check for crouching
function int CheckPlayerCrouching(void)
{
    if(GetActorViewHeight(0) <= PLAYER_VIEWHEIGHT / 2 << 16)
        GiveInventory("PlayerFlag_IsCrouching", 1);
    else
        TakeInventory
("PlayerFlag_IsCrouching", 1);
    
    return CheckInventory
("PlayerFlag_IsCrouching");
}
 


This is what I used in my project, although it's only tested against the specific heights for my player class actor... YMMV.
User avatar
Nash
http://twitter.com/ISurvivorGame
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: A way to "get" if the player is crouched

Postby Enjay » Sun Aug 05, 2012 6:25 pm

Thanks for the input and, yes, GetActorViewHeight(0) does do exactly what was required and I'm sure it could be put to use in the other situations that I was thinking about too.

I guess this is either a [Not Needed] or an [Already In] then. :)
User avatar
Enjay
The Force is strong with this one.
 
Joined: 15 Jul 2003
Location: Scotland

Re: A way to "get" if the player is crouched

Postby FDARI » Mon Aug 06, 2012 4:27 am

Well... If you want it to work with other mods (introducing player classes with different features) you will require a more dynamic feature than #define/#libdefine.

Actor property: APROP_HEIGHT
Actor property: APROP_VIEWHEIGHT

Player property: PROP_MODHEIGHT
Player property: PROP_MODVIEWHEIGHT

if (GetActorProperty(0, APROP_HEIGHT) > ...

Does SetPlayerProperty not have a "get" counterpart? I suppose then, one could add APROP_... constants for modified heights and use GetActorProperty(). After all, even if most actors will not change their dimensions (hell) or point of view (ghastly), you can still write code that checks for crouching. A monster will just not be crouching.

Which reminds me to wonder exactly why the crouch-resize is manageable for players and not for monsters. Hm. Different discussion, but still interesting.
User avatar
FDARI
Bronies eunt domus
 
Joined: 03 Nov 2009

Re: A way to "get" if the player is crouched

Postby Enjay » Mon Aug 06, 2012 4:44 am

One of the reasons given for not adding crouching monsters was the difficulty of ensuring that uncrouching monsters had room to uncrouch.
User avatar
Enjay
The Force is strong with this one.
 
Joined: 15 Jul 2003
Location: Scotland

Re: A way to "get" if the player is crouched

Postby FDARI » Mon Aug 06, 2012 5:20 am

Players uncrouch as far as they are able, and keep uncrouching as the environment permits, until they reach full height. At least, that's what it seems like. If you give them a crouchtoggle mechanism (rather than an instant crouch/uncrouch, which does not exist in zdoom) that should be manageable. I want to investigate this properly. (In code, that means.)
User avatar
FDARI
Bronies eunt domus
 
Joined: 03 Nov 2009


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest