Jump to content
IGD Big Steve

onKeyDown script help (Resolved)

Recommended Posts

I have been trying to get this script to work for a while now. I am trying to make a keypress (ideally "O", key# 39 I think), that will call a script to toggle between different "fadesound" commands on a DEDICATED server. I'm not looking for anything fancy, just the basics. There's 100% an error in my logic and any help would be appreciated. 

 

// line in initServer.sqf
earplugDisplayHandle = (findDisplay 46) displayAddEventHandler ["KeyDown", [] remoteExec ["dokeyPress_fnc", _this select 0]]; 

 

//fnc in initPlayerLocal.sqf

dokeyPress_fnc = {
	switch (_this) do {
              //key
		case 39: {
			nul = [] execVM "earplugs.sqf";
		};
	};
};

 

//earplugs.sqf

_plugNum = 0;

if (_plugNum ==  0) then {
1 fadeSound 1;
hint format["earplugs removed"];
_plugNum = _plugNum + 1};


if (_plugNum ==  1) then {
1 fadeSound 0.5;
hint format["earplugs 50%"];
_plugNum = _plugNum + 1};


if (_plugNum ==  2) then {
1 fadeSound 0.2;
hint format["earplugs 80%"];
_plugNum = 0};

 

Share this post


Link to post
Share on other sites

First of all, there is no reason to do that from server. Your EH "keydown"  is fine for local PC, then all clients (+ hosted if not dedicated)

So, this EH should be in initPlayerLocal.sqf with your function.

 

Try that:

 

togglingKEY18 = 0;
(findDisplay 46) displayAddEventHandler ["KeyDown", {
    params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];
    if (_key == 24) then {
        switch (togglingKEY18) do {
            case 0 : {
                hint "earplugs removed";
                1 fadeSound 1;
            };
            case 1 : {
                hint "earplugs 50%";
                1 fadeSound 0.5;
            };
            case 2 : {
                hint "earplugs 80%";
                1 fadeSound 0.2;
            };
        };
    togglingKEY18 = (togglingKEY18 + 1) mod 3;
    };
    false
 }];

 

 

  • Like 1

Share this post


Link to post
Share on other sites
59 minutes ago, pierremgi said:

First of all, there is no reason to do that from server. Your EH "keydown"  is fine for local PC, then all clients (+ hosted if not dedicated)

So, this EH should be in initPlayerLocal.sqf with your function.

 

Try that:

 

 

 

I tried this with mild success. The script is constantly hinting the pressed key. I removed all my old scripts and I believe I still need the top line in initServer to have it function correctly.

Share this post


Link to post
Share on other sites

Works now with some modifications. Thanks a ton! The script must be inside initPlayerLocal.sqf and run before any execVM scripts/functions for some reason.

 

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

×