Home   Help Search Login Register  

Author Topic: Key Binding for a conversation?  (Read 2828 times)

0 Members and 2 Guests are viewing this topic.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Key Binding for a conversation?
« on: 07 Jun 2010, 14:44:11 »
;a robber with a knife popped out from a bush near Gorka
;he executes a script named robber.sqf
robber.sqf

Quote
robber1 globalChat "Give me 500 dollars or die!";
sleep 4;
hint "Press 'Shift' to give him 500 dollars OR  kill him with your M4A1 and take his knife"

Well as you realized, how do i assign the keys?
how do I detect if he has pressed that key?

is it even possible?

Regards,
Haroon1992
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Key Binding for a conversation?
« Reply #1 on: 07 Jun 2010, 15:21:31 »
It is, but why not do it via addaction instead? Or, more cleverly, via something else, for instance "Drop your weapon and give me money!" --> "Drop your weapon to give him $500, or shoot him with it. Duh". Then you could check whether the player's primaryWeapon is "" (i.e. nothing) or not. But, I suppose there's a chance he might not have a weapon, in which case the addAction is probably best.

That said, you CAN get a key binding too. This is how I did it in ArmA:

Code: [Select]
(findDisplay 46) displaySetEventHandler ["KeyDown", "if (_this select 1) == 42) then {execvm ""yourscript.sqf""}"];
This is where I got the numbers from: http://community.bistudio.com/wiki/ListOfKeyCodes

Left Shift should be 42, but yeah. Anyway, this will also overwrite any addons etc. that use this scripting command (e.g. ACE2), so unless you either want your mission to be incompatible with these addons, or a bunch of angry people complaining their stuff doesn't work, I suggest going the addAction route instead :)

Don't know if the above works in A2 anymore, sadly.

Wolfrug out.

"When 900 years YOU reach, look as good you will not!"

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Key Binding for a conversation?
« Reply #2 on: 07 Jun 2010, 16:30:21 »
It works but use displayAddEventHandler instead, it shouldn't overwrite other people's display events.
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: Key Binding for a conversation?
« Reply #3 on: 07 Jun 2010, 17:30:11 »
Well that was JUST an example.
There's really nothing like that in my mission.
(Who will rob a guy who have a big gun with just a knife?
Lol I was just doing some joke on the question but you have taken it seriously)

I just wanted to know how to detect a key bind.
(maybe i use it at the end of a cutscene, press 'space bar' to continue.
Like the Benchmark missions of ArmA 2)
but my real aim is to use it in the cutscene, press S to skip...etc
(I know i can open the menu and skip the game)

I'll try it out, thanks........

Regards,
Haroon1992
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: Key Binding for a conversation?
« Reply #4 on: 11 Jun 2010, 17:21:59 »
Hi all,
I tried the displayseteventhandler and it worked
but why isn't the displayerAddEventhandler working?
I copied Wolfrug's code and just changed it to displayAddEventhandler,but it didn't work.

Also what are the meanings of the code?

(findDisplay 46) ?
"if (_this select 1) == 42) then {execvm ""yourscript.sqf""}" ?
why can't i use :
{nil=_this execVM "yourscript.sqf"} ?
and how can i execute a script with arguments in it?

Regards,
Haroon1992
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Key Binding for a conversation?
« Reply #5 on: 11 Jun 2010, 18:46:50 »
display 46 is the "game" display, the one that shows all the time while running around. I don't know who figured that out, but that's the way it is. There are other displays out there, like one for the "gear" screen and so on. But yeah.

_this select 0 =: the eventhandler has a _this array, like all other eventhandlers, and the first element in the _this array is a number corresponding to whatever key was pressed (shift in your case). Whenever you press a key, you see, the "KeyDown" eventhandler runs - much like every time you hit someone with a "hit" eventhandler that eventhandler runs. What the code does is make sure that you only run the script whenever the key -you're- interested in is pressed.

And you can execute a script with arguments just like any other! just add them before:

Quote
"if (_this select 1) == 42) then {[yourarguments, 3] execvm ""yourscript.sqf""}"

Oh, and don't use nil! Use nul or null or something, but not nil=; it will break all the nil-related commands (isNil etc). It's a bit of a bug, but yeah.

Don't know how the addeventhandler works as opposed to set - someone else who knows how it works will have to enlighten you on that. :)

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Key Binding for a conversation?
« Reply #6 on: 11 Jun 2010, 22:05:23 »
Quote
Don't know how the addeventhandler works as opposed to set
It's identical in usage.


Haroon, if you're using init.sqs/sqf you need to add a little pause, like 0.5-1 seconds otherwise it won't work (didn't get displaySetEventHandler to work either without the pause).
And you need to use the command disableSerialization as well.

Also, in Wolfrug's example there's a missing ( and in Arma1/2 you can use ' instead of "" (more readable :P)

Code: (init.sqf) [Select]
disableSerialization;
sleep 1;
_display = (findDisplay 46);
_display displayAddEventHandler ["KeyDown","if ((_this select 1) == 42) then {execVM 'yourscript.sqf'}"];
« Last Edit: 11 Jun 2010, 22:06:55 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: Key Binding for a conversation?
« Reply #7 on: 13 Jun 2010, 21:37:11 »
Code: [Select]
waitUntil {sleep 0.1; (!(isNull (findDisplay 46)))};