Skip to content

Instantly share code, notes, and snippets.

View commy2's full-sized avatar

commy2

View GitHub Profile
@commy2
commy2 / param.md
Last active November 11, 2017 10:56

Why you should use "param" more often.

####The basics of "param"

param and the related, but not to be confused with, params command are fairly new additions to the Arma 3 SQF library (- they came with v1.48).
While it feels to me like params is rightfully catching up in usage in the Arma scripting community, replacing ugly and slow _this select N constructions that take up multiple lines and are tiring to look at, param is still largely ignored.

param was introduced during the initiative to replace common BI functions (here: BIS_fnc_param) with native SQF commands, in an effort to increase code performance and readability.
Other notable examples are sort (v1.44), arrayIntersect (v1.48), remoteExec(Call) (v1.50) and the new "conditional select" select CODE (v1.56)

if (!isServer) exitWith {};
PZG_EnableSound = true;
params ["_logic"];
private _allSounds = [
["A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions1.wss", 20],
["A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions2.wss", 23],
/* -------------------------------------------
Macro: NS_NULL
Description:
Returns a undefined (null) CBA namespace.
Parameters:
None
Example:
//init.sqf
My_fnc_addCustomUniform = {
params [["_unit", objNull, [objNull]], ["_uniform", "", [""]], ["_texture", "", [""]]];
_unit addUniform _uniform;
if (_texture != "") then {
_unit setObjectTextureGlobal [0, _texture];
(uniformContainer _unit) setVariable ["custom_texture", _texture, true];
// by commy2
params ["_group", "_position"];
private _index = currentWaypoint _group;
_group enableAttack false;
private _units = units _group;
private _staticWeapons = _position nearObjects ["StaticWeapon", 50] select {_x emptyPositions "gunner" > 0};
private _buildings = (_position nearObjects ["Building", 50]) apply {_x buildingPos -1} select {count _x > 0};
ID1 = player addEventHandler ["fired", {
systemChat str 1;
player removeEventHandler ["fired", ID1];
}];
player addEventHandler ["fired", {
systemChat str 2;
}];
private _e = [];
private _c = "true" configClasses (configFile >> "CfgVehicles");
{
private _ce = "true" configClasses (_x >> "DestructionEffects") apply {toLower getText (_x >> "type")} select {(_x find "\") isEqualTo -1};
_e append _ce;
_e = _e arrayIntersect _e;
} forEach _c;
_r = configFile >> "CfgWeapons" >> "ItemInfo";
_w = "true" configClasses (configFile >> "CfgWeapons");
_w = _w select {inheritsFrom (_x >> "ItemInfo") == _r} apply {configName _x};
copyToClipBoard str _w;
CBA_fnc_findLoadableWeapon = {//
params [["_unit", objNull, [objNull]], ["_magazine", "", [""]]];
_magazine = toLower _magazine;
private _weaponsMagazines = [
[primaryWeapon _unit, primaryWeaponMagazine _unit],
[handgunWeapon _unit, handgunMagazine _unit],
[secondaryWeapon _unit, secondaryWeaponMagazine _unit],
=====================================================================
== C:\Program Files (x86)\Steam\steamapps\common\Arma 3\arma3.exe
== "C:\Program Files (x86)\Steam\steamapps\common\Arma 3\arma3.exe" "-mod=C:\Program Files (x86)\Steam\steamapps\common\Arma 3\!Workshop\@CBA_A3;C:\Program Files (x86)\Steam\steamapps\common\Arma 3\!Workshop\@ace"
Original output filename: Arma3Retail_DX11
Exe timestamp: 2016/09/21 16:15:19
Current time: 2016/10/03 23:43:12
Type: Public
Build: Stable