RyanTurner 23 Posted September 20, 2016 Hey, i've been tryign to make a "jump" on key and i can't get it to work, if addAction to the script with the jump works fine. moduleName_keyDownEHId = (findDisplay 57) displayAddEventHandler ["KeyDown", "hint str _this;"]; // Init.sqf MY_KEYDOWN_FNC = { switch (_this) do { //Key "SPACE" ; Spacebar case 57: { nul = [] execVM "jump.sqf"; }; }; }; // keypressed.sqf { _vel = velocity player; _dir = direction player; _speed = 1; player setVelocity [ (_vel select 0) + (sin _dir * _speed), (_vel select 1) + (cos _dir * _speed), (_vel select 2) + 5 ]; }]; // jump.sqf If i do add an Action on the jump.sqf and make it run init.sqf (run the jump.sqf) it will work fine in game with a Interaction menu, does anyone know why it doesnt work? Credit to the Jump script by: dreadedentity Share this post Link to post Share on other sites
das attorney 858 Posted September 20, 2016 Off the top of my head, I would say you need to do (findDisplay 46), not 57. Display 46 is the main display of Arma and normally you would attach event handlers to that one. Also, you are using some code to make a hint and that doesn't call your function. So try something like this: jumpDisplayHandle = (findDisplay 46) displayAddEventHandler ["KeyDown", "_this call MY_KEYDOWN_FNC"]; // Init.sqf With your other function as you showed it as well. You should do a search on this mission editing forum as well. There's loads of good threads that tell you exactly what to do somewhere in here as well. :) Share this post Link to post Share on other sites
RyanTurner 23 Posted September 20, 2016 i've changed the: moduleName_keyDownEHId = (findDisplay 57) displayAddEventHandler ["KeyDown", "hint str _this;"]; // Init.sqf to jumpDisplayHandle = (findDisplay 46) displayAddEventHandler ["KeyDown", "_this call MY_KEYDOWN_FNC"]; // Init.sqf and you said to change: MY_KEYDOWN_FNC = { switch (_this) do { //Key "SPACE" ; Spacebar case 57: { nul = [] execVM "optreJ_script.sqf"; }; }; }; // scripts\optreJ_runner.sqf (chang'd) to MY_KEYDOWN_FNC = { switch (_this) do { //Key "SPACE" ; Spacebar case 46: { nul = [] execVM "optreJ_script.sqf"; }; }; }; // scripts\optreJ_runner.sqf but if i change that "Spacebar" will be a Y at the wikipedia, and i've change the files names and directories.P.S: Still doesnt work. Share this post Link to post Share on other sites
t.buur 0 Posted September 21, 2016 For me it works with following changes: moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 57) then {_nul = [] execVM 'jump.sqf'};"] and _vel = velocity player; _dir = direction player; _speed = 1; player setVelocity [ ((_vel select 0) + (sin _dir * _speed)), ((_vel select 1) + (cos _dir * _speed)), ((_vel select 2) + 5) ]; // jump.sqf some comments: if you want to know what's in the _this variable use hint str _this Be careful in eventhandelers with double quotes " . Mostly you better use single quotes ' Your script jump.sqf was written by you as function. Then you have to use call or spawn. For me it is not clear what you mean with but if i change that "Spacebar" will be a Y at the wikipedia, and i've change the files names and directories. Maybe you can explain a little bit more. Share this post Link to post Share on other sites
RyanTurner 23 Posted September 21, 2016 that the "Spacebar" was for this code MY_KEYDOWN_FNC = { switch (_this) do { //Key "SPACE" ; Spacebar case 57: { nul = [] execVM "optreJ_script.sqf"; // jump.sqf }; }; }; cause i want when i press the Spacebar run the keydown and make the action (script) in-game so i can jump via press of Spacebar insteed of interatction menu (scroll menu from ArmA games) Share this post Link to post Share on other sites
t.buur 0 Posted September 21, 2016 So my code will work as a charm. Please try it, it runs. Without the keydown. It is not addaction. Be careful with the itnteraction menu (it is called addactien). It is an other thing. With my (and also your) code you define a new action by pressing a key. In Arma I know three types of eventhandlers: addEventHandler https://community.bistudio.com/wiki/addEventHandler addAction https://community.bistudio.com/wiki/addAction inGameUISetEventhandlers https://community.bistudio.com/wiki/inGameUISetEventHandler All of them work a little bit differently. That make it hard for beginners to find the right one and also to find the right words to describe their problems. regards Share this post Link to post Share on other sites
RyanTurner 23 Posted September 22, 2016 Im confused now, waht do i need to change to make when i press down the key (Spacebar) to run/do the "action"(action being jump not addAction) Share this post Link to post Share on other sites
t.buur 0 Posted September 22, 2016 You don't need a change. 1.copy jump.sqf in a file in your mission folder with name jump.sqf _vel = velocity player; _dir = direction player; _speed = 1; player setVelocity [ ((_vel select 0) + (sin _dir * _speed)), ((_vel select 1) + (cos _dir * _speed)), ((_vel select 2) + 5) ]; // jump.sqf 2. copy eventhandler and paste it debug console. Run it. moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 57) then {_nul = [] execVM 'jump.sqf'};"] that is all. Now press space bar and you will jump. Later you can copy eventhandler in init.sqf or an equal file. Share this post Link to post Share on other sites
RyanTurner 23 Posted September 22, 2016 It does work thanks! may i ask for an other thing, if i dont start it localy it doesnt work, how can i make it work via .sqf (init or not) and do you know how to make a x amount of the time so they can jump again (like a x secs so they dont spam it like a jetpack) or make it's anyway to make the with the isTouchingGround you know "only can jump if in the ground" but iwht like 0.5 sleep or 1 sleep on the jump? Share this post Link to post Share on other sites
t.buur 0 Posted September 22, 2016 Copy the eventhandler in a file named init.sqf in your mission folder. Thats all. During start up ARMA loads all commads in the init.sqf. Please have also a deeper look to the https://community.bistudio.com/wiki/Event_Scripts For the second point: You cannot work with a sleep command inside a eventhandler! So we have to found a solution within the jump sqf Try this jump = { // your jumping code as a function _vel = velocity player; _dir = direction player; _speed = 1; player setVelocity [ ((_vel select 0) + (sin _dir * _speed)), ((_vel select 1) + (cos _dir * _speed)), ((_vel select 2) + 5) ]; }; if (isNil "player_jump_time") then // function only executet when variable player_jump_time not set. { call jump; player_jump_time = [player,time]; // variable player_jump_time will be set } else { //if variable set this part will executet if ((player == player_jump_time select 0) && (time > (player_jump_time select 1 ) + 5)) then // here we check if the player_jump_varialble is right player and also if the time (here 5 seconds.) { call jump; player_jump_time = [player,time]; // variable player_jump_time will be set in the eles part }; }; // jump.sqf For me it works Share this post Link to post Share on other sites
RyanTurner 23 Posted September 23, 2016 I've asked about the init.sqf cause the moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 57) then {_nul = [] execVM 'scripts\optreJ_script.sqf'};"]; doesnt work if i dont start localy (debug menu), and thanks for the help with the "jump limit" just to ask it's possible to limit the jump script only when standing? Share this post Link to post Share on other sites
t.buur 0 Posted September 23, 2016 Sometimes the init.sqf loaded to fast. Insert simple a sleep 3; before the eventhandler and than it will run. sleep 3; moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 57) then {_nul = [] execVM 'jump.sqf'};"] You can check your own speed. If it is zero you can add special code. jump = { // your jumping code as a function _vel = velocity player; _dir = direction player; _speed = 1; player setVelocity [ ((_vel select 0) + (sin _dir * _speed)), ((_vel select 1) + (cos _dir * _speed)), ((_vel select 2) + 5) ]; }; if (isNil "player_jump_time" ) then // function only executet when variable player_jump_time not set for the player { if ((vectorMagnitude velocity player) == 0) then { hint "I am standing now! and cannot jump"; } else { call jump; player_jump_time = [player,time]; // variable player_jump_time will be set }; } else { //if variable set this part will executet if ((player == player_jump_time select 0) && (time > (player_jump_time select 1 ) + 5)) then // here we check if the player_jump_varialble is right player and also if the time (here 5 seconds.) { if ((vectorMagnitude velocity player) == 0) then { hint "I am standing now! and cannot jump"; } else { call jump; player_jump_time = [player,time]; // variable player_jump_time will be set in the eles part }; }; }; Share this post Link to post Share on other sites
RyanTurner 23 Posted September 23, 2016 Thanks with the Init sleep i didn't knew it actual help'd! and btw if the people isn't moving it can't jump, but if the they are prone/crouch moving they can jump it's any way easy way to fix it? Share this post Link to post Share on other sites
t.buur 0 Posted September 23, 2016 Yes, https://community.bistudio.com/wiki/stance jump = { // your jumping code as a function _vel = velocity player; _dir = direction player; _speed = 1; player setVelocity [ ((_vel select 0) + (sin _dir * _speed)), ((_vel select 1) + (cos _dir * _speed)), ((_vel select 2) + 5) ]; }; if (isNil "player_jump_time" ) then // function only executet when variable player_jump_time not set for the player { if ((vectorMagnitude velocity player) == 0 || (stance player) == "CROUCH" || (stance player) == "PRONE") then { hint "I am standing now! and cannot jump"; } else { call jump; player_jump_time = [player,time]; // variable player_jump_time will be set }; } else { //if variable set this part will executet if ((player == player_jump_time select 0) && (time > (player_jump_time select 1 ) + 5)) then // here we check if the player_jump_varialble is right player and also if the time (here 5 seconds.) { if ((vectorMagnitude velocity player) == 0 || (stance player) == "CROUCH" || (stance player) == "PRONE") then { hint "I am standing now! and cannot jump"; } else { call jump; player_jump_time = [player,time]; // variable player_jump_time will be set in the eles part }; }; }; Share this post Link to post Share on other sites
RyanTurner 23 Posted September 24, 2016 Thank you! now a working great (not saying it wasnt) now i can have a Halo jump look-a-like for the missions just one more question, insteed of if ((vectorMagnitude velocity player) == 0 || (stance player) == "CROUCH" || (stance player) == "PRONE") then is it possible to use isTouchingGround insteed of delaying the script? you know so only can jump of any height and only can jump when it's on the ground? Share this post Link to post Share on other sites
t.buur 0 Posted September 24, 2016 Never worked with this command. Try it. Share this post Link to post Share on other sites