Jump to content
Sign in to follow this  
jakkob4682

Script Help: two functions in one script

Recommended Posts

Ok so I have the core function(thanks to RYD and Muzzle for the insight)

LocatePos = 
{
_pos = _this select 0;
{
	_townCenter = nearestLocation [getPos  leader _x,"CityCenter"];
	if ((!isNull _townCenter)&&(side _x==west)) then {
		_pos = _townCenter;
		};
}forEach allGroups;
_pos
};

AUTO_IED = 
{
_TC = _this select 0;
_blue = [];
{
	_locations = nearestLocations [getPos leader _x,["CityCenter"],1000];
	{
		if(side _x==west) then {
			_blue = _blue + [_x];
			};
	}forEach allGroups;

	_TC = [];
	_inTown = [];
	_iT_Count = 0;
	{
		if ((!isNull _TC)&&(side _x == west)) then {
			_TC = _locations select 0;
			_iedCount = 0;
			_inTown = nearestObjects [getPos _TC,["SoldierWB"],300];
			_iT_Count = count _inTown;
			if (iT_Count <= 4) then {
				_iedCount = _iT_Count * 3;
				}
				else
				{
					if (_iT_Count >= 5) then {
						_iedCount = _iT_Count * 2;
						};
				};
			};'
			for "_i" from 0 to _iedCount do 
			{
				_iedpos = [getMarkerPos "TC1",250 * (sqrt (random 1)),random 360] call BIS_fnc_relPos;
				_ied = createVehicle ["LAND_IED_V1_PMC",_iedpos, [], 0, "NONE"] ;
				_trig = ([getPosATL _ied, "AREA:", [5, 5, 0, false], "ACT:", ["WEST", "PRESENT", true],"STATE:",["this","deleteVehicle (thisTrigger getVariable ['ied',objNull]); createVehicle ['Sh_125_HE',getPosATL thisTrigger, [], 0, 'NONE']",""]] call CBA_fnc_createTrigger) select 0;
				_trig setVariable ["ied",_ied];
				_mrk = createMarker[format ["ied_%1",random 1000],_iedpos];
				_mrk setMarkerShape "ICON";
				_mrk setMarkerType "DOT";
			}forEach allGroups;
	}forEach allGroups;	
}forEach _blue;
_TC
};

while {true} do {
sleep 15;

The question is how do I call the core function to check whether _pos returns null? would it be _pos = call compile format ["%1",LocatePos select 0]; then do an if then with if (!isNull _pos)?

Share this post


Link to post
Share on other sites

It would only be possible to obtain a null value if you feed that function a null location when you call it? Is that actually going to happen? If not why check for a null there - check for a null before you call the function? _pos will only change if a valid location is returned from nearestLocation.

Share this post


Link to post
Share on other sites
It would only be possible to obtain a null value if you feed that function a null location when you call it? Is that actually going to happen? If not why check for a null there - check for a null before you call the function? _pos will only change if a valid location is returned from nearestLocation.

Yes but isn't _pos local to the core function? if so should I make it a global variable at the beginning of the script in order to access it from the two functions?

Share this post


Link to post
Share on other sites

That makes less sense than the 1st question - _pos is only present in 1 function there - LocatePos. If you call locatePos (it's global) you will get the value of _pos.

If you do this in your init.sqf for the above script file:

[] call compile preprocessFile "scriptName.sqf";

Then you can call locatePos from any other script with:

[_location] call locatePos;

Edited by Mattar_Tharkari

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  

×