Jump to content

Recommended Posts

Hey guys, I was wondering if anyone could help me fix my earplug script im working on. Pretty much trying to override the F1 key here but its overriding every other key as well. Any help would be greatly appreciated.

 


[] spawn {
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displaySetEventHandler ["KeyDown", "_this call keyspressed; true"];
};


keyspressed = {
    _keyDik = _this select 1;
    _shift =_this select 2;
    _ctrl = _this select 3;
    _alt = _this select 4;
    _handled = false;


    switch (_this select 1) do {

    case 59: {
            if (_ctrl) then {
                1 fadeSound 0.2;
                hint "Earplugs in!";
            }
            else {
                1 fadeSound 1;
                hint "Earplugs removed!";
            };
        };
    };
    _handled;
};

Share this post


Link to post
Share on other sites
[] spawn 
{
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displayAddEventHandler ["KeyDown","_this call keyspressed"];
};


keyspressed = 
{
    params["_ctrl","_dikCode","_shift","_ctrlKey","_alt",["_handled",false,[false]]];

    switch (_dikCode) do 
    {
        case 59: 
        {
            if(_ctrlKey) then 
            {
                1 fadeSound 0.2;
                hint "Earplugs in!";
            } else {
                1 fadeSound 1;
                hint "Earplugs removed!";
            };
            _handled = true;
        };
    };

    _handled;
};

 

Share this post


Link to post
Share on other sites
9 hours ago, hoverguy said:

[] spawn 
{
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displayAddEventHandler ["KeyDown","_this call keyspressed"];
};


keyspressed = 
{
    params["_ctrl","_dikCode","_shift","_ctrlKey","_alt",["_handled",false,[false]]];

    switch (_dikCode) do 
    {
        case 59: 
        {
            if(_ctrlKey) then 
            {
                1 fadeSound 0.2;
                hint "Earplugs in!";
            } else {
                1 fadeSound 1;
                hint "Earplugs removed!";
            };
            _handled = true;
        };
    };

    _handled;
};

 

 

this is setting the sound level to max when earplugs are removed.

 

better to store soundVolume in a variable before reducing sound, so when earplugs removed set to that variable instead of max.

 

[] spawn {
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displaySetEventHandler ["KeyDown", "_this call keyspressed; true"];
};


keyspressed = {
    _keyDik = _this select 1;
    _shift =_this select 2;
    _ctrl = _this select 3;
    _alt = _this select 4;
    _handled = false;


    switch (_this select 1) do {

    case 59: {
            if (_ctrl) then {
				player setVariable ['tag_var_earplugsVolume',soundVolume,FALSE];
                1 fadeSound 0.2;
                hint "Earplugs in!";
            }
            else {
                1 fadeSound (player getVariable ['tag_var_earplugsVolume',1]);
                hint "Earplugs removed!";
            };
        };
    };
    _handled;
};

 

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

×