Jump to content
Sign in to follow this  
maxqubit

Bind a key directly to a script

Recommended Posts

As topic says ... is it possible to bind a key directly to a script?

Say you want to excecute 'somescript.sqs' by pressing the L key on the keyboard. Is this possible and if yes, how would you do that?

Share this post


Link to post
Share on other sites

This is only possible with dialog eventhandlers like onKeyDown. Otherwise it is not possible or it would be really tricky respectively.

Share this post


Link to post
Share on other sites
This is only possible with dialog eventhandlers like onKeyDown. Otherwise it is not possible or it would be really tricky respectively.

Thx ... any pointer where to start understanding this dialog eventhandlers? I searched and hit upon some stuff but it feels like i jump in the middle of this stuff. A basic start point/thread/topic/site would be appreciated

Share this post


Link to post
Share on other sites

If you not use dialogs already I think it is not possible what you want. But to get it clear tell us in what situation you should be able to press a key and what should happen.

Share this post


Link to post
Share on other sites

I made a mission (see this post) of a Cobra attacking a convoy (how original:)

Anyway i use character switching between pilot and gunner. If you take the gunners seat the pilot doesn't do anything anymore. That's GOOD, because i can fly as a pilot to where ever i want, go into hover, then switch to gunner and take out infantry with the main gun while the Cobra keeps hovering ...

... of course somebody came up with the idea that it would be even better if you could hover below a tree line, take the gunner seat AND ORDER YOUR PILOT TO BOB ABOVE THE TREELINE, take some shots and go back below the treeline into cover.

... now how would you perform such an action while being gunner?

You'd think of something like define a button/key which:

- onkeydown (or something like that) performs in pseudo code (h=flyingheight, heli flyinheight h+10)

- onkeyup (or something like that) performs in pseudo code (h=flyingheight, heli flyinheight h-10)

This only when you are gunner and stuff like that.

Anyway, the idea is to alter the flyinheight by pressing a key or button while in gunner seat

(but it could be that i overlook a much more simple solution, if that is the case, enlighten me:)

Share this post


Link to post
Share on other sites
For this situation, I think a BIKI:AddAction would suffice. Add 2 actions to your Action menu for both the up and down request and you're done.

Yep, that could do the trick and is not too complex.

(Max with his 360 controller muses a bit on ... it would be very sophisticated if you could bob by pulling the left analogue trigger, pull it more = bob more high ... right stick to aim and right trigger to fire ... hmmm, perhaps too sophisticated and 'arcade' and i wouldn't know how to program this, if at all possible;)

Share this post


Link to post
Share on other sites
For this situation, I think a BIKI:AddAction would suffice. Add 2 actions to your Action menu for both the up and down request and you're done.

I did this (can post the scripting) but it is very weird! If i set flyinheigth to a height above the current height the heli will go up, but if i set it to a height lower than the current height nothing happens!? Even if all is hard-coded! So say heli (name is 'cobra') is at 10 meters and i perform a script in which are the following satements:

cobra flyinheight 25

~20

cobra flyinheight 10

The cobra WILL go to 25 meters but WON'T go down to 10 meters anymore!?

Weird.

Share this post


Link to post
Share on other sites

I guess the problem is the same as in OFP, sometime a pilot AI must be told to move to get a new flyinheight to be applied, even if this move is not going anywhere it forces the AI pilot to apply the flyinheight order.

In OFP, the following would have worked with your problem, i guess it should always work in ArmA

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">cobra flyinheight 25

cobra move getpos cobra

~20

cobra flyinheight 10

cobra move getpos cobra

Share this post


Link to post
Share on other sites
Thx sanctuary. Will try it

Tried it ... same prob. Goes up NOT down ... smells buggy (this goes for a lot of character/team switching features ... switching f*cks up the AI/commanding) and i don't like workarounds anyway ... Probably i will report it in the BUG list

EDIT(!): Hmmm, not giving up on this i started to implement it all manually so using addswitchableunit and stuff with scripting in stead of predefining it in the editor ... And it seems to work (better). Will report back and use it in version 0.2 of my Cobra vs convoy mission

EDIT2(!!): Nope, it doesn't work either. I used a global variable h for flyinheight. If i do h = h + 10 the heli will go up, if i do h = h - 10 it won't go down. Tried adding a dummy moveto and lots of more stuff. It is just a bug i think. Frustrating cause it becomes useless.

To make it clear. I do this as a gunner ... so if the gunner wants to manipulate the flyinheight it WILL go up but it WON'T go down (no matter if the gunner is teamleader or whatever)!?!?

Share this post


Link to post
Share on other sites
Thx sanctuary. Will try it

Oh no ... it seems it works!! Dumbass me used 'moveto' but i HAD TO USE 'domove' so:

cobra DOmove getpos cobra

(but it is still a workaround;)

Share this post


Link to post
Share on other sites

I'm also interested in binding keys to scripts... for a very simple reason : It's a jump script !!

Currently, since you can't jump over small obstacles you may have to walk around insignifant fences...

Nobody found a way to do it yet ?

I found that command actionkeys which "Returns a list of dikCodes of buttons assigned to the given user action." but I don't really know if that can help me...

Thanks

Eric

Share this post


Link to post
Share on other sites

Those codes IIRC are to bind to buttons on a dialog.

e.g. C for Cancel button, Y for Yes button, etc...

Share this post


Link to post
Share on other sites

control ctrlSetEventHandler [Event, CODE]

Events

[/i]KeyDown

KeyUp

ChildDestroy

Load

UnLoad[/i]

Find MainDisplay control

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_dsp = [];

for[{_i = 0},{_i < 1000},{_i=_i+1}]do{_c = (findDisplay _i);if(_c==_c)then{_dsp = _dsp + [c];};}

_dsp - display list

and we found display `#46` <- MainDisplay

just try this wink_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

@!IsNull (findDisplay 46)

(findDisplay 46) displaySetEventHandler ["KeyDown", "hint str _this"]

Share this post


Link to post
Share on other sites

I am interested in the original topic of this thread. I don't want any addAction substitutes. Let's imagine that when I press F1, it fires a code or script that in all its glory is f1pressed=1, now what do I have to do? The ID number of F1 is 59.

Share this post


Link to post
Share on other sites

Based on the info that Mr. Flea provided, this code below may help other folks see how to apply it.

;AddHandler.sqs

;thanks to mr.Flea for posting the information on key-events in the BIS forums.

; the next line is just ONE line of code!

if(!IsNull (findDisplay 46)) then {(findDisplay 46) displaySetEventHandler ["KeyUp", "[""KeyUp"",_this]exec""KeyShow.sqs"";"]

;};

(edit: for some reason the semicolon-brace-semicolon above is forced to next line on this forum, the whole thing from if to there SHOULD be on one line!)

;KeyShow.sqs

_p0=_this select 0;

_p1=(_this select 1)select 0;

_p2=(_this select 1)select 1;

_p3=(_this select 1)select 2;

_p4=(_this select 1)select 3;

_p5=(_this select 1)select 4;

_s0="";

_s0=_s0+(str(_p0));

_s0=_s0+"\n obj:"+(str(_p1));

_s0=_s0+"\n keycode:"+(str(_p2));

_s0=_s0+"\n shift:"+(str(_p3));

_s0=_s0+"\n ctrl:"+(str(_p4));

_s0=_s0+"\n alt:"+(str(_p5));

hint _s0;

Share this post


Link to post
Share on other sites

The code has proven extremely useful in my maps. But how could I detect when a player presses a button on the mouse or joystick?

Share this post


Link to post
Share on other sites

Find the right Code, Celery. it's easiest if you set it in your config (for example for Reload) and read it out in a script then:

hint format[ "%1",actionKeys "ReloadMagazine" ]

Share this post


Link to post
Share on other sites
Find the right Code, Celery. it's easiest if you set it in your config (for example for Reload) and read it out in a script then:

hint format[ "%1",actionKeys "ReloadMagazine" ]

I can check those codes in my player config, but the problem is that even though I know the code, findDisplay 46 doesn't detect mouse clicks.

Share this post


Link to post
Share on other sites

Try to create a subdisplay called "RscDisplayEmpty" child to #46 with createDisplay and assign a EH to this one then.

If "RscDisplayEmpty" aint good try one of the following:

RscDisplayMission #46

RscDisplayIntro #47

RscDisplayOutro #48

RscDisplayAward #62

RscDisplayCampaign #33

still, i wonder why 46 doesnt accept mouse clicks...

Share this post


Link to post
Share on other sites

I guess for mouseclick events you need a control and not a display.

See scope column here.

Probably the onKey events are a exception as they work also for displays.

Share this post


Link to post
Share on other sites
I guess for mouseclick events you need a control and not a display.

See scope column here.

Probably the onKey events are a exception as they work also for displays.

So how do I add such an eventhandler to make it work?

I tried inGameUISetEventHandler ["onMouseButtonDown","player setdammage 1"] for immediate feedback, but got nothing.

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  

×