Example Code: General Deletion: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Fix³)
(Update)
Line 7: Line 7:
   
   
  Parameters:
  Parameters:
  0: OBJECT or GROUP or LOCATION or TEAM_MEMBER or ARRAY or SIDE or STRING or TASK
  0: ANYTHING
  1: NUMBER or ARRAY or STRING
  1: NUMBER or ARRAY or STRING - see examples below
   
   
  Returns:
  Returns:
  ANYTHING
  ANYTHING (false in case of a bad parameter, e.g null or number)
   
   
  Examples:
  Examples:
  cursorObject call LM_fnc_delete
  cursorObject   call LM_fnc_delete
  group player call LM_fnc_delete
  group player   call LM_fnc_delete
  [units group player] call LM_fnc_delete
myLocation    call LM_fnc_delete
  [<nowiki/>["mark1", "mark2", "mark3"]] call LM_fnc_delete
myScriptHandle call LM_fnc_delete
myTeamMember  call LM_fnc_delete
myControl      call LM_fnc_delete
myDisplay      call LM_fnc_delete
mySimpleTask  call LM_fnc_delete
"myMarker"    call LM_fnc_delete
  [myControl, 1] call LM_fnc_delete
["myMarker", "local"]           call LM_fnc_delete
  ["myIdentity", "identity"]      call LM_fnc_delete
["myCustomStatus", "status"]    call LM_fnc_delete
["myFrameworkTaskId", "task"]   call LM_fnc_delete
[units group player]           call LM_fnc_delete
  waypoints group player select 3 call LM_fnc_delete
  waypoints group player select 3 call LM_fnc_delete
  [myArray, 3] call LM_fnc_delete // myArray [[deleteAt]] 3
[group player, 3]              call LM_fnc_delete // waypoint as well
  [myArray, [0, 3]] call LM_fnc_delete // myArray [[deleteRange]] [0, 3]
[blufor]          call LM_fnc_delete // deletes all the blufor units
[blufor, "center"] call LM_fnc_delete // deletes the side center
  [myArray, 3]       call LM_fnc_delete // myArray [[deleteAt]] 3
  [myArray, [0, 3]] call LM_fnc_delete // myArray [[deleteRange]] [0, 3]
[<nowiki/>[group player, "myMarker", blufor, myScriptHandle]] call LM_fnc_delete // everything can be mixed
  */}}
  */}}
   
   
  [[params]] [
  [[params]] [
  ["_argument", [[objNull]], [<nowiki/>[[objNull]], [[grpNull]], [[locationNull]], [[teamMemberNull]], [], ""]],
  "_argument",
["_parameter", "", [0, [], ""]]
["_parameter", [[objNull]], [0, [], ""]]
  ];
  ];
   
   
  [[if]] (!(_argument [[isEqualType]] [] [[a or b|<nowiki/>||]] _argument [[isEqualType]] "") [[a && b|&&]] { [[isNull]] _argument }) [[exitWith]] { [[false]] };
  [[if]] ([[isNil]] "_argument") [[exitWith]] { [[false]] };
[[if]] (
_argument [[isEqualTo]] [[objNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualTo]] [[grpNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualTo]] [[controlNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualTo]] [[displayNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualTo]] [[locationNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualTo]] [[scriptNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualTo]] [[teamMemberNull]] [[a or b|<nowiki/>||]] {{cc|[[isNull]] exception}}
_argument [[isEqualTo]] [[taskNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualType]] 0 [[a or b|<nowiki/>||]]
_argument [[isEqualType]] {} [[a or b|<nowiki/>||]]
_argument [[isEqualType]] [[configNull]] [[a or b|<nowiki/>||]]
_argument [[isEqualType]] [[missionNamespace]]
) [[exitWith]] { [[false]] };
  [[if]] (_argument [[isEqualType]] [[objNull]]) [[exitWith]] {{cc|...the initial reason this function was written}}
  [[if]] (_argument [[isEqualType]] [[objNull]]) [[exitWith]] {{cc|...the initial reason this function was written}}
  {
  {
  [[if]] ([[vehicle]] _argument [[a == b|==]] _argument) [[then]]
  [[if]] ([[vehicle]] _argument [[a == b|==]] _argument) [[then]]
  {
  {
[[private]] _[[vehicle]] [[a = b|=]] _argument;
  [[if]] [[! a|!]]([[crew]] _argument [[isEqualTo]] []) [[then]]
  [[if]] [[! a|!]]([[crew]] _argument [[isEqualTo]] []) [[then]]
  {
  {
Line 43: Line 72:
  };
  };
  };
  };
  [[if]] (_argument [[isEqualType]] [[grpNull]]) [[exitWith]]
  [[if]] (_argument [[isEqualType]] [[locationNull]])   [[exitWith]] { [[deleteLocation]] _argument };
{
[[if]] (_argument [[isEqualType]] [[teamMemberNull]]) [[exitWith]] { [[deleteTeam]] _argument };
[[if]] (![[isNil]] "_parameter" [[a && b|&&]] { _parameter [[isEqualType]] 0 }) [[exitWith]] { [[deleteWaypoint]] [_argument, _parameter] };
[[[units]] _argument] [[call]] LM_fnc_delete;
[[deleteGroup]] _argument;
};
  [[if]] (_argument [[isEqualType]] []) [[exitWith]]
  [[if]] (_argument [[isEqualType]] []) [[exitWith]]
  {
  {
  _argument [[params]] ["_item0", "_item1"];
  _argument [[params]] ["_item0", "_item1"];
  [[if]] (_item1 [[isEqualType]] 0 [[a && b|&&]] _item0 [[isEqualType]] [[grpNull]]) [[exitWith]] { [[deleteWaypoint]] [_item0, _item1] };
  [[private]] _mustExit [[a = b|=]] [[false]];
  [[if]] (_item1 [[isEqualType]] 0 [[a && b|&&]] _item0 [[isEqualType]] [])      [[exitWith]] { _item0 [[deleteAt]] _item1 };
  [[if]] (![[isNil]] "_item0" [[a && b|&&]] [[! a|!]][[isNil]] "_item1") [[then]]
[[if]] (_item1 [[isEqualType]] [] [[a && b|&&]] { [[count]] _item1 [[a greater b|>]] 1 [[a && b|&&]] _item1 [[isEqualTypeAll]] 0 }) [[exitWith]]
  {
  {
  _item1 [[params]] ["_from", "_range"];
  [[if]] (_item1 [[isEqualType]] 0) [[then]]
_item0 [[deleteRange]] [_from, _range];
{
[[if]] (_item0 [[isEqualType]] [[grpNull]]) [[exitWith]] { _mustExit [[a = b|=]] [[true]]; [[deleteWaypoint]] [_item0, _item1] };
[[if]] (_item0 [[isEqualType]] [])      [[exitWith]] { _mustExit [[a = b|=]] [[true]]; _item0 [[deleteAt]] _item1 };
};
[[if]] (_item1 [[isEqualType]] [] [[a && b|&&]] { [[count]] _item1 [[a greater b|>]] 1 [[a && b|&&]] _item1 [[isEqualTypeAll]] 0 }) [[exitWith]]
{
_item1 [[params]] ["_from", "_range"];
_item0 [[deleteRange]] [_from, _range];
};
  };
  };
  { _x [[call]] LM_fnc_delete } [[forEach]] _argument;
  [[if]] (_mustExit) [[exitWith]] {};
{ [_x] [[call]] LM_fnc_delete } [[forEach]] _argument;
  };
  };
  [[if]] (_argument [[isEqualType]] "") [[exitWith]]
  [[if]] (_argument [[isEqualType]] "") [[exitWith]]
  {
  {
  [[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "identity" }) [[exitWith]] { [[deleteIdentity]] _argument };
[[private]] _mustExit [[a = b|=]] [[false]];
[[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "status"  }) [[exitWith]] { [[deleteStatus]] _argument };
  [[if]] (![[isNil]] "_parameter" [[a && b|&&]] { _parameter [[isEqualType]] "" }) [[then]]
[[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "task"    }) [[exitWith]] { [_argument, [[allUnits]] [[+]] [[allDeadMen]]] [[call]] [[BIS_fnc_deleteTask]] };
{
[[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "local"    }) [[exitWith]] { [[deleteMarkerLocal]] _argument };
[[if]] (_parameter [[a == b|==]] "identity") [[exitWith]] { _mustExit [[a = b|=]] [[true]]; [[deleteIdentity]] _argument };
[[if]] (_parameter [[a == b|==]] "status"[[exitWith]] { _mustExit [[a = b|=]] [[true]]; [[deleteStatus]] _argument };
[[if]] (_parameter [[a == b|==]] "local")    [[exitWith]] { _mustExit [[a = b|=]] [[true]]; [[deleteMarkerLocal]] _argument };
[[if]] (_parameter [[a == b|==]] "task")     [[exitWith]]
{
_mustExit [[a = b|=]] [[true]];
[_argument, [[allUnits]] [[+]] [[allDeadMen]] [[+]] [blufor, [[opfor]], [[independent]], [[civilian]]]] [[call]] [[BIS_fnc_deleteTask]];
};
};
[[if]] (_mustExit) [[exitWith]] {};
  [[deleteMarker]] _argument;
  [[deleteMarker]] _argument;
  };
  };
  [[if]] (_argument [[isEqualType]] [[grpNull]]) [[exitWith]]
  [[if]] (_argument [[isEqualType]] [[scriptNull]])    [[exitWith]] { [[terminate]] _argument };
[[if]] (_argument [[isEqualType]] [[locationNull]])  [[exitWith]] { [[deleteLocation]] _argument };
[[if]] (_argument [[isEqualType]] [[blufor]])        [[exitWith]]
{
[[if]] (![[isNil]] "_parameter" [[a && b|&&]] { _parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "center" } }) [[then]]
{
[[deleteCenter]] _argument;
} [[else]] {
[[[allGroups]] [[select]] { [[side]] _x [[a == b|==]] _argument }] [[call]] LM_fnc_delete;
};
};
[[if]] (_argument [[isEqualType]] [[controlNull]]) [[exitWith]] { [[ctrlDelete]] _argument };
[[if]] (_argument [[isEqualType]] [[displayNull]]) [[exitWith]]
  {
  {
  [[if]] (_parameter [[isEqualType]] 0) [[exitWith]] { [[deleteWaypoint]] [_argument, _parameter] };
  [[private]] _exitCode [[a = b|=]] 0;
[<nowiki/>[[units]] _argument] [[call]] LM_fnc_delete;
[[if]] (![[isNil]] "_parameter" [[a && b|&&]] { _parameter [[isEqualType]] 0 }) [[then]] { _exitCode [[a = b|=]] _parameter };
  [[deleteGroup]] _argument;
  _argument [[closeDisplay]] _exitCode;
  };
  };
[[if]] (_argument [[isEqualType]] [[blufor]]) [[exitWith]] { [[deleteCenter]] _argument };
  [[if]] (_argument [[isEqualType]] [[taskNull]] [[a && b|&&]] _parameter [[isEqualType]] [[objNull]]) [[exitWith]] { _parameter [[removeSimpleTask]] _argument };
  [[if]] (_argument [[isEqualType]] [[taskNull]] [[a && b|&&]] _parameter [[isEqualType]] [[objNull]]) [[exitWith]] { _parameter [[removeSimpleTask]] _argument };
[[if]] (_argument [[isEqualType]] [[teamMemberNull]]) [[exitWith]] { [[deleteTeam]] _argument };
   
   
  [[false]];
  [[false]];

Revision as of 21:42, 8 November 2020

fn_delete.sqf:

/*
	Author: Lou Montana

	Description:
		Deletes anything that is passed to it.

	Parameters:
		0: ANYTHING
		1: NUMBER or ARRAY or STRING - see examples below

	Returns:
		ANYTHING (false in case of a bad parameter, e.g null or number)

	Examples:
		cursorObject   call LM_fnc_delete
		group player   call LM_fnc_delete
		myLocation     call LM_fnc_delete
		myScriptHandle call LM_fnc_delete
		myTeamMember   call LM_fnc_delete
		myControl      call LM_fnc_delete
		myDisplay      call LM_fnc_delete
		mySimpleTask   call LM_fnc_delete
		"myMarker"     call LM_fnc_delete
		[myControl, 1] call LM_fnc_delete
		["myMarker", "local"]           call LM_fnc_delete
		["myIdentity", "identity"]      call LM_fnc_delete
		["myCustomStatus", "status"]    call LM_fnc_delete
		["myFrameworkTaskId", "task"]   call LM_fnc_delete
		[units group player]            call LM_fnc_delete
		waypoints group player select 3 call LM_fnc_delete
		[group player, 3]               call LM_fnc_delete // waypoint as well
		[blufor]           call LM_fnc_delete // deletes all the blufor units
		[blufor, "center"] call LM_fnc_delete // deletes the side center
		[myArray, 3]       call LM_fnc_delete // myArray deleteAt 3
		[myArray, [0, 3]]  call LM_fnc_delete // myArray deleteRange [0, 3]
		[[group player, "myMarker", blufor, myScriptHandle]] call LM_fnc_delete // everything can be mixed
*/

params [
	"_argument",
	["_parameter", objNull, [0, [], ""]]
];

if (isNil "_argument") exitWith { false };
if (
	_argument isEqualTo objNull ||
	_argument isEqualTo grpNull ||
	_argument isEqualTo controlNull ||
	_argument isEqualTo displayNull ||
	_argument isEqualTo locationNull ||
	_argument isEqualTo scriptNull ||
	_argument isEqualTo teamMemberNull || // isNull exception
	_argument isEqualTo taskNull ||
	_argument isEqualType 0 ||
	_argument isEqualType {} ||
	_argument isEqualType configNull ||
	_argument isEqualType missionNamespace
) exitWith { false };

if (_argument isEqualType objNull) exitWith // ...the initial reason this function was written
{
	if (vehicle _argument == _argument) then
	{
		if !(crew _argument isEqualTo []) then
		{
			{ _argument deleteVehicleCrew _x } forEach crew _argument;
		};
		deleteVehicle _argument;
	} else {
		objectParent _argument deleteVehicleCrew _argument;
	};
};
if (_argument isEqualType grpNull) exitWith
{
	if (!isNil "_parameter" && { _parameter isEqualType 0 }) exitWith { deleteWaypoint [_argument, _parameter] };
	[[[units]] _argument] call LM_fnc_delete;
	deleteGroup _argument;
};
if (_argument isEqualType []) exitWith
{
	_argument params ["_item0", "_item1"];
	private _mustExit = false;
	if (!isNil "_item0" && !isNil "_item1") then
	{
		if (_item1 isEqualType 0) then
		{
			if (_item0 isEqualType grpNull) exitWith { _mustExit = true; deleteWaypoint [_item0, _item1] };
			if (_item0 isEqualType [])      exitWith { _mustExit = true; _item0 deleteAt _item1 };
		};
		if (_item1 isEqualType [] && { count _item1 > 1 && _item1 isEqualTypeAll 0 }) exitWith
		{
			_item1 params ["_from", "_range"];
			_item0 deleteRange [_from, _range];
		};
	};
	if (_mustExit) exitWith {};
	{ [_x] call LM_fnc_delete } forEach _argument;
};
if (_argument isEqualType "") exitWith
{
	private _mustExit = false;
	if (!isNil "_parameter" && { _parameter isEqualType "" }) then
	{
		if (_parameter == "identity") exitWith { _mustExit = true; deleteIdentity _argument };
		if (_parameter == "status")   exitWith { _mustExit = true; deleteStatus _argument };
		if (_parameter == "local")    exitWith { _mustExit = true; deleteMarkerLocal _argument };
		if (_parameter == "task")     exitWith
		{
			_mustExit = true;
			[_argument, allUnits + allDeadMen + [blufor, opfor, independent, civilian]] call BIS_fnc_deleteTask;
		};
	};
	if (_mustExit) exitWith {};
	deleteMarker _argument;
};
if (_argument isEqualType scriptNull)     exitWith { terminate _argument };
if (_argument isEqualType locationNull)   exitWith { deleteLocation _argument };
if (_argument isEqualType blufor)         exitWith
{
	if (!isNil "_parameter" && { _parameter isEqualType "" && { _parameter == "center" } }) then
	{
		deleteCenter _argument;
	} else {
		[[[allGroups]] select { side _x == _argument }] call LM_fnc_delete;
	};
};
if (_argument isEqualType controlNull) exitWith { ctrlDelete _argument };
if (_argument isEqualType displayNull) exitWith
{
	private _exitCode = 0;
	if (!isNil "_parameter" && { _parameter isEqualType 0 }) then { _exitCode = _parameter };
	_argument closeDisplay _exitCode;
};
if (_argument isEqualType taskNull && _parameter isEqualType objNull) exitWith { _parameter removeSimpleTask _argument };
if (_argument isEqualType teamMemberNull) exitWith { deleteTeam _argument };

false;