mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
more common code cleanup
This commit is contained in:
parent
4c4785c140
commit
e8ebe87450
@ -179,6 +179,7 @@ PREP(toBitmask);
|
||||
PREP(toHex);
|
||||
PREP(toNumber);
|
||||
PREP(unhideUnit);
|
||||
PREP(uniqueElements);
|
||||
PREP(uniqueElementsOnly);
|
||||
PREP(unloadPerson);
|
||||
PREP(unloadPersonLocal);
|
||||
|
@ -11,6 +11,8 @@
|
||||
* None
|
||||
*
|
||||
* Public: Yes
|
||||
*
|
||||
* Note: uses player
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: commy2
|
||||
*
|
||||
* Sets the name variable of the object. Used to prevent issues with the name command.
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: esteldunedain
|
||||
*
|
||||
* Sets the value of an ACE_Parameter and makes it public.
|
||||
*
|
||||
* Arguments:
|
||||
@ -12,7 +11,7 @@
|
||||
*
|
||||
* Public: Yes
|
||||
*
|
||||
* Deprecated *@todo commy
|
||||
* Deprecated
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: commy2
|
||||
*
|
||||
* Sets a public object namespace variable that gets reset with the same value after respawn, so JIP clients keep the value.
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: commy2 and joko // Jonas
|
||||
*
|
||||
* Sets a public variable, but wait a certain amount of ACE_time to transfer the value over the network. Changing the value by calling this function again resets the windup timer.
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* ? deprecated
|
||||
* ?
|
||||
*
|
||||
* Arguments:
|
||||
* ?
|
||||
|
@ -1,35 +1,41 @@
|
||||
/**
|
||||
* fn_stringCompare.sqf
|
||||
* @Descr: Determines whether one string matches another and how many characters match. Case insensitive.
|
||||
* @Author: bovine3dom
|
||||
/*
|
||||
* Author: bovine3dom
|
||||
* Determines whether one string matches another and how many characters match. Case insensitive.
|
||||
*
|
||||
* @Arguments: [stringA STRING, stringB STRING]
|
||||
* @Return: NUMBER Number of matching characters
|
||||
* @PublicAPI: true
|
||||
* Arguments:
|
||||
* 0: stringA <STRING>
|
||||
* 1: stringB <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* Number of matching characters >NUMBER>
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_searchTerm", "_string", "_arraySearchTerm", "_arrayString", "_sizeSearchTerm", "_sizeString", "_matchingCharacters", "_searchIterator", "_targetIterator"];
|
||||
_string = toLower (_this select 0); // removes case sensitivity
|
||||
_searchTerm = toLower (_this select 1);
|
||||
params ["_string", "_searchTerm"];
|
||||
|
||||
_string = toLower _string; // removes case sensitivity
|
||||
_searchTerm = toLower _searchTerm;
|
||||
|
||||
private ["_arraySearchTerm", "_arrayString", "_sizeSearchTerm", "_sizeString", "_matchingCharacters", "_searchIterator", "_targetIterator"];
|
||||
|
||||
_arraySearchTerm = toArray _searchTerm; // splits string into array of unicode decimals
|
||||
_arrayString = toArray _string;
|
||||
_sizeSearchTerm = count _arraySearchTerm; // We only measure the array once
|
||||
_sizeString = count _arrayString;
|
||||
|
||||
|
||||
_matchingCharacters = 0;
|
||||
_targetIterator = 0;
|
||||
_searchIterator = 0;
|
||||
while {(_searchIterator < _sizeSearchTerm) && (_targetIterator < _sizeString)} do { // Prevents us from going out of bounds
|
||||
if ((_arraySearchTerm select _searchIterator) == (_arrayString select _targetIterator)) then { // If we have a match, start looking for the next character in the search term
|
||||
_targetIterator = 0;
|
||||
|
||||
while {_searchIterator < _sizeSearchTerm && _targetIterator < _sizeString} do { // Prevents us from going out of bounds
|
||||
if (_arraySearchTerm select _searchIterator == _arrayString select _targetIterator) then { // If we have a match, start looking for the next character in the search term
|
||||
_matchingCharacters = _matchingCharacters + 1;
|
||||
_searchIterator = _searchIterator + 1
|
||||
};
|
||||
|
||||
_targetIterator = _targetIterator + 1; // Look at the next character in the string
|
||||
};
|
||||
|
||||
_matchingCharacters
|
||||
_matchingCharacters
|
||||
|
@ -10,17 +10,9 @@
|
||||
* copy of string <STRING>
|
||||
*
|
||||
* Public: Yes
|
||||
*
|
||||
* Deprecated
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_string", ""];
|
||||
params ["_string"];
|
||||
|
||||
private ["_charArray", "_returnString"];
|
||||
|
||||
_charArray = toArray _string;
|
||||
_charArray = _charArray - [((toArray " ") select 0)];
|
||||
_returnString = toString _charArray;
|
||||
|
||||
_returnString
|
||||
(_string splitString " ") joinString ""
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: commy2
|
||||
*
|
||||
* Create a centered, colored text.
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,33 +1,27 @@
|
||||
/*
|
||||
* Author: jaynus
|
||||
*
|
||||
* Call and propegate a synced event
|
||||
*
|
||||
* Argument:
|
||||
* 0: Name (String)
|
||||
* 1: Arguments (Array)
|
||||
* 2: TTL (Number or Code) [Optional] for this specific event call
|
||||
* Arguments:
|
||||
* 0: Name <STRING>
|
||||
* 1: Arguments <ARRAY>
|
||||
* 2: TTL <NUMBER, CODE> [Optional] for this specific event call
|
||||
*
|
||||
* Return value:
|
||||
* Boolean of success
|
||||
* Return Value:
|
||||
* Boolean of success <BOOL>
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
//#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_2(_name,_args);
|
||||
params ["_name", "_args", ["_ttl", 0]];
|
||||
|
||||
private["_ttl", "_eventData"];
|
||||
|
||||
if( (count _this) > 2) then {
|
||||
_ttl = _this select 2;
|
||||
} else {
|
||||
_ttl = 0;
|
||||
};
|
||||
|
||||
if(!HASH_HASKEY(GVAR(syncedEvents),_name)) exitWith {
|
||||
if (!HASH_HASKEY(GVAR(syncedEvents),_name)) exitWith {
|
||||
ACE_LOGERROR("Synced event key not found.");
|
||||
false
|
||||
};
|
||||
|
||||
_eventData = [_name, _args,_ttl];
|
||||
private "_eventData";
|
||||
_eventData = [_name, _args, _ttl];
|
||||
|
||||
["SEH", _eventData] call FUNC(globalEvent);
|
||||
|
@ -1,52 +1,66 @@
|
||||
//#define DEBUG_MODE_FULL
|
||||
/*
|
||||
* Author: ?
|
||||
*
|
||||
* ?
|
||||
*
|
||||
* Arguments:
|
||||
* ?
|
||||
*
|
||||
* Return Value:
|
||||
* ?
|
||||
*
|
||||
* Public: ?
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
if(!isServer) exitWith { false };
|
||||
if (!isServer) exitWith {false};
|
||||
|
||||
// Walk through the local synced events and clean up anything thats already EOL
|
||||
// @TODO: This should be iteration limited to prevent FPS lag
|
||||
private["_data"];
|
||||
|
||||
{
|
||||
private["_data", "_eventLog", "_newEventLog", "_name", "_globalEventTTL"];
|
||||
private ["_name", "_data", "_newEventLog"];
|
||||
|
||||
_name = _x;
|
||||
|
||||
_data = HASH_GET(GVAR(syncedEvents),_name);
|
||||
_eventLog = _data select 1;
|
||||
_globalEventTTL = _data select 2;
|
||||
_data params ["_eventTime", "_eventLog", "_globalEventTTL"];
|
||||
|
||||
_newEventLog = [];
|
||||
|
||||
|
||||
// @TODO: This should be iteration limited to prevent FPS lag
|
||||
{
|
||||
private["_eventEntry", "_ttlReturn"];
|
||||
private ["_eventEntry", "_ttlReturn"];
|
||||
|
||||
_eventEntry = _x;
|
||||
|
||||
_ttlReturn = true;
|
||||
if(typeName _globalEventTTL == "CODE") then {
|
||||
_ttlReturn = [(_data select 0),_eventEntry] call _globalEventTTL;
|
||||
|
||||
if (typeName _globalEventTTL == "CODE") then {
|
||||
_ttlReturn = [_eventTime, _eventEntry] call _globalEventTTL;
|
||||
} else {
|
||||
_ttlReturn = call { _globalEventTTL < 1 || {ACE_diagTime < (_eventEntry select 0) + _globalEventTTL} };
|
||||
_ttlReturn = call {_globalEventTTL < 1 || {ACE_diagTime < (_eventEntry select 0) + _globalEventTTL}};
|
||||
};
|
||||
|
||||
if(_ttlReturn) then {
|
||||
if (_ttlReturn) then {
|
||||
// Do event based TTL check
|
||||
private["_eventTTL"];
|
||||
_eventTTL = _eventEntry select 2;
|
||||
|
||||
if(typeName _eventTTL == "CODE") then {
|
||||
_ttlReturn = [(_data select 0),_eventEntry] call _eventTTL;
|
||||
_eventEntry params ["_time", "", "_eventTTL"];
|
||||
|
||||
if (typeName _eventTTL == "CODE") then {
|
||||
_ttlReturn = [_eventTime, _eventEntry] call _eventTTL;
|
||||
} else {
|
||||
_ttlReturn = call { _eventTTL < 1 || {ACE_diagTime < (_eventEntry select 0) + _eventTTL} };
|
||||
_ttlReturn = call {_eventTTL < 1 || {ACE_diagTime < _time + _eventTTL}};
|
||||
};
|
||||
};
|
||||
|
||||
// Finally drop it if the TTL check fails
|
||||
if(_ttlReturn) then {
|
||||
if (_ttlReturn) then {
|
||||
_newEventLog pushBack _x;
|
||||
};
|
||||
} forEach _eventLog;
|
||||
|
||||
_data set[1, _newEventLog];
|
||||
} forEach (GVAR(syncedEvents) select 0);
|
||||
false
|
||||
} count _eventLog;
|
||||
|
||||
_data set [1, _newEventLog];
|
||||
false
|
||||
} count (GVAR(syncedEvents) select 0);
|
||||
|
||||
// @TODO: Next, detect if we had a new request from a JIP player, and we need to continue syncing events
|
||||
|
@ -17,21 +17,20 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_3(_unit,_varName,_maxDelay);
|
||||
params ["_unit", "_varName", "_maxDelay"];
|
||||
|
||||
// Create the publish scheduler PFH the first ACE_time
|
||||
if (isNil QGVAR(publishSchedId)) then {
|
||||
|
||||
GVAR(publishVarNames) = [];
|
||||
GVAR(publishNextTime) = 1e7;
|
||||
|
||||
GVAR(publishSchedId) = [{
|
||||
|
||||
if (ACE_diagTime > GVAR(publishNextTime)) then {
|
||||
{
|
||||
EXPLODE_2_PVT(_x,_unit,_varName);
|
||||
_unit setVariable [_varName, (_unit getVariable _varName), true];
|
||||
} forEach GVAR(publishVarNames);
|
||||
_x params [_unit, _varName];
|
||||
_unit setVariable [_varName, _unit getVariable _varName, true];
|
||||
false
|
||||
} count GVAR(publishVarNames);
|
||||
|
||||
GVAR(publishVarNames) = [];
|
||||
GVAR(publishNextTime) = 1e7;
|
||||
@ -40,10 +39,10 @@ if (isNil QGVAR(publishSchedId)) then {
|
||||
};
|
||||
|
||||
// If the variable is not on the list
|
||||
if (GVAR(publishVarNames) find [_unit,_varName] == -1) exitWith {
|
||||
GVAR(publishVarNames) pushBack [_unit,_varName];
|
||||
if (GVAR(publishVarNames) find [_unit, _varName] == -1) exitWith {
|
||||
GVAR(publishVarNames) pushBack [_unit, _varName];
|
||||
GVAR(publishNextTime) = GVAR(publishNextTime) min (ACE_diagTime + _maxDelay);
|
||||
};
|
||||
|
||||
// If the variable is on the list
|
||||
GVAR(publishNextTime) = GVAR(publishNextTime) min (ACE_diagTime + _maxDelay);
|
||||
GVAR(publishNextTime) = GVAR(publishNextTime) min (ACE_diagTime + _maxDelay);
|
||||
|
@ -21,6 +21,7 @@ ACE_gameTime = time;
|
||||
ACE_diagTime = diag_tickTime;
|
||||
|
||||
_delta = ACE_diagTime - _lastTickTime;
|
||||
|
||||
if (ACE_gameTime <= _lastGameTime) then {
|
||||
TRACE_1("paused",_delta);
|
||||
ACE_paused = true;
|
||||
|
@ -12,14 +12,11 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_array", "_result"];
|
||||
|
||||
_array = _this;
|
||||
|
||||
private "_result";
|
||||
_result = 0;
|
||||
|
||||
{
|
||||
if (_x) then {_result = _result + 2 ^ _forEachIndex};
|
||||
} forEach _array;
|
||||
} forEach _this;
|
||||
|
||||
_result
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: Garth de Wet (LH)
|
||||
*
|
||||
* Takes a string/number and returns the number.
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: ?
|
||||
*
|
||||
* ?
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: ?
|
||||
*
|
||||
* ?
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: SilentSpike (based on unmuteUnit)
|
||||
*
|
||||
* Globally unhides a unit. Only unhides if the last reason was removed.
|
||||
*
|
||||
* Arguments:
|
||||
|
27
addons/common/functions/fnc_uniqueElements.sqf
Normal file
27
addons/common/functions/fnc_uniqueElements.sqf
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Make a copy of an array with only the unique elements.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: array <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* Copy of original array <ARRAY>
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_array"];
|
||||
|
||||
private "_result";
|
||||
_result = [];
|
||||
|
||||
{
|
||||
if !(_x in _result) then {
|
||||
_result pushBack _x;
|
||||
};
|
||||
false
|
||||
} count _array;
|
||||
|
||||
_result
|
@ -1,24 +1,17 @@
|
||||
/**
|
||||
* fn_uniqueElementsOnly.sqf
|
||||
* @Descr: Make a copy of an array with only the unique elements.
|
||||
* @Author: Glowbal
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Make a copy of an array with only the unique elements.
|
||||
*
|
||||
* @Arguments: [array ARRAY]
|
||||
* @Return: ARRAY Copy of original array
|
||||
* @PublicAPI: true
|
||||
* Arguments:
|
||||
* 0: array <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* Copy of original array <ARRAY>
|
||||
*
|
||||
* Public: Yes
|
||||
*
|
||||
* Deprecated
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_result", "_value"];
|
||||
PARAMS_1(_array);
|
||||
|
||||
_result = [];
|
||||
{
|
||||
_value = _x;
|
||||
if ({_x isEqualTo _value} count _result == 0) then {
|
||||
_result pushback _x;
|
||||
};
|
||||
} forEach _array;
|
||||
|
||||
_result;
|
||||
_this call FUNC(uniqueElements)
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: commy2
|
||||
*
|
||||
* Unmutes the unit. Only unmutes if the last reason was removed.
|
||||
*
|
||||
* Arguments:
|
||||
|
@ -1,36 +1,37 @@
|
||||
/**
|
||||
* fn_useItem.sqf
|
||||
* @Descr:
|
||||
* @Author: Glowbal
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Use item
|
||||
*
|
||||
* @Arguments: []
|
||||
* @Return:
|
||||
* @PublicAPI: true
|
||||
* Arguments:
|
||||
* 0: unit <OBJECT>
|
||||
* 1: item <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* if item has been used. <BOOL>
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_2(_unit,_item);
|
||||
|
||||
private ["_return", "_vehicleUsage"];
|
||||
|
||||
_vehicleUsage = [_this, 2, false, [false]] call BIS_fnc_Param;
|
||||
params ["_unit", "_item", ["_vehicleUsage", false]];
|
||||
|
||||
private "_return";
|
||||
_return = false;
|
||||
if (!_vehicleUsage) then {
|
||||
|
||||
if !(_vehicleUsage) then {
|
||||
if (_item != "") then {
|
||||
if (_item in (items _unit)) then {
|
||||
if (_item in items _unit) then {
|
||||
_unit removeItem _item;
|
||||
_return = true;
|
||||
} else {
|
||||
if (_item in (assignedItems _unit)) then {
|
||||
_unit unassignItem _item;
|
||||
_unit removeItem _item;
|
||||
if (_item in assignedItems _unit) then {
|
||||
_unit unlinkItem _item;
|
||||
_return = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
//} else {
|
||||
// @todo implement shared item functionality for with vehicles.
|
||||
};
|
||||
// TODO implement shared item functionality for with vehicles.
|
||||
|
||||
_return;
|
||||
_return
|
||||
|
@ -1,28 +1,32 @@
|
||||
/**
|
||||
* fn_useMagazine.sqf
|
||||
* @Descr: Use magazine
|
||||
* @Author: Glowbal
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Use magazine
|
||||
*
|
||||
* @Arguments: [unit OBJECt, magazine STRING]
|
||||
* @Return: BOOL True if magazine has been used.
|
||||
* @PublicAPI: true
|
||||
* Arguments:
|
||||
* 0: unit <OBJECT>
|
||||
* 1: magazine <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* if magazine has been used. <BOOL>
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_return", "_vehicleUsage"];
|
||||
PARAMS_2(_unit,_magazine);
|
||||
_vehicleUsage = [_this, 2, false, [false]] call BIS_fnc_Param;
|
||||
params ["_unit", "_magazine", ["_vehicleUsage", false]];
|
||||
|
||||
if (!_vehicleUsage) then {
|
||||
private "_return";
|
||||
_return = false;
|
||||
|
||||
if !(_vehicleUsage) then {
|
||||
if (_magazine != "") then {
|
||||
_unit removeMagazine _magazine;
|
||||
_return = true;
|
||||
} else {
|
||||
_return = false;
|
||||
};
|
||||
[format["fnc_useMagazine: %1 | %2",_this,_return]] call FUNC(debug);
|
||||
|
||||
[format ["fnc_useMagazine: %1 | %2", _this, _return]] call FUNC(debug);
|
||||
//} else {
|
||||
// @todo implement shared magazine functionality
|
||||
};
|
||||
|
||||
_return
|
||||
} else {
|
||||
// TODO implement shared magazine functionality
|
||||
};
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Author: esteldunedain
|
||||
*
|
||||
* Executes a code once with a given game ACE_time delay, using a PFH
|
||||
*
|
||||
* Arguments:
|
||||
@ -20,5 +19,5 @@
|
||||
|
||||
params ["_func", "_params", "_delay"];
|
||||
|
||||
GVAR(waitAndExecArray) pushBack [(ACE_time + _delay), _func, _params];
|
||||
GVAR(waitAndExecArray) pushBack [ACE_time + _delay, _func, _params];
|
||||
GVAR(waitAndExecArray) sort true;
|
||||
|
@ -19,6 +19,7 @@ params ["_position"];
|
||||
if (isNil QGVAR(waveHeightLogic)) then {
|
||||
GVAR(waveHeightLogic) = "Logic" createVehicleLocal [0,0,0];
|
||||
};
|
||||
|
||||
GVAR(waveHeightLogic) setPosASL _position;
|
||||
|
||||
(getPosASLW GVAR(waveHeightLogic) select 2) - (getPosASL GVAR(waveHeightLogic) select 2)
|
||||
|
Loading…
Reference in New Issue
Block a user