Defining a global variable in Arma 3 is simple… use this one is for defining the max radius of a battle zone.
Declare it at the initial phase of your mission scripting like this.
missionNamespace setVariable ['PARAMS_AOSize',1000,FALSE]; // Radius of main AO. |
Then it may be used where ever the value is required for a script.
_randomPos = [Loc, 0, PARAMS_AOSize, 5, 0, 0.4, 0, [], Loc] call BIS_fnc_findSafePos; |
This means that you do not need to type a value over and over again, that would be a pain if it needed to be changed, this allows the user to define it once and then have the variable everywhere else.
Just like this example, I am using the variable to define the size of an area to search for a position.
_grp1 = createGroup east; private _CarAmount = 1; for "_i" from 1 to 3 do { private ["_car", "_turret"]; _randomPos = [Loc, 0, PARAMS_AOSize, 5, 0, 0.4, 0, [], Loc] call BIS_fnc_findSafePos; _vehicleType = selectRandom ["LOP_BH_Landrover_M2","LOP_BH_Landrover_SPG9", "LOP_BH_Nissan_PKM", "LOP_BH_Offroad_M2","rhsgref_ins_uaz_spg9", "rhsgref_ins_uaz_dshkm","rhsgref_ins_uaz_ags", "rhs_tigr_sts_3camo_msv","O_Truck_03_transport_F"]; _grp1 = createGroup east; switch (_vehicleType) do { case "rhs_kamaz5350_flatbed_msv": { _turretType = selectRandom ["rhs_KORD_high_MSV", "rhsgref_ins_DSHKM","rhsgref_ins_SPG9M", "rhsgref_ins_Igla_AA_pod","rhs_Kornet_9M133_2_vdv"]; _car = createVehicle [_vehicleType, _randomPos, [], 5, "NONE"]; _turret = createVehicle [_turretType, _randomPos, [], 5, "NONE"]; _car setDir 0; _turret attachTo [_car,[0,-3.4,0.6]]; _turret setDir 180; createvehiclecrew _car; (crew _car) join _grp1; createvehiclecrew _turret; (crew _turret) join _grp1; _turret lock 3; _turret allowCrewInImmobile true; }; default { _car = createVehicle [_vehicleType, _randomPos, [], 5, "NONE"]; createvehiclecrew _car; (crew _car) join _grp1; }; }; _grp1 setGroupIdGlobal [format ['AO-MRAP/Car-%1', _CarAmount]]; _CarAmount = _CarAmount + 1; _car lock 3; _car allowCrewInImmobile true; [_grp1, Loc, 600] call BIS_fnc_taskPatrol; sleep 0.621; }; |
This is a better way to program an Arma 3 mission than just having the numbers everywhere. And if a certain value is changed by a script,
you can use a variable to store the old value if you need to change it back later with setVariable.
Like this, getting the number plate of a vehicle in Arma 3, and storing the value in a variable.
missionNamespace setVariable ['LicensePlate',getPlateNumber (_this select 2),FALSE]; |
Then setting it back after we are done with the vehicle.
(_this select 2) setPlateNumber LicensePlate; |
This is a very powerful part of scripting in Arma 3. This allows communicating values from one script to another. A script variable that starts with an underscore like this: _car is only visible in the script using it. But a variable without this is always visible.
One last trick, get the player`s height above sea level.
cuttext format[" Your current height: %1",(getPosASL player) select 2]; |