cleanup common

This commit is contained in:
commy2
2015-09-17 18:25:02 +02:00
parent 067b08611e
commit 36a279012c
20 changed files with 225 additions and 150 deletions

View File

@ -3,9 +3,9 @@
* Converts ASL to Arma "Position" * Converts ASL to Arma "Position"
* *
* Arguments: * Arguments:
* 0: position x <Number> * 0: position x <NUMBER>
* 1: position y <Number> * 1: position y <NUMBER>
* 2: position z <Number> * 2: position z <NUMBER>
* *
* Return Value: * Return Value:
* None * None

View File

@ -1,11 +1,22 @@
// by commy2 /*
* Author: commy2
*
* hint retun value of given function every frame
*
* Argument:
* <CODE>
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp" #include "script_component.hpp"
terminate (missionNamespace getVariable [QGVAR(MonitorFnc), scriptNull]); if (!isNil QGVAR(MonitorFnc)) then {
[GVAR(MonitorFnc)] call CBA_fnc_removePerFrameHandler;
GVAR(MonitorFnc) = _this spawn {
waitUntil {
hintSilent str (call _this);
false
};
}; };
GVAR(MonitorFnc) = [{
hintSilent str (call (_this select 0));
}, 0, _this] call CBA_fnc_addPerFrameHandler;

View File

@ -3,23 +3,23 @@
* *
* Transforms a number to an array of the correspondending digits. * Transforms a number to an array of the correspondending digits.
* *
* Argument: * Arguments:
* 0: Number to 'digitize' (Number) * 0: Number to 'digitize' <NUMBER>
* 1: Set the minimal length of the returned array. Useful for getting left hand zeroes. (Number, optional) * 1: Set the minimal length of the returned array. Useful for getting left hand zeroes. <NUMBER>, optional
* *
* Return value: * Return Value:
* Digits. The maximum count is six digits. (Array) * Digits. The maximum count is six digits. (Array)
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_length", "_digits"]; params ["_number", "_minLength"];
PARAMS_2(_number,_minLength);
_number = _number min 999999; _number = _number min 999999;
_number = str _number; _number = str _number;
private "_length";
_length = count _number; _length = count _number;
if (isNil "_minLength") then {_minLength = _length}; if (isNil "_minLength") then {_minLength = _length};
@ -31,7 +31,9 @@ while {_length < _minLength} do {
_length = _length + 1; _length = _length + 1;
}; };
private "_digits";
_digits = []; _digits = [];
for "_x" from 0 to (_length - 1) do { for "_x" from 0 to (_length - 1) do {
_digits pushBack parseNumber (_number select [_x, 1]); _digits pushBack parseNumber (_number select [_x, 1]);
}; };

View File

@ -3,23 +3,23 @@
* *
* Transforms a number to an string of the correspondending digits. * Transforms a number to an string of the correspondending digits.
* *
* Argument: * Arguments:
* 0: Number to 'digitize' (Number) * 0: Number to 'digitize' <NUMBER>
* 1: Set the minimal length of the returned string. Useful for getting left hand zeroes. (Number, optional) * 1: Set the minimal length of the returned string. Useful for getting left hand zeroes. (Number, optional)
* *
* Return value: * Return Value:
* Digits. The maximum length is six digits. (String) * Digits. The maximum length is six digits. (String)
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_length"]; params ["_number", "_minLength"];
PARAMS_2(_number,_minLength);
_number = _number min 999999; _number = _number min 999999;
_number = str _number; _number = str _number;
private "_length";
_length = count _number; _length = count _number;
if (isNil "_minLength") then {_minLength = _length}; if (isNil "_minLength") then {_minLength = _length};

View File

@ -3,23 +3,24 @@
* *
* Converts a number to a string without losing as much precission as str or format. * Converts a number to a string without losing as much precission as str or format.
* *
* Argument: * Arguments:
* 0: A number (Number) * 0: A number <NUMBER>
* *
* Return value: * Return Value:
* The number as string (String) * The number as string (String)
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_decimals"]; params ["_number"];
PARAMS_1(_number); private "_decimals";
_decimals = str (abs _number mod 1);
_decimals = str (abs(_number) mod 1);
_decimals = toArray _decimals; _decimals = toArray _decimals;
_decimals deleteAt 0; _decimals deleteAt 0;
if (_number < 0) exitWith { if (_number < 0) exitWith {
format ["-%1%2", floor abs(_number), toString _decimals]; format ["-%1%2", floor abs _number, toString _decimals];
}; };
format ["%1%2", floor _number, toString _decimals]; format ["%1%2", floor _number, toString _decimals];

View File

@ -4,14 +4,15 @@
* Counterpart of ace_common_fnc_claim. Check if the given object is claimed by another unit. * Counterpart of ace_common_fnc_claim. Check if the given object is claimed by another unit.
* *
* Arguments: * Arguments:
* 0: Any object. (Object) * 0: Any object. <OBJECT>
* *
* Return Value: * Return Value:
* Is this object claimed by someone? * Is this object claimed by someone?
* *
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_target); params ["_target"];
!isNull (_target getVariable [QGVAR(owner), objNull]) !isNull (_target getVariable [QGVAR(owner), objNull])

View File

@ -8,7 +8,9 @@
* NONE. * NONE.
* *
* Return Value: * Return Value:
* Player controlled unit (object) * Player controlled unit <OBJECT>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,4 +1,16 @@
// by commy2 /*
* Author: commy2
*
* Return the current side of the player
*
* Arguments:
* None
*
* Return Value:
* current local side (Side)
*
* Public: Yes
*/
#include "script_component.hpp" #include "script_component.hpp"
side group ACE_player side group ACE_player

View File

@ -3,23 +3,23 @@
* *
* Sets the name variable of the object. Used to prevent issues with the name command. * Sets the name variable of the object. Used to prevent issues with the name command.
* *
* Argument: * Arguments:
* 0: Object (Object) * 0: Object <OBJECT>
* *
* Return value: * Return Value:
* Nothing. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_name"]; params ["_unit"];
PARAMS_1(_unit);
if (isNull _unit || {!alive _unit}) exitWith {}; if (isNull _unit || {!alive _unit}) exitWith {};
if (_unit isKindOf "CAManBase") then { if (_unit isKindOf "CAManBase") then {
_name = [name _unit, true] call FUNC(sanitizeString); _name = [name _unit, true] call FUNC(sanitizeString);
//if (_name != _unit getVariable ["ACE_Name", ""]) then { //if (_name != _unit getVariable ["ACE_Name", ""]) then {
_unit setVariable ["ACE_Name", _name, true]; _unit setVariable ["ACE_Name", _name, true];
//}; //};

View File

@ -1,8 +1,22 @@
// by commy2 /*
* Author: commy2
*
* hint the Variable ACE_isUsedBy from the input Object every frame
*
* Argument:
* <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
GVAR(Debug_Object) = _this select 0; if (!isNil QGVAR(showUserPFH)) then {
[GVAR(showUserPFH)] call CBA_fnc_removePerFrameHandler;
onEachFrame {
hintSilent str (GVAR(Debug_Object) getVariable ["ACE_isUsedBy", objNull]);
}; };
GVAR(showUserPFH) = [{
hintSilent str ((_this select 0) getVariable ["ACE_isUsedBy", objNull]);
}, 0, _this] call CBA_fnc_addPerFrameHandler;

View File

@ -3,26 +3,27 @@
* *
* Create a centered, colored text. * Create a centered, colored text.
* *
* Argument: * Arguments:
* 0: Text (Anything) * 0: Text <ANY>
* 2: Color (Array) * 1: Color <ARRAY>
* *
* Return value: * Return Value:
* Text * Text <STRING>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_string", "_color"]; params ["_string", "_color"];
_string = format ["%1", _this select 0]; _string = format ["%1", _string];
_color = _this select 1;
_color = ( _color = (
[255 * (_color select 0), 2] call FUNC(toHex) [255 * (_color select 0), 2] call FUNC(toHex)
) + ( ) + (
[255 * (_color select 1), 2] call FUNC(toHex) [255 * (_color select 1), 2] call FUNC(toHex)
) + ( ) + (
[255 * (_color select 2), 2] call FUNC(toHex) [255 * (_color select 2), 2] call FUNC(toHex)
); );
parseText format ["<t align='center' color='#%2' >%1</t>", _string, _color]; parseText format ["<t align='center' color='#%2' >%1</t>", _string, _color]

View File

@ -1,23 +1,22 @@
/* /*
Author: commy2 * Author: commy2
*
Description: * Converts number to binary number
Converts number to binary number *
* Arguments:
Arguments: * A number
A number *
* Return Value:
Return Value: * A binary number, String
A binary number, String *
*/ * Public: Yes
*/
#include "script_component.hpp" #include "script_component.hpp"
params ["_number", ["_minLength", 1]];
private ["_sign", "_bin", "_rest"]; private ["_sign", "_bin", "_rest"];
PARAMS_2(_number,_minLength);
if (isNil "_minLength") then {_minLength = 1};
_sign = ["", "-"] select (_number < 0); _sign = ["", "-"] select (_number < 0);
_number = round abs _number; _number = round abs _number;

View File

@ -3,11 +3,13 @@
* *
* Convert an array of booleans into a number. * Convert an array of booleans into a number.
* *
* Argument: * Arguments:
* 0: Booleans (Array of Booleans) * N: Booleans <ARRAY of Booleans>
* *
* Return value: * Return Value:
* Bitmask (Number) * Bitmask (Number)
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,15 +1,16 @@
/* /*
Author: commy2, esteldunedain * Author: commy2, esteldunedain
*
Description: * Converts number to hexadecimal number
Converts number to hexadecimal number *
* Arguments:
Arguments: * A number between 0 and 255 <NUMBER>
A number between 0 and 255 <NUMBER> *
* Return Value:
Return Value: * A hexadecimal number, <STRING>
A hexadecimal number, String *
*/ * Public: Yes
*/
#include "script_component.hpp" #include "script_component.hpp"
private ["_number"]; private ["_number"];

View File

@ -1,5 +1,6 @@
/* /*
* Author: SilentSpike (based on unmuteUnit) * Author: SilentSpike (based on unmuteUnit)
*
* Globally unhides a unit. Only unhides if the last reason was removed. * Globally unhides a unit. Only unhides if the last reason was removed.
* *
* Arguments: * Arguments:
@ -7,17 +8,16 @@
* 1: Reason to unhide the unit <STRING> * 1: Reason to unhide the unit <STRING>
* *
* Return Value: * Return Value:
* nil * None
* *
* Example: * Example:
* [ACE_Player, "SpectatorMode"] call ace_common_fnc_unhideUnit * [ACE_Player, "SpectatorMode"] call ace_common_fnc_unhideUnit
* *
* Public: No * Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_reason); params ["_unit", "_reason"];
if (isNull _unit) exitWith {}; if (isNull _unit) exitWith {};

View File

@ -3,16 +3,18 @@
* *
* Unmutes the unit. Only unmutes if the last reason was removed. * Unmutes the unit. Only unmutes if the last reason was removed.
* *
* Argument: * Arguments:
* 0: Unit (Object) * 0: Unit <OBJECT>
* 1: Reason to unmute the unit. (String) * 1: Reason to unmute the unit. <STRING>
* *
* Return value: * Return Value:
* Nothing * None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_reason); params ["_unit", "_reason"];
if (isNull _unit) exitWith {}; if (isNull _unit) exitWith {};

View File

@ -3,12 +3,12 @@
* *
* Executes a code once with a given game ACE_time delay, using a PFH * Executes a code once with a given game ACE_time delay, using a PFH
* *
* Argument: * Arguments:
* 0: Code to execute (Code) * 0: Code to execute <CODE>
* 1: Parameters to run the code with (Array) * 1: Parameters to run the code with <ARRAY>
* 2: Delay in seconds before executing the code (Number) * 2: Delay in seconds before executing the code <NUMBER>
* *
* Return value: * Return Value:
* None * None
* *
* Example: * Example:
@ -18,7 +18,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_func,_params,_delay); params ["_func", "_params", "_delay"];
GVAR(waitAndExecArray) pushBack [(ACE_time + _delay), _func, _params]; GVAR(waitAndExecArray) pushBack [(ACE_time + _delay), _func, _params];
GVAR(waitAndExecArray) sort true; GVAR(waitAndExecArray) sort true;

View File

@ -9,12 +9,16 @@
* Return Value: * Return Value:
* Wave height in meters * Wave height in meters
* *
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
if(isNil QGVAR(waveHeightLogic)) then { params ["_position"];
if (isNil QGVAR(waveHeightLogic)) then {
GVAR(waveHeightLogic) = "Logic" createVehicleLocal [0,0,0]; GVAR(waveHeightLogic) = "Logic" createVehicleLocal [0,0,0];
}; };
GVAR(waveHeightLogic) setPosASL (_this select 0); GVAR(waveHeightLogic) setPosASL _position;
(((getPosASLW GVAR(waveHeightLogic)) select 2) - ((getPosASL GVAR(waveHeightLogic)) select 2)) (getPosASLW GVAR(waveHeightLogic) select 2) - (getPosASL GVAR(waveHeightLogic) select 2)

View File

@ -1,53 +1,76 @@
// (c) zGuba 2011 /*
// Function helper for framing objects on screen. * Author: zGuba 2011
// Input: [_object,_margins3D,_offset3D] (object, 3 * float array, 3 * float array) *
// Output: [_minX,_minY,_minY,_maxY] (4 * float) * Function helper for framing objects on screen.
*
* Arguments:
* 0: object <OBJECT>
* 1: margins 3D <ARRAY>
* 0: X <NUMBER>
* 1: Y <NUMBER>
* 2: Z <NUMBER>
* 2: offset 3D <ARRAY>
* 0: X <NUMBER>
* 1: Y <NUMBER>
* 2: Z <NUMBER>
*
* Return Value:
* 0: Minimal X <NUMMBER>
* 1: Minimal Y <NUMMBER>
* 2: Maximal X <NUMMBER>
* 3: Maximal Y <NUMMBER>
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
private ["_minX","_minY","_maxX","_maxY", "_bounds", "_boundsCorners", "_boundsMax", "_boundsMaxX", "_boundsMaxY", "_boundsMaxZ", "_boundsMin", "_boundsMinX", "_boundsMinY", "_boundsMinZ"]; params ["_object", "_margins", "_offsets"];
PARAMS_3(_object,_margins,_offsets); private ["_minX", "_minY", "_maxX", "_maxY", "_bounds", "_boundsCorners"];
_minX = 10; _minX = 10;
_minY = 10; _minY = 10;
_maxX = -10; _maxX = -10;
_maxY = -10; _maxY = -10;
if (true) then { _bounds = boundingBox _object;
_bounds = boundingBox _object; _margins params ["_marginsX", "_marginsY", "_marginsZ"];
_offsets params ["_offsetsX", "_offsetsY", "_offsetsZ"];
_boundsMin = _bounds select 0; _bounds params ["_boundsMin", "_boundsMax"];
_boundsMinX = (_boundsMin select 0) - (_margins select 0) + (_offsets select 0); _boundsMin params ["_boundsMinX", "_boundsMinY", "_boundsMinZ"];
_boundsMinY = (_boundsMin select 1) - (_margins select 1) + (_offsets select 1); _boundsMax params ["_boundsMaxX", "_boundsMaxY", "_boundsMaxZ"];
_boundsMinZ = (_boundsMin select 2) - (_margins select 2) + (_offsets select 2);
_boundsMax = _bounds select 1;
_boundsMaxX = (_boundsMax select 0) + (_margins select 0) + (_offsets select 0);
_boundsMaxY = (_boundsMax select 1) + (_margins select 1) + (_offsets select 1);
_boundsMaxZ = (_boundsMax select 2) + (_margins select 2) + (_offsets select 2);
_boundsCorners = [ _boundsMinX = _boundsMinX - _marginsX + _offsetsX;
[_boundsMinX,_boundsMinY,_boundsMinZ], _boundsMinY = _boundsMinY - _marginsY + _offsetsY;
[_boundsMinX,_boundsMinY,_boundsMaxZ], _boundsMinZ = _boundsMinZ - _marginsZ + _offsetsZ;
[_boundsMinX,_boundsMaxY,_boundsMinZ],
[_boundsMinX,_boundsMaxY,_boundsMaxZ],
[_boundsMaxX,_boundsMinY,_boundsMinZ],
[_boundsMaxX,_boundsMinY,_boundsMaxZ],
[_boundsMaxX,_boundsMaxY,_boundsMinZ],
[_boundsMaxX,_boundsMaxY,_boundsMaxZ]
];
_boundsMaxX = _boundsMaxX + _marginsX + _offsetsX;
_boundsMaxY = _boundsMaxY + _marginsY + _offsetsY;
_boundsMaxZ = _boundsMaxZ + _marginsZ + _offsetsZ;
{ _boundsCorners = [
_ppos = worldToScreen (_object modelToWorld _x); [_boundsMinX,_boundsMinY,_boundsMinZ],
if (count _ppos >= 2) then { [_boundsMinX,_boundsMinY,_boundsMaxZ],
EXPLODE_2_PVT(_ppos,_pposX,_pposY); [_boundsMinX,_boundsMaxY,_boundsMinZ],
if (_pposX < _minX) then {_minX = _pposX}; [_boundsMinX,_boundsMaxY,_boundsMaxZ],
if (_pposX > _maxX) then {_maxX = _pposX}; [_boundsMaxX,_boundsMinY,_boundsMinZ],
if (_pposY < _minY) then {_minY = _pposY}; [_boundsMaxX,_boundsMinY,_boundsMaxZ],
if (_pposY > _maxY) then {_maxY = _pposY}; [_boundsMaxX,_boundsMaxY,_boundsMinZ],
}; //else - what to do if it is offscreen? [_boundsMaxX,_boundsMaxY,_boundsMaxZ]
} forEach _boundsCorners; ];
};
{
private "_ppos";
_ppos = worldToScreen (_object modelToWorld _x);
if (count _ppos >= 2) then {
_ppos params ["_pposX", "_pposY"];
if (_pposX < _minX) then {_minX = _pposX};
if (_pposX > _maxX) then {_maxX = _pposX};
if (_pposY < _minY) then {_minY = _pposY};
if (_pposY > _maxY) then {_maxY = _pposY};
}; //else - what to do if it is offscreen?
false
} count _boundsCorners;
[_minX,_minY,_maxX,_maxY] [_minX,_minY,_maxX,_maxY]

View File

@ -10,4 +10,4 @@
if((count _this) > c) then {\ if((count _this) > c) then {\
_callFrom = _this select c;\ _callFrom = _this select c;\
_lineNo = _this select c+1;\ _lineNo = _this select c+1;\
}; };