Jump to content

Recommended Posts

I've got a safeZone script I am working on. Players spawn on a base, and should be able to use bunkers as "elevators" to other parts of the base via add action, at which point they will be teleported to the corresponding bunker object. I've looked at the wiki for both BIS_fnc_holdActionAdd and I've narrowed it down to the custom arguments, but I have no idea how to extrapolate that. I am using the bunker names to help the script determine which bunker should send a player to. The action is added, but having trouble passing the destination variable.
 

_baseEntry1 = objNull;
_baseEntry2 = objNull;
_baseExit1 = objNull;
_baseExit2 = objNull;


//Initialize Elevators
_syncedobjs = synchronizedObjects _logic;
{
    if (toLower str _x find "base_exit_1" == 0) then
    {
        _baseExit1 = _x;
    }
} forEach _syncedobjs;

_syncedobjs = synchronizedObjects _logic;
{
    if (toLower str _x find "base_exit_2" == 0) then
    {
        _baseExit2 = _x;
    }
} forEach _syncedobjs;

_syncedobjs = synchronizedObjects _logic;
{
    if (toLower str _x find "base_entry_1" == 0) then
    {
        _baseEntry1 = _x;
    }
} forEach _syncedobjs;

_syncedobjs = synchronizedObjects _logic;
{
    if (toLower str _x find "base_entry_2" == 0) then
    {
        _baseEntry2 = _x;
    }
} forEach _syncedobjs;

diag_log format["logic instance: %1", _logic];
diag_log format["_baseExit1: %1", _baseExit1];
diag_log format["_baseExit1 position: %1", getPosATL _baseExit1];
diag_log format["_baseExit2: %1", _baseExit2];
diag_log format["_baseExit2 position: %1", getPosATL _baseExit2];
diag_log format["_baseEntry1: %1", _baseEntry1];
diag_log format["_baseEntry1 position: %1", getPosATL _baseEntry1];
diag_log format["_baseEntry2: %1", _baseEntry2];
diag_log format["_baseEntry2 position: %1", getPosATL _baseEntry2];

// Code executed when action is performed
_actionCode = {
    private ["_baseEntry1"];  // Define _baseEntry1 as a private variable to access it within this code block


    // Teleport
    [0, "BLACK", 1, 1] spawn BIS_fnc_fadeEffect;
    sleep 0.5;
    player setPosATL (getPosATL _baseEntry1);
    [1, "BLACK", 1, 1] spawn BIS_fnc_fadeEffect;
};

// Add action to the object _baseExit1
_baseExit1 addAction [
    "Exit to Helipad",                           // Title of the action
    _actionCode,                                 // Code executed when action is performed
    [_baseEntry1],                               // Additional parameters: passing _baseEntry1
    6,                                           // Priority of the action
    true,                                        // Show in the action menu
    true,                                        // Hide the action on completion
    "",                                          // Condition for the action to be available
    "alive player"                               // Condition for the action to be shown
];

Share this post


Link to post
Share on other sites

Short answer...

16 hours ago, Northup said:

_baseExit1 addAction [
    "Exit to Helipad",                           // Title of the action
    _actionCode,                                 // Code executed when action is performed
    [_baseEntry1],                               // Additional parameters: passing _baseEntry1

_actionCode = {
	params [ "_target", "_caller", "_id", "_args" ];    // _args will be [_baseEntry1] as passed
	_args params[ "_to" ];                              // _to will be _baseEntry1

 

Long answer, maybe an easier way to make the connections (this is presuming all exit/entries of the same number are tied to each other entry_1 goes to exit_1 and visa versa)...

Spoiler

_baseConnections = [
	[ /*Entry1*/, /*Exit1*/ ], // connection 0 - entry1 <-> exit1
	[ /*Entry2*/, /*Exit2*/ ]  // connection 1 - entry2 <-> exit2
];

//Initialize Elevators
_syncedobjs = synchronizedObjects _logic;
{
	_name = toLower str _x;
	
	switch ( true ) do {
		case ( _name select[ 5, 5 ] == "entry" ) : {
			[ parseNumber ( _name splitString "base_entry_" ) -1, 0 ]
		};
		case ( _name select[ 5, 4 ] == "exit" ) : {
			[ parseNumber ( _name splitString "base_exit_" ) -1, 1 ]
		};
	} params[ "_connection", "_index" ];
		
	_baseConnections select _connection set[ _index, _x ];
} forEach _syncedobjs;

// Function to add action
_fnc_addAction = {
	params[ "_from", "_to", "_title" ];
	
	 _from addAction [
		format[ "%1 %2", _title, _to getVariable[ "locationName", "" ] ],
		{
			params [ "_target", "_caller", "_id", "_args" ];
			_args params[ "_to" ];
			
			// Teleport
		    [0, "BLACK", 1, 1] spawn BIS_fnc_fadeEffect;
		    sleep 0.5;
		    _caller setPosATL getPosATL _to;
		    [1, "BLACK", 1, 1] spawn BIS_fnc_fadeEffect;
		}, 
		[ _to ],
		6,
		true,
		true,
		"",
		//_target (unit to which action is attached to) and _this (caller/executing unit)
		"alive _this"
	]; 
	
};

{
	_x params[ "_entry", "_exit" ];
	
	[ _entry, _exit, "Enter" ] call _fnc_addAction;
	[ _exit, _entry, "Exit to" ] call _fnc_addAction;
	
}forEach _baseConnections;


//Add this to each exit/entry objects init in the editor eg.
//this setVariable[ "locationName", "Helipad" ];
//We can then use this to apply to each addAction title

 

 

  • Like 3

Share this post


Link to post
Share on other sites

Thank you Larrow! 
Yes. Entry_1 always exits to Exit_1 and Exit_1 always enters to Entry_1. 

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

×