Jump to content
Sign in to follow this  
voidbyte

Multiple AddAction's from Script

Recommended Posts

Hello, 

 

I am working on an re-usable Teleport-Script. But I can't get it to work.
Here is what it should do:

Point A should allow people to spread out to point B, C, D, E
But B, C, D, E should only allow people to return to Point A.

 

I used an Infotable as Teleport Object. 
When using the inBuild Script:
 

this addAction ["Visit the Medics", "portScript.sqf"];

and write this into the script:

_telPort =_this select 0;
_caller = _this select 1;
_caller setPos (getPos (telPo_Medic));

it works without problems.

 

So I tried to outsource the script to make it reuseable and easier to edit.
I made the same Infotable and gave it:

this addAction ["Teleport", "portScriptTest.sqf"];

and into the portScriptTest.sqf I wrote:

_telPort =_this select 0;
_caller = _this select 1;

_caller addAction ["Visit the Medics", _caller setPos (getPos (telPo_Medic))];
_caller addAction ["Visit the Basement", _caller setPos (getPos (telPo_Base))];
_caller addAction ["Visit the Airport", _caller setPos (getPos (telPo_Airport))];

...
When using the Table, I get immediately teleported to telPo_Airport. No choices no menu.
Can someone tell me what I did wrong?

  • Like 1

Share this post


Link to post
Share on other sites

Made something similar a while ago, feel free to adapt:
 

Spoiler



//GOM_fnc_fastTravelSystem V0.9 - created by Grumpy Old Man
//version as is, since it's not released or tested thoroughly
//to use it:
//travel object (flagpole or whatever): [this] call GOM_fnc_FastTravelSystem;
//[] execVM "GOM_fnc_FastTravelSystem.sqf";
//
//to add custom name to teleport:
//this setvariable ["GOM_fnc_FastTravelName","WHATEVERYOUWANT"];
//
//you can also only allow certain destinations from a teleport:
//this setvariable ["GOM_fnc_FastTravelAllowedDestinations"[teleport2,teleport4]];
//
//you can also exclude destinations:
//this setvariable ["GOM_fnc_FastTravelExcludedDestinations",[teleport3,teleport4]];
//if you want to add teleport points mid mission simply run the script again with the updated input array of teleport objects


GOM_fnc_fastTravelSystem = {


if (count _this isEqualTo 1) exitWith {
params ["_travelPoint"];
_travelArray = missionNamespace getVariable ["GOM_fnc_FastTravelArray",[]];
_travelArray pushBackUnique _travelPoint;
missionNamespace setVariable ["GOM_fnc_FastTravelArray",_travelArray,true];

};


params [["_travelCooldown",60],["_travelDurationperKM",5],["_travelMinDuration",10],["_travelArray",[]]];

_travelArray = missionNamespace getVariable ["GOM_fnc_FastTravelArray",[]];
if (_travelArray isEqualTo []) exitWith {diag_log "GOM_fnc_FastTravel: No valid travelpoints found!";systemchat "GOM_fnc_FastTravel: No valid travelpoints found!"};

{

	_ID = _x getVariable ["GOM_fnc_travelActionID",-1];
	_x removeAction _ID;

} foreach _travelArray;

{

	_travelPoint = _x;
	_allowedDestinations = _x getVariable ["GOM_fnc_FastTravelAllowedDestinations",_travelArray];
	_excludedDestinations = _x getVariable ["GOM_fnc_FastTravelExcludedDestinations",[]];
	_tempTravelArray = _travelArray - [_travelPoint];
	diag_log str _excludedDestinations;
	diag_log str _tempTravelArray;
	_tempTravelArray = _tempTravelArray - [_excludedDestinations];
	diag_log str _tempTravelArray;
	{

		_travelName = _x getvariable ["GOM_fnc_FastTravelName",""];

		_nearLocation = nearestLocation [getPosATL _x,""];

		if (_travelName isEqualTo "" AND !(text _nearLocation isEqualTo "")) then {

			_travelName = text _nearLocation;

		};

		if (_travelName isEqualTo "" AND (text _nearLocation isEqualTo "")) then {

			_travelName = format ["Point %1",(_foreachIndex) + 1];

		};

		_distance = round ((_travelPoint distance2d _x) / 1000);
		_traveltime = _distance * _travelDurationperKM;

		if (_traveltime < _travelMinDuration) then {_traveltime = _travelMinDuration};

			if (_x in _allowedDestinations AND !(_x in _excludedDestinations)) then {

				_ID = _travelPoint addAction [format ["Travel to %1 (%2km - %3s)",_travelName,_distance,_traveltime ],{

					params ["_travelPoint","_caller","_ID","_params"];
					_params params ["_travelTarget","_targetName","_traveltime","_travelCooldown"];

					_lockOut = _caller getvariable ["GOM_fnc_travelCooldown",-60];

					if (time < _lockOut) exitWith {cutText [format ["Next travel possible in %1s.",round (_lockOut - time)], "PLAIN DOWN",1];true};

					_teleport = [_caller,_travelPoint,_travelTarget,_targetName,_traveltime,_travelCooldown] spawn {

						params ["_caller","_travelPoint","_travelTarget","_targetName","_traveltime","_travelCooldown"];
						cutText [format ["You will be transported to %1 in %2 seconds.\nMove away if you wish to stay.",_targetName,_traveltime], "PLAIN DOWN",1];
						_travelPoint setvariable ['GOM_fnc_travelInProgress',true];
						playSound "click";
						_caller setvariable ["GOM_fnc_travelCooldown",time + _travelCooldown];
						sleep _traveltime;

						_hasVehicle = false;
						_vehicle = assignedVehicle _caller;

						if (!(_vehicle isEqualTo objNull) AND alive _vehicle AND _vehicle distance2D _caller < 20) then {_check = typeof assignedVehicle _caller;_hasVehicle = true;};

						if (_caller distance2D _travelPoint < 20) then {

							_safePos = getposatl _travelTarget findEmptyPosition [10,30,typeof _caller];

							if (_safePos isEqualTo []) then {

								_safePos = getposatl _travelTarget findEmptyPosition [10,150,typeof _caller];

							};

							if (_safePos isEqualTo []) then {

								_safePos = getPosATLVisual _travelTarget;

							};

						_caller setdir random 360;
						_caller allowdamage false;
						_caller setposatl _safePos;
						_caller allowdamage true;

						if (_hasVehicle) then {
						_safePos = _safePos findEmptyPosition [10,150,typeof _vehicle];
						_vehicle setdir random 360;
						_vehicle allowdamage false;
						_vehicle setposatl _safePos;
						_vehicle allowdamage true;
						};



						cutText [format ["You arrived at %1.\n%2",_targetName,selectRandom ["Enjoy your stay.","Stay safe.","Watch your step.","Grab your towel and don't panic.","Have a nice stay.","Welcome."]], "PLAIN DOWN",1];
						_travelPoint say3d "Spawn";
						sleep 5;
						_travelPoint setvariable ['GOM_fnc_travelInProgress',false];

						} else {

						cutText [format ["Transport to %1 aborted. You need to stay near the departure point.",_targetName], "PLAIN DOWN",1];

						_travelPoint say3d "click";
						sleep 5;
						_travelPoint setvariable ['GOM_fnc_travelInProgress',false];
						hint "";

						};

					};


				},[_x,_travelName,_traveltime,_travelCooldown],0,false,true,"","!(_target getvariable ['GOM_fnc_travelInProgress',false]) AND _this distance2d _target < 20"];
				_travelPoint setVariable ["GOM_fnc_travelActionID",_ID];
		};
	} foreach _tempTravelArray;


} foreach _travelArray;
true
};

[] call GOM_fnc_FastTravelSystem;


 

 

Should be straightforward and at least give some pointers on what you want to do (routing, excluding certain destinations etc).

 

Cheers

  • Like 2
  • Thanks 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
Sign in to follow this  

×