Jump to content
Sign in to follow this  
xJordannx

Place hands on head script

Recommended Posts

Hi, I'm new to ArmA 2 coding and I was wondering if anyone could help me make a script so that when you press Tab it puts your hands on your head,

Thanks.

Share this post


Link to post
Share on other sites

http://community.bistudio.com/wiki/ctrlSetEventHandler

(findDisplay 46) displayAddEventHandler ["keyDown", "if ((_this select 1) == ???) then {hint '??? key pressed';}"];

You need to find the DIK code for the TAB key and put it in the above '???' - here:

http://community.bistudio.com/wiki/DIK_KeyCodes

then:

(findDisplay 46) displayAddEventHandler ["keyDown", "if ((_this select 1) == ???) then {player PlayACTION 'amovpercmstpsnonwnondnon_amovpercmstpssurwnondnon'; player enablesimulation false;}"];
(findDisplay 46) displayAddEventHandler ["keyUp", "if ((_this select 1) == ???) then {player enablesimulation true;}"];

Are you sure it's wise to use the TAB key? Might be best to unbind one of the lesser used keys - eg diary and use that instead? You may need an additional condition to check the player isn't in a vehicle when this is used, if using TAB.

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

That won't work, as soon as you use player enablesimulation false; it will freeze, the action won't even start without a delay between the two.

you may have to use player PlayACTION "surrender".

I think "amovpercmstpsnonwnondnon_amovpercmstpssurwnondnon" only work with playmove, switchmove.

Share this post


Link to post
Share on other sites

Yeah wondered about that - disableAI / enableAI "ANIM" doesn't work for players either? I was trying to think of a way to freeze the player in the animation while the key was down - the player PlayACTION "surrender" might do it all.

If that doesn't work another way is to use an addAction with a defined shortcut key.

Share this post


Link to post
Share on other sites

I seem to have something working just place this in a trigger or init.sqf file

hoh=(findDisplay 46) displayAddEventHandler ["keyDown", "if ((_this select 1) == 15) then {;null = [player] execvm 'hands.sqf'}"];

then save this script as "hands.sqf"

// Player hands on head using TAB key (15)
// place this next line in a trigger on init.sqf ,it won't work from a units init.
// hoh=(findDisplay 46) displayAddEventHandler ["keyDown", "if ((_this select 1) == 15) then {;null = [player] execvm 'hands.sqf'}"];
// it may take a second or two to take hands off the head

end_hands = true;

_unit = _this select 0;
_unit playaction "surrender";
(finddisplay 46) displayremoveeventhandler ["KeyDown",hoh]; 
hoh=(findDisplay 46) displayAddEventHandler ["keyDown", "if ((_this select 1) == 15) then {end_hands=false}"];

while {end_hands} do {
         sleep 0.01;
         _unit playaction "surrender";
   };

hoh=(findDisplay 46) displayAddEventHandler ["keyDown", "if ((_this select 1) == 15) then {;null = [player] execvm 'hands.sqf'}"];

If you unit has no weapons it's easier

call with this in an init.sqf or trigger

hoh=(findDisplay 46) displayAddEventHandler ["keyDown", "if ((_this select 1) == 15) then {removeallweapons player; playaction 'surrender'}"];

any movement key will cancel the action.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

That's a good un^!

Regarding the key codes from the link in post #2 - they are in hexidecimal so:

Hexadecimal: 	0 	1 	2 	3 	4 	5 	6 	7 	8 	9 	A 	B 	C 	D 	E 	F
   Decimal: 	0 	1 	2 	3 	4 	5 	6 	7 	8 	9 	10 	11 	12 	13 	14 	15

DIK_TAB 0x0F

You use the digits after the x:

0 x 16 = 0

F = 15

0+15 = 15

Tab code = 15

so:

DIK_A 0x1E = 30

DIK_B 0x30 = 48

DIK_C 0x2E = 46

DIK_D 0x20 = 32

Share this post


Link to post
Share on other sites

Or you code let the keydown do it for you

hoh=(findDisplay 46) displayAddEventHandler ["keyDown", "hint str (_this select 1)"];

it will display the number of the key pressed.

The only problem would be if the user maps his keys in a different way.

Share this post


Link to post
Share on other sites

Isn't "Surrender" already mapped in the default ArmA2? I'm pretty sure it is and it does just that - put the hands behind the players head. Just a thought.

Share this post


Link to post
Share on other sites

It may be sitting is, although the question has been asked a few times.

Share this post


Link to post
Share on other sites

It is - you just have to enable it under - options / controls. Only works properly if you drop your weapons from the gear menu 1st so what F2k wrote is actually a needed improvement.

Share this post


Link to post
Share on other sites

Hi, I was wondering, and hoping that I am not off topic but....

Is it possible to get this shaved up a bit and used for a "Capture" animation? When capturing a unit, they do the "hands on head" animation? That would include when the captured unit joins your group and follows you to the next location...

Sorry, just putting that out there.....

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  

×