Example Code: General Deletion: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page creation)
 
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''fn_delete.sqf''':
'''fn_delete.sqf''':
{{codecomment|/*
<sqf>
Author: Lou Montana
/*
Author: Lou Montana
Description:
 
Deletes anything that is passed to it.
Description:
Deletes anything that is passed to it.
Parameters:
 
0: OBJECT or GROUP or LOCATION or TEAM_MEMBER or ARRAY or SIDE or STRING or TASK
Parameters:
1: NUMBER or ARRAY or STRING
0: ANYTHING
1: NUMBER or ARRAY or STRING - see examples below
Returns:
 
NOTHING or NUMBER or BOOLEAN
Returns:
NOTHING
ANYTHING (false in case of a bad parameter, e.g null or number)
NUMBER - deleteAt result
 
BOOLEAN - false in case of null argument or no case met
Examples:
cursorObject   call LM_fnc_delete
Examples:
group player   call LM_fnc_delete
cursorObject call LM_fnc_delete
myLocation    call LM_fnc_delete
group player call LM_fnc_delete
myScriptHandle call LM_fnc_delete
[units group player] call LM_fnc_delete
myTeamMember  call LM_fnc_delete
[<nowiki/>["mark1", "mark2", "mark3"]] call LM_fnc_delete
myControl      call LM_fnc_delete
waypoints group player select 3 call LM_fnc_delete
myDisplay      call LM_fnc_delete
[myArray, 3] call LM_fnc_delete // myArray [[deleteAt]] 3
mySimpleTask  call LM_fnc_delete
[myArray, [0, 3]] call LM_fnc_delete // myArray [[deleteRange]] [0, 3]
"myMarker"    call LM_fnc_delete
*/}}
[myDisplay, 1] call LM_fnc_delete // display + errorCode
["myMarker", "local"]             call LM_fnc_delete // uses deleteMarkerLocal
[[params]] [
["myIdentity", "identity"]        call LM_fnc_delete // uses deleteIdentity
["_argument", [[objNull]], [objNull, [[grpNull]], [[locationNull]], [[teamMemberNull]], [], ""]],
["myCustomStatus", "status"]      call LM_fnc_delete // uses deleteStatus
["_parameter", "", [0, [], ""]]
["myFrameworkTaskId", "task"]     call LM_fnc_delete // uses BIS_fnc_deleteTask
];
[units group player]             call LM_fnc_delete // USE [] for arrays!
[waypoints group player select 3] call LM_fnc_delete // waypoint - USE [] as a waypoint is an array
[[if]] ([[isNull]] _argument) [[exitWith]] { [[false]] };
[group player, 3]                call LM_fnc_delete // waypoint as well
[[if]] (_argument [[isEqualType]] [[objNull]]) [[exitWith]] {{cc|...the main reason this function was written}}
blufor            call LM_fnc_delete // deletes all the blufor units (keeping the side centre)
{
[blufor, "center"] call LM_fnc_delete // deletes the side centre
[[if]] ([[vehicle]] _x [[a == b|==]] _x) [[then]]
[myArray, 3]       call LM_fnc_delete // myArray deleteAt 3
{
[myArray, [0, 3]] call LM_fnc_delete // myArray deleteRange [0, 3]
[[private]] _[[vehicle]] [[a = b|=]] _x;
[[group player, "myMarker", blufor, myScriptHandle]] call LM_fnc_delete // everything can be mixed together
[[if]] [[! a|!]]([[crew]] _x [[isEqualTo]] []) [[then]]
*/
{
 
{ _[[vehicle]] [[deleteVehicleCrew]] _x } [[forEach]] [[crew]] _x;
params [
};
"_argument",
[[deleteVehicle]] _x;
["_parameter", {}, [0, [], ""]]
} [[else]] {
];
[[objectParent]] _x [[deleteVehicleCrew]] _x;
 
};
if (isNil "_argument" ||
};
{
_argument in [objNull, grpNull, controlNull, displayNull, locationNull, scriptNull, taskNull, teamMemberNull] ||
[[if]] (_argument [[isEqualType]] [[locationNull]])   [[exitWith]] { [[deleteLocation]] _argument };
{ _argument isEqualTypeAny [0, {}, configNull, missionNamespace] }
[[if]] (_argument [[isEqualType]] [[teamMemberNull]]) [[exitWith]] { [[deleteTeam]] _argument };
}
[[if]] (_argument [[isEqualType]] []) [[exitWith]]
) exitWith { false };
{
 
_argument [[params]] ["_item0", "_item1"];
if (_argument isEqualType objNull) exitWith // ...the initial reason this function was written
[[if]] (_item1 [[isEqualType]] 0 [[a && b|&&]] _item0 [[isEqualType]] [[grpNull]]) [[exitWith]] { [[deleteWaypoint]] [_item0, _item1] };
{
[[if]] (_item1 [[isEqualType]] 0 [[a && b|&&]] _item0 [[isEqualType]] [])     [[exitWith]] { _item0 [[deleteAt]] _item1 };
if (vehicle _argument == _argument) then
[[if]] (_item1 [[isEqualType]] [] [[a && b|&&]] { [[count]] _item1 [[a greater b|>]] 1 [[a && b|&&]] _item1 [[isEqualTypeAll]] 0 }) [[exitWith]]
{
{
if (crew _argument isNotEqualTo []) then
_item1 [[params]] ["_from", "_range"];
{
_item0 [[deleteRange]] [_from, _range];
{ _argument deleteVehicleCrew _x } forEach crew _argument;
};
};
{ _x [[call]] LM_fnc_delete } [[forEach]] _argument;
private _vehicleCargo = getVehicleCargo _argument;
};
if (_vehicleCargo isNotEqualTo []) then
[[if]] (_argument [[isEqualType]] "") [[exitWith]]
{
{
[_vehicleCargo] call LM_fnc_delete;
[[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "identity" }) [[exitWith]] { [[deleteIdentity]] _argument };
};
[[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "status"  }) [[exitWith]] { [[deleteStatus]] _argument };
deleteVehicle _argument;
[[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "task"    }) [[exitWith]] { [_argument, [[allUnits]] [[+]] [[allDeadMen]]] [[call]] [[BIS_fnc_deleteTask]] };
} else {
[[if]] (_parameter [[isEqualType]] "" [[a && b|&&]] { _parameter [[a == b|==]] "local"   }) [[exitWith]] { [[deleteMarkerLocal]] _argument };
objectParent _argument deleteVehicleCrew _argument;
[[deleteMarker]] _argument;
};
};
};
[[if]] (_argument [[isEqualType]] [[grpNull]]) [[exitWith]]
if (_argument isEqualType grpNull) exitWith
{
{
[[if]] (_parameter [[isEqualType]] 0) [[exitWith]] { [[deleteWaypoint]] [_argument, _parameter] };
if (!isNil "_parameter" && { _parameter isEqualType 0 }) exitWith { deleteWaypoint [_argument, _parameter] };
[[units]] _argument [[call]] LM_fnc_delete;
[units _argument] call LM_fnc_delete;
[[deleteGroup]] _argument;
deleteGroup _argument;
};
};
[[if]] (_argument [[isEqualType]] [[blufor]]) [[exitWith]] { [[deleteCenter]] _argument };
if (_argument isEqualType []) exitWith
[[if]] (_argument [[isEqualType]] [[taskNull]] [[a && b|&&]] _parameter [[isEqualType]] [[objNull]]) [[exitWith]] { _parameter [[removeSimpleTask]] _argument };
{
private _mustExit = false;
[[false]];
if (!isNil "_parameter") then
{
if (_parameter isEqualType 0) exitWith { _mustExit = true; _argument deleteAt _parameter };
if (_parameter isEqualType [] && { count _item1 > 1 && _item1 isEqualTypeAll 0 }) exitWith
{
_mustExit = true;
_parameter params ["_from", "_range"];
_argument 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;
</sqf>




[[Category:Example Code]]
[[Category:Example Code]]

Latest revision as of 23:28, 14 July 2022

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 [myDisplay, 1] call LM_fnc_delete // display + errorCode ["myMarker", "local"] call LM_fnc_delete // uses deleteMarkerLocal ["myIdentity", "identity"] call LM_fnc_delete // uses deleteIdentity ["myCustomStatus", "status"] call LM_fnc_delete // uses deleteStatus ["myFrameworkTaskId", "task"] call LM_fnc_delete // uses BIS_fnc_deleteTask [units group player] call LM_fnc_delete // USE [] for arrays! [waypoints group player select 3] call LM_fnc_delete // waypoint - USE [] as a waypoint is an array [group player, 3] call LM_fnc_delete // waypoint as well blufor call LM_fnc_delete // deletes all the blufor units (keeping the side centre) [blufor, "center"] call LM_fnc_delete // deletes the side centre [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 together */ params [ "_argument", ["_parameter", {}, [0, [], ""]] ]; if (isNil "_argument" || { _argument in [objNull, grpNull, controlNull, displayNull, locationNull, scriptNull, taskNull, teamMemberNull] || { _argument isEqualTypeAny [0, {}, configNull, missionNamespace] } } ) exitWith { false }; if (_argument isEqualType objNull) exitWith // ...the initial reason this function was written { if (vehicle _argument == _argument) then { if (crew _argument isNotEqualTo []) then { { _argument deleteVehicleCrew _x } forEach crew _argument; }; private _vehicleCargo = getVehicleCargo _argument; if (_vehicleCargo isNotEqualTo []) then { [_vehicleCargo] call LM_fnc_delete; }; 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 { private _mustExit = false; if (!isNil "_parameter") then { if (_parameter isEqualType 0) exitWith { _mustExit = true; _argument deleteAt _parameter }; if (_parameter isEqualType [] && { count _item1 > 1 && _item1 isEqualTypeAll 0 }) exitWith { _mustExit = true; _parameter params ["_from", "_range"]; _argument 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;