add header & PFH

WIP
This commit is contained in:
bux578 2015-02-02 23:28:27 +01:00
parent 869e36eb5f
commit d339b9567d
11 changed files with 288 additions and 262 deletions

View File

@ -6,6 +6,6 @@ class Extended_PreInit_EventHandlers {
class Extended_PostInit_EventHandlers {
class ADDON {
postInit = QUOTE(call COMPILE_FILE(XEH_postInit) );
clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) );
};
};

View File

@ -1,17 +1,22 @@
/*
Author(s):
bux578
*/
* Author: bux578
* Initializes the SwitchUnits pbo.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* None
*
* Public: No
*/
#include "script_component.hpp"
//0 spawn {
private ["_sides"];
//waitUntil {sleep 0.5; AGM_SwitchUnits_EnableSwitchUnits};
//_side = [west, east, independent, civilian] select AGM_SwitchUnits_SwitchUnitsAllowedForSide;
private "_sides";
_sides = [];
@ -20,8 +25,8 @@ if(GVAR(SwitchToEast)) then {_sides pushBack east};
if(GVAR(SwitchToIndependent)) then {_sides pushBack independent};
if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian};
if (player getVariable ["ACE_CanSwitchUnits", false]) then {
[player, _sides] call FUNC(initPlayer);
};
hint "TEST";
//};
if (player getVariable ["ACE_CanSwitchUnits", false]) then {
[player, _sides] call FUNC(initPlayer);
};

View File

@ -1,19 +1,19 @@
/*
Name: ACE_SwitchUnits_fnc_addMapFunction
Author(s):
bux578
Description:
Adds a mapClick Eventhandler
Parameters:
0: OBJECT - unit
1: ARRAY<OBJECT> - sides
Returns:
VOID
*/
* Author: bux578
* Adds a mapClick Eventhandler
*
* Arguments:
* 0: unit <OBJECT>
* 1: sides <ARRAY<OBJECT>>
*
* Return Value:
* None
*
* Example:
* [_unit, _sides] call FUNC(addMapFunction)
*
* Public: No
*/
#include "script_component.hpp"

View File

@ -1,28 +1,24 @@
/*
Name: ACE_SwitchUnits_fnc_handleMapClick
Author(s):
bux578
Description:
Finds the clicked unit
Parameters:
0: OBJECT - MapClickEventHandlerArgs
0: OBJECT - unit // useless
1: ARRAY<OBJECT> - sides
Returns:
VOID
*/
* Author: bux578
* Switches to a unit close to a clicked map position
*
* Arguments:
* 0: unit <OBJECT>
* 1: sides <ARRAY<OBJECT>>
*
* Return Value:
* None
*
* Example:
* [_unit, _sides] call FUNC(handleMapClick)
*
* Public: No
*/
#include "script_component.hpp"
private ["_sides", "_pos", "_sideNearest"];
// that's wrong
//_currentPlayerUnit = (_this select 0) select 0;
_sides = (_this select 0) select 1;
_pos = _this select 1;

View File

@ -1,19 +1,19 @@
/*
Name: ACE_SwitchUnits_fnc_initPlayer
Author(s):
bux578
Description:
Initializes the player
Parameters:
0: OBJECT - player
1: ARRAY<OBJECT> - Array containing selected sides
Returns:
VOID
*/
* Author: bux578
* Initializes the player
*
* Arguments:
* 0: player <OBJECT>
* 1: sides <ARRAY<OBJECT>>
*
* Return Value:
* None
*
* Example:
* [_player, _sides] call FUNC(initPlayer)
*
* Public: No
*/
#include "script_component.hpp"

View File

@ -1,22 +1,22 @@
/*
Name: ACE_SwitchUnits_fnc_isValidAi
Author(s):
bux578
Description:
Checks if AI is a valid target for switching
Parameters:
0: OBJECT - unit
Returns:
VOID
*/
* Author: bux578
* Checks if AI is a valid target for switching.
*
* Arguments:
* 0: unit <OBJECT>
*
* Return Value:
* Boolean
*
* Example:
* [_unit] call FUNC(isValidAi)
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_unit"];
private "_unit";
_unit = _this select 0;

View File

@ -1,38 +1,36 @@
/*
Name: ACE_SwitchUnits_fnc_markAiOnMap
Author(s):
bux578
Description:
Creates markers for AI units for given sides
Marks players in a different color
Parameters:
0: OBJECT - side
Returns:
VOID
*/
* Author: bux578
* Creates markers for AI units for given sides.
* Marks players in a different colour.
*
* Arguments:
* 0: side <OBJECT>
*
* Return Value:
* None
*
* Example:
* [west, east] call FUNC(markAiOnMap)
*
* Public: No
*/
#include "script_component.hpp"
private ["_sidesToShow"];
private "_sidesToShow";
_sidesToShow = _this select 0;
_sidesToShow spawn {
GVAR(AllMarkerNames) = [];
private ["_sides", "_allMarkerNames"];
_sides = _this;
_allMarkerNames = [];
while { true } do {
sleep 1.5;
DFUNC(pfhMarkAiOnMap) = {
private ["_args", "_sides"];
_args = _this select 0;
_sides = _args select 0;
// delete markers
{
deleteMarkerLocal _x;
} forEach _allMarkerNames;
} forEach GVAR(AllMarkerNames);
if (alive ACE_player && {GVAR(OriginalUnit) getVariable ["ACE_CanSwitchUnits", false]}) then {
@ -61,9 +59,10 @@ _sidesToShow spawn {
_markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName"));
};
_allMarkerNames pushBack _markerName;
GVAR(AllMarkerNames) pushBack _markerName;
};
} forEach allUnits;
};
};
};
[FUNC(pfhMarkAiOnMap), 1, _sidesToShow] call CBA_fnc_addPerFrameHandler;

View File

@ -1,20 +1,20 @@
/*
Name: ACE_SwitchUnits_fnc_module
Author(s):
bux578
Description:
Initializes the SwitchUnits module
Parameters:
0: OBJECT - module logic
1: ARRAY<OBJECT> - list of affected units
2: BOOLEAN - isActivated
Returns:
BOOLEAN (Good practice to include one)
*/
* Author: bux578
* Initializes the SwitchUnits module
*
* Arguments:
* 0: module logic <OBJECT>
* 1: list of affected units <ARRAY<OBJECT>>
* 2: isActivated <BOOLEAN>
*
* Return Value:
* None
*
* Example:
* None
*
* Public: No
*/
#include "script_component.hpp"

View File

@ -1,19 +1,19 @@
/*
Name: ACE_SwitchUnits_fnc_nearestPlayers
Author(s):
bux578
Description:
Returns an array of alive players in a given radius around a given location
Parameters:
0: POSTION - Center position
1: NUMBER - Radius
Returns:
ARRAY<OBJECT> - Player units
*/
* Author: bux578
* Returns an array of alive players in a given radius around a given location
*
* Arguments:
* 0: Center position <POSTION>
* 1: Radius <NUMBER>
*
* Return Value:
* Player units <ARRAY<OBJECT>>
*
* Example:
* [_pos, 100] call FUNC(nearestPlayers)
*
* Public: Yes
*/
#include "script_component.hpp"

View File

@ -1,31 +1,41 @@
/*
Name: ACE_SwitchUnits_fnc_switchBack
Author(s):
bux578
Description:
Switches back to the original player unit
This method needs to be "spawn"ed
Parameters:
0: OBJECT - original player unit
1: OBJECT - respawned unit
Returns:
VOID
*/
* Author: bux578
* Switches back to the original player unit
*
* Arguments:
* 0: Original player unit <OBJECT>
* 1: Respawned unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_origPlayer, _respPlayer] call FUNC(switchBack)
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_originalPlayerUnit", "_currentUnit"];
_originalPlayerUnit = _this select 0;
_currentUnit = _this select 1;
private ["_origPlayerUnit"];
[_originalPlayerUnit] joinSilent GVAR(OriginalGroup);
_origPlayerUnit = _this select 0;
[_origPlayerUnit] joinSilent GVAR(OriginalGroup);
waitUntil {local _originalPlayerUnit};
DFUNC(pfhSwitchBack) = {
selectPlayer _originalPlayerUnit;
private ["_args", "_originalPlayerUnit", "_currentUnit"];
deleteVehicle _currentUnit;
_args = _this select 0;
_originalPlayerUnit = _args select 0;
_currentUnit = _args select 1;
if (local _originalPlayerUnit) exitWith {
selectPlayer _originalPlayerUnit;
deleteVehicle _currentUnit;
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
};
[FUNC(pfhSwitchBack), 0.2, _this] call CBA_fnc_addPerFrameHandler;

View File

@ -1,36 +1,34 @@
/*
Name: ACE_SwitchUnits_fnc_switchUnit
* Author: bux578
* Switches to the new given player unit
*
* Arguments:
* 0: current unit <OBJECT>
* 1: the unit to switch to <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_unit] call FUNC(switchUnit)
*
* Public: Yes
*/
Author(s):
bux578
Description:
Selects the new given player unit
Parameters:
0: OBJECT - the unit to switch to
Returns:
VOID
*/
#include "script_component.hpp"
private ["_newUnit"];
private ["_unit", "_allNearestPlayers", "_oldUnit", "_leave"];
_newUnit = _this select 1;
_unit = _this select 1;
// don't switch to original player units
if (!([_newUnit] call FUNC(isValidAi))) exitWith {};
if (!([_unit] call FUNC(isValidAi))) exitWith {};
_newUnit spawn {
private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"];
// exit var
_leave = false;
_unit = _this;
_leave = false;
if (GVAR(EnableSafeZone)) then {
if (GVAR(EnableSafeZone)) then {
_allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers);
_nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(common,filter);
@ -38,20 +36,32 @@ _newUnit spawn {
if (count _nearestEnemyPlayers > 0) exitWith {
_leave = true;
};
};
// exitWith doesn't exit past the "if(EnableSafeZone)" block
if (_leave) exitWith {
};
// exitWith doesn't exit past the "if(EnableSafeZone)" block
if (_leave) exitWith {
[localize "STR_ACE_SwitchUnits_TooCloseToEnemy"] call EFUNC(common,displayTextStructured);
};
};
// should switch locality
// This doesn't work anymore, because one's now able to switch to units from a different side
//[_unit] joinSilent group player;
[[_unit, player], QUOTE({(_this select 0) setVariable [ARR_3(QUOTE(QGVAR(OriginalOwner)), owner (_this select 0), true)]; (_this select 0) setOwner owner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc);
// should switch locality
// This doesn't work anymore, because one's now able to switch to units from a different side
//[_unit] joinSilent group player;
[[_unit, player], QUOTE({(_this select 0) setVariable [ARR_3(QUOTE(QGVAR(OriginalOwner)), owner (_this select 0), true)]; (_this select 0) setOwner owner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc);
_oldUnit = player;
waitUntil {sleep 0.2; local _unit};
_oldUnit = player;
DFUNC(pfhSwitchUnit) = {
private ["_args", "_unit", "_oldUnit", "_respawnEhId", "_oldOwner"];
_args = _this select 0;
_unit = _args select 0;
_oldUnit = _args select 1;
if (local _unit) exitWith {
_oldUnit setVariable [QGVAR(IsPlayerControlled), false, true];
_oldUnit setVariable [QGVAR(PlayerControlledName), "", true];
@ -67,7 +77,7 @@ _newUnit spawn {
_unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true];
_respawnEhId = _unit addEventHandler ["Respawn", {
[GVAR(OriginalUnit), _this select 0] spawn FUNC(switchBack);
[GVAR(OriginalUnit), _this select 0] call FUNC(switchBack);
}];
_unit setVariable [QGVAR(RespawnEhId), _respawnEhId, true];
@ -78,4 +88,10 @@ _newUnit spawn {
};
[localize "STR_ACE_SwitchUnits_SwitchedUnit"] call EFUNC(common,displayTextStructured);
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
};
[FUNC(pfhSwitchBack), 0.2, [_unit, _oldUnit]] call cba_fnc_addPerFrameHandler;