MambaSix

Custom onKeyDown event not executing

1 post in this topic

Trying to attach a chemlight and/or IR beacon to players based on a previous method on the forums, where it's added when F5 is pressed.

I have tested my attachIFF.sqf script and it executes as it should in the editor.  The issue comes when I add the custom "ExileClient_gui_hud_event_onKeyDown.sqf" script. The interesting thing is that the removeIFF.sqf code will execute but for the life of me I can't get attachIFF.sqf to execute. I've tried swapping it to another key, and even confirmed on the dedicated server that the code was overwritten by checking the ExileClient_gui_hud_event_onKeyDown variable, which correctly reported the path to my mission's override and had the correct code stored. The error toasts don't even show if the incorrect throwable is selected etc.

Am I just not understanding a piece of 

Any help would be appreciated.

custom\MB6\attachIFF.sqf:

// custom\MB6\attachIFF.sqf
try {
    // Check if player has IFF attached already
    if !(isNil {player getVariable ["MB6_IFF_ON", nil]}) then {
        throw "ExceptionMB6IFFAlreadyOn"
    } else {
        if !((currentThrowable player select 0) in MB6_IFF_ATTACHMENTS) then {
            throw "ExceptionMB6IFFNotSelected"
        } else {
            // Get the current throwable selected
            // Returned in array [<magazineClassName>, <muzzleClassName>, [<magazineId>, <creatorId>]]
            _mag = (currentThrowable player) select 0;
            // Get the actual ammo classname of the item to create
            _ammo = getText(configFile >> "CfgMagazines" >> _mag >> "ammo");

            // Set player attachment point
            _attachPoint = [vehicle player, [-0.03, -0.08, 0], "neck"];
            // Find attachment point of vehicle of player, if it isn't a man
            if !(vehicle player isEqualTo player) then {
                // This finds the vertical height of the vehicle's bounding box
                _bBox = boundingBoxReal (vehicle player);
                _p2 = _bBox select 1;
                _p1 = _bBox select 0;
                //_zpos = (_bBox select 1) select 2;
                _zpos = abs ((_p2 select 2) - (_p1 select 2));
                _attachPoint = [vehicle player, [0, -1, 0.5]];
            };

            // Remove the chemlight/beacon from inventory
            player removeMagazine _mag;
            // Create the chemlight/beacon
            _light = _ammo createVehicle ASLToATL getposASL player;
            if !(typeName _light isEqualTo "OBJECT") then {
                throw "ExceptionMB6IFFCreationError"
            } else {
                ["SuccessTitleOnly", ["IFF marker attached!"]] call ExileClient_gui_toaster_addTemplateToast;
            };
            _light attachTo _attachPoint;
            // Set the variableses
            player setVariable ["MB6_IFF_ON", true, false];
            player setVariable ["MB6_IFF_OBJ", _light, false];

            // Action to remove the IFF marker
            /*_action = player addAction ["Remove IFF",
                {
                    _obj = player getVariable ["MB6_IFF_OBJ", objNull];
                    detach _obj;
                    deleteVehicle _obj;
                    player setVariable ["MB6_IFF_ON", nil, false];
                    player setVariable ["MB6_IFF_OBJ", nil, false]; 
                    _body = (_this select 1);
                    player removeEventHandler ["GetInMan", (player getVariable ["MB6_IFF_EH",[0]]) select 0];
                    player removeEventHandler ["GetOutMan", (player getVariable ["MB6_IFF_EH",[0,0]]) select 1];
                    player removeEventHandler ["Respawn", (player getVariable ["MB6_IFF_EH",[0,0,0]]) select 2];
                    player setVariable ["MB6_IFF_EH", nil, false];
                    player removeAction (_this select 2);
                },[],0,false,true,"","true"];*/
            
            // Set the IFF marker on top of the vehicle when the player gets in one
            _getInEH = player addEventHandler ["GetInMan", {
                // Find attachment point of vehicle of player, if it isn't a man
                _bBox = boundingBoxReal (_this select 2);
                _p2 = _bBox select 1;
                _p1 = _bBox select 0;
                //_zpos = (_bBox select 1) select 2;
                _zpos = abs ((_p2 select 2) - (_p1 select 2));
                (player getVariable ["MB6_IFF_OBJ", objNull]) attachTo [_this select 2, [0,-1,0.5]];
            }];
            // Set the IFF marker back on the player
            _getOutEH = player addEventHandler ["GetOutMan", {
                (player getVariable ["MB6_IFF_OBJ", objNull]) attachTo [vehicle player, [-0.03, -0.08, 0], "neck"];
            }];
            // Add a respawn EH to remove the GetIn/GetOut persistent EHs and reset object variables
            _respawnLocalEH = player addEventHandler ["Respawn", {
                _body = (_this select 1);
                player removeEventHandler ["GetInMan", (_body getVariable ["MB6_IFF_EH",[0]]) select 0];
                player removeEventHandler ["GetOutMan", (_body getVariable ["MB6_IFF_EH",[0,0]]) select 1];
                player removeEventHandler ["Respawn", (_body getVariable ["MB6_IFF_EH",[0,0,0]]) select 2];
            }];
             // Record EHs to remove; protect randomly removing an Exile EH
            _playerEHs = [_getInEH, _getOutEH,_respawnLocalEH];
            player setVariable ["MB6_IFF_EH", _playerEHs, false];
        };
    };
}
catch {
    switch (_exception) do {
        case "ExceptionMB6IFFAlreadyOn": {
            // Toast
            ["ErrorTitleOnly", ["IFF marker already attached!"]] call ExileClient_gui_toaster_addTemplateToast;
            //hint "ON!";
        };
        case "ExceptionMB6IFFNotSelected": {
            // Toast
            ["ErrorTitleAndText", ["IFF marker not attached!", "The throwable you selected is not an IFF item."]] call ExileClient_gui_toaster_addTemplateToast;
            //hint "BAD!";
        };
        default {
            // Toast
            ["ErrorTitleAndText", ["IFF marker not attached!", "Problem is, we don't really know what went wrong."]] call ExileClient_gui_toaster_addTemplateToast;
            //hint "ERROR!";
        };
    };
};

ExileClient_gui_hud_event_onKeyDown.sqf:

/**
 * ExileClient_gui_hud_event_onKeyDown
 *
 * Exile Mod
 * www.exilemod.com
 * © 2015 Exile Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 */
 
private["_stopPropagation","_caller","_keyCode","_shiftState","_controlState","_altState","_grenadeName"];
_stopPropagation = false;
_caller = _this select 0;
_keyCode = _this select 1;
_shiftState = _this select 2;
_controlState = _this select 3;
_altState = _this select 4; 
if ((_keyCode in (actionKeys "nightVision")) && ExileClientGasMaskVisible) exitWith {true};
if (_keyCode in (actionKeys "TacticalView")) exitWith {true};
if (!(_controlState) && (_keyCode in (actionKeys "Throw"))) exitWith
{	
	_stopPropagation = false;
	_grenadeName = (currentThrowable player) select 0;
	if (_grenadeName isEqualTo "Exile_Item_ZipTie") then 
	{
		call ExileClient_object_handcuffs_use;
		_stopPropagation = true;
	};
	_stopPropagation
};
switch (_keyCode) do  
{ 
	case 0x29:	{ _stopPropagation = true; }; 
	case 0x0B:	 	{ _stopPropagation = true; };
	case 0x06: 	{ _stopPropagation = true; };
	case 0x07: 	{ _stopPropagation = true; };
	case 0x08: 	{ _stopPropagation = true; };
	case 0x09: 	{ _stopPropagation = true; };
	case 0x0A: 	{ _stopPropagation = true; };
	case 0x3B: 	{ _stopPropagation = true; };
	case 0x3C: 	{ _stopPropagation = true; };
	case 0x3D:	{ _stopPropagation = true; };
	case 0x3E:	{ _stopPropagation = true; };
	case 0x3F:	{ _nul = [] execVM "custom\MB6\attachIFF.sqf"; _stopPropagation = true; };
	case 0x40: 	{ _nul = [] execVM "custom\MB6\removeIFF.sqf"; _stopPropagation = true; };
	case 0x41: 	{ _stopPropagation = true; };
	case 0x42:	{ _stopPropagation = true; };
	case 0x43: 	{ _stopPropagation = true; };
	case 0x44:	{ _stopPropagation = true; };
	case 0x57: 	{ _stopPropagation = true; };
	case 0x58: 	{ _stopPropagation = true; };
	case 0x0E: 	{ _stopPropagation = true; };
	case 0xCF:	{ _stopPropagation = true; };
	case 0xC7:	{ _stopPropagation = true; };
	case 0x02: 	
	{ 
		_stopPropagation = true; 
	};
	case 0x03: 	
	{ 
		_stopPropagation = true; 
	};
	case 0x04: 	
	{ 
		_stopPropagation = true; 
	};
	case 0x05: 	
	{ 
		_stopPropagation = true;
	};
	case 0xD2:
	{
		_stopPropagation = true;
	};
	case 0x10:
	{
		if (ExileClientIsInConstructionMode) then
		{
			_stopPropagation = true;
		};
	};
	case 0x12:
	{
		if (ExileClientIsInConstructionMode) then
		{
			_stopPropagation = true;
		};
	};
	case 0xC9: 
	{
		if (ExileClientIsInConstructionMode) then
		{
			_stopPropagation = true;
		};
	};
	case 0xD1: 
	{
		if (ExileClientIsInConstructionMode) then
		{
			_stopPropagation = true;
		};
	};
	case 0x39:
	{
		if (ExileClientIsInConstructionMode) then
		{
			_stopPropagation = true;
		};
	};
	case 0x01:
	{
		if (ExileClientIsInConstructionMode) then
		{
			ExileClientConstructionResult = 2;
			_stopPropagation = true;
		};
		if (ExileIsPlayingRussianRoulette) then 
		{
			if (ExileRussianRouletteCanEscape) then 
			{
				["leaveRussianRouletteRequest", []] call ExileClient_system_network_send;
				ExileRussianRouletteCanEscape = false;
			};
			_stopPropagation = true;
		};
	};
};
_stopPropagation

config.cpp:

class CfgExileCustomCode 
{
	/*
		You can overwrite every single file of our code without touching it.
		To do that, add the function name you want to overwrite plus the 
		path to your custom file here. If you wonder how this works, have a
		look at our bootstrap/fn_preInit.sqf function.

		Simply add the following scheme here:

		<Function Name of Exile> = "<New File Name>";

		Example:

		ExileClient_util_fusRoDah = "myaddon\myfunction.sqf";
	*/
	ExileClient_object_player_death_startBleedingOut = "custom\EnigmaRevive\ExileClient_object_player_death_startBleedingOut.sqf"; //Happys Revive
    ExileClient_object_player_event_onInventoryOpened = "custom\EnigmaRevive\ExileClient_object_player_event_onInventoryOpened.sqf"; //Happys Revive AntiDupe ---NEW with v0.65
	ExileClient_gui_hud_event_onKeyDown = "custom\MB6\ExileClient_gui_hud_event_onKeyDown.sqf";
};

 

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.