more common code cleanup

This commit is contained in:
commy2 2015-09-19 23:18:07 +02:00
parent 6b96c7fd7c
commit 73a9c1b5f8
6 changed files with 83 additions and 96 deletions

View File

@ -1,6 +1,5 @@
/*
* Author: Nou
*
* Execute a local event on this client only.
*
* Arguments:

View File

@ -1,28 +1,20 @@
/**
* fn_setProne.sqf
* @Descr: Force a unit to go prone
* @Author: Glowbal
/*
* Author: Glowbal
* Force a unit to go prone
*
* @Arguments: [unit OBJECT]
* @Return: void
* @PublicAPI: true
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_unit"];
_unit = [_this,0, ObjNull,[ObjNull]] call BIS_fnc_Param;
switch (currentWeapon _unit) do {
case (primaryWeapon _unit): {
[_unit,"amovppnemstpsraswrfldnon"] call FUNC(localAnim);
};
case (secondaryWeapon _unit): {
[_unit,"amovppnemstpsraswlnrdnon"] call FUNC(localAnim);
};
case (handgunWeapon _unit): {
[_unit,"AmovPpneMstpSrasWpstDnon"] call FUNC(localAnim);
};
default {
[_unit,"amovppnemstpsnonwnondnon"] call FUNC(localAnim);
};
};
params ["_unit"];
[
_unit,
["amovppnemstpsnonwnondnon", "amovppnemstpsraswrfldnon", "amovppnemstpsraswlnrdnon", "amovppnemstpsraswpstdnon"] select (([primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit] find currentWeapon _unit) + 1)
] call FUNC(localAnim);

View File

@ -5,10 +5,10 @@
* If executed on server it can have global effect if the last parameter is set to true.
*
* Arguments:
* 0: Setting name (String)
* 1: Value (Any)
* 2: Force it? (Bool) (Optional)
* 3: Broadcast the change to all clients (Bool) (Optional)
* 0: Setting name <STRING>
* 1: Value <ANY>
* 2: Force it? (default: false) <BOOL>
* 3: Broadcast the change to all clients (default: false) <BOOL>
*
* Return Value:
* None
@ -17,15 +17,9 @@
*/
#include "script_component.hpp"
private ["_force", "_settingData","_failed"];
params ["_name", "_value", ["_force", false], ["_broadcastChanges", false]];
PARAMS_2(_name,_value);
private ["_force"];
_force = false;
if (count _this > 2) then {
_force = _this select 2;
};
private ["_settingData", "_failed"];
_settingData = [_name] call FUNC(getSettingData);
@ -37,9 +31,9 @@ if (_settingData select 6) exitWith {};
// If the type is not equal, try to cast it
_failed = false;
if ((typeName _value) != (_settingData select 1)) then {
if (typeName _value != _settingData select 1) then {
_failed = true;
if ((_settingData select 1) == "BOOL" and (typeName _value) == "SCALAR") then {
if (_settingData select 1 == "BOOL" && typeName _value == "SCALAR") then {
// If value is not 0 or 1 consider it invalid and don't set anything
if (_value isEqualTo 0) then {
_value = false;
@ -50,10 +44,11 @@ if ((typeName _value) != (_settingData select 1)) then {
_failed = false;
};
};
if ((_settingData select 1) == "COLOR" and (typeName _value) == "ARRAY") then {
if (_settingData select 1 == "COLOR" && typeName _value == "ARRAY") then {
_failed = false;
};
};
if (_failed) exitWith {};
// Force it if it was required
@ -66,7 +61,7 @@ if (_value isEqualTo (missionNamespace getVariable _name)) exitWith {};
TRACE_2("Variable Updated",_name,_value);
missionNamespace setVariable [_name, _value];
if (isServer && {count _this > 3} && {_this select 3}) then {
if (isServer && {_broadcastChanges}) then {
// Publicize the new value
publicVariable _name;

View File

@ -3,7 +3,7 @@
* Load a setting from config if it was not previosuly forced. Force if neccesary.
*
* Arguments:
* 0: Config entry (config entry)
* 0: Config entry <CONFIG>
*
* Return Value:
* None
@ -12,12 +12,12 @@
*/
#include "script_component.hpp"
PARAMS_1(_optionEntry);
params ["_optionEntry"];
private ["_fnc_getValueWithType", "_value","_name", "_typeName", "_settingData", "_valueConfig", "_text"];
private ["_fnc_getValueWithType", "_value", "_name", "_typeName", "_settingData", "_valueConfig", "_text"];
_fnc_getValueWithType = {
EXPLODE_2_PVT(_this,_optionEntry,_typeName);
params ["_optionEntry", "_typeName"];
_valueConfig = (_optionEntry >> "value");
_value = if (isNumber (_optionEntry >> "value")) then {getNumber (_optionEntry >> "value")} else {0};
@ -103,11 +103,8 @@ if (isNil _name) then {
// The setting is not forced, so update the value
// Get the type from the existing variable
_typeName = _settingData select 1;
// Read entry and cast it to the correct type
_value = [_optionEntry, _typeName] call _fnc_getValueWithType;
// Read entry and cast it to the correct type from the existing variable
_value = [_optionEntry, _settingData select 1] call _fnc_getValueWithType;
// Update the variable
missionNamespace setVariable [_name, _value];

View File

@ -3,25 +3,26 @@
*
* Sets a public object namespace variable that gets reset with the same value after respawn, so JIP clients keep the value.
*
* Argument:
* 0: Object (Object)
* 1: Variable name (String)
* 2: Any value (Anything)
* Arguments:
* 0: Object <OBJECT>
* 1: Variable name <STRING>
* 2: Any value <ANY>
*
* Return value:
* Nothing.
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_respawnVariables"];
PARAMS_3(_unit,_varName,_value);
params ["_unit", "_varName", "_value"];
private "_respawnVariables";
_respawnVariables = _unit getVariable ["ACE_respawnVariables", []];
if !(_varName in _respawnVariables) then {
_respawnVariables pushBack _varName;
_unit setVariable ["ACE_respawnVariables", _respawnVariables, true];
_respawnVariables pushBack _varName;
_unit setVariable ["ACE_respawnVariables", _respawnVariables, true];
};
_unit setVariable [_varName, _value, true];

View File

@ -1,54 +1,57 @@
/*
* Author: commy2
* 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.
*
* Argument:
* 0: Object the variable should be assigned to (Object)
* 1: Name of the variable (String)
* 2: Value of the variable (Any)
* 3: Windup ACE_time (Number, optional. Default: 1)
* Arguments:
* 0: Object the variable should be assigned to <OBJECT>
* 1: Name of the variable <STRING>
* 2: Value of the variable <ANY>
* 3: Windup ACE_time <NUMBER> (default: 1)
*
* Return value:
* Nothing.
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_4(_object,_varName,_value,_sync);
if (isNil "_sync") then {
_sync = 1;
};
params ["_object", "_varName", "_value", ["_sync", 1]];
// set value locally
_object setVariable [_varName, _value];
// "duh"
if (!isMultiplayer) exitWith {};
// Exit Dedicated server and headless Clients
if (!hasInterface) exitWith {};
// generate stacked eventhandler id
private "_idName";
_idName = format ["ACE_setVariablePublic_%1", _varName];
private ["_idName", "_syncTime"];
// exit now if an eh for that variable already exists
private "_allIdNames";
_allIdNames = [GETMVAR(BIS_stackedEventHandlers_onEachFrame,[]), {_this select 0}] call FUNC(map);
if (_idName in GVAR(setVariableNames)) exitWith {};
if (_idName in _allIdNames) exitWith {};
// when to push the value
private "_syncTime";
_syncTime = ACE_diagTime + _sync;
// add eventhandler
[_idName, "onEachFrame", {
// wait to sync the variable
if (ACE_diagTime > _this select 2) then {
// set value public
(_this select 0) setVariable [_this select 1, (_this select 0) getVariable (_this select 1), true];
GVAR(setVariableNames) pushBack _idName;
// remove eventhandler
[_this select 3, "onEachFrame"] call BIS_fnc_removeStackedEventHandler
GVAR(setVariablePublicArray) pushBack [_object, _varName, _syncTime, _idName];
if (isNil QGVAR(setVariablePublicPFH)) exitWith {};
GVAR(setVariablePublicPFH) = [{
private "_delete";
_delete = 0;
{
_x params ["_object", "_varName", "_syncTime", "_idName"];
if (ACE_diagTime > _syncTime) then {
// set value public
_object setVariable [_varName, _object getVariable _varName, true];
GVAR(setVariablePublicArray) deleteAt _forEachIndex - _delete;
GVAR(setVariableNames) deleteAt _forEachIndex - _delete;
_delete = _delete + 1;
};
} forEach GVAR(setVariablePublicArray);
if (GVAR(setVariablePublicArray) isEqualTo []) then {
[GVAR(setVariablePublicPFH)] call CBA_fnc_removePerFrameHandler;
GVAR(setVariablePublicPFH) = nil;
};
}, [_object, _varName, _syncTime, _idName]] call BIS_fnc_addStackedEventHandler;
nil
}, 0, []] call CBA_fnc_addPerFrameHandler;