mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
init
This commit is contained in:
parent
bb194e6e93
commit
f3427938b3
5
addons/switchunits/CfgEventHandlers.hpp
Normal file
5
addons/switchunits/CfgEventHandlers.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
class Extended_PreInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_preInit.sqf) );
|
||||
};
|
||||
};
|
BIN
addons/switchunits/UI/IconSwitchUnits_ca.paa
Normal file
BIN
addons/switchunits/UI/IconSwitchUnits_ca.paa
Normal file
Binary file not shown.
11
addons/switchunits/XEH_preInit.sqf
Normal file
11
addons/switchunits/XEH_preInit.sqf
Normal file
@ -0,0 +1,11 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
PREP(addMapFunction);
|
||||
PREP(handleMapClick);
|
||||
PREP(initPlayer);
|
||||
PREP(isValidAi);
|
||||
PREP(markAiOnMap);
|
||||
PREP(module);
|
||||
PREP(nearestPlayers);
|
||||
PREP(switchBack);
|
||||
PREP(switchUnit);
|
17
addons/switchunits/config.cpp
Normal file
17
addons/switchunits/config.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
class CfgPatches {
|
||||
class ADDON {
|
||||
units[] = {};
|
||||
weapons[] = {};
|
||||
requiredVersion = 0.60;
|
||||
requiredAddons[] = {"ace_core"};
|
||||
version = "0.95";
|
||||
versionStr = "0.95";
|
||||
versionAr[] = {0,95,0};
|
||||
author[] = {""};
|
||||
authorUrl = "";
|
||||
};
|
||||
};
|
||||
|
||||
#include "CfgEventHandlers.hpp"
|
23
addons/switchunits/functions/fnc_addMapFunction.sqf
Normal file
23
addons/switchunits/functions/fnc_addMapFunction.sqf
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
Name: AGM_SwitchUnits_fnc_addMapFunction
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Adds a mapClick Eventhandler
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - unit
|
||||
1: ARRAY<OBJECT> - sided
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
|
||||
private ["_unit"];
|
||||
_unit = _this select 0;
|
||||
|
||||
["theMapClick", "onMapSingleClick", {
|
||||
[_this, _pos, _shift, _alt] call AGM_SwitchUnits_fnc_handleMapClick;
|
||||
}, [_unit, _sides]] call BIS_fnc_addStackedEventHandler;
|
41
addons/switchunits/functions/fnc_handleMapClick.sqf
Normal file
41
addons/switchunits/functions/fnc_handleMapClick.sqf
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Name: AGM_SwitchUnits_fnc_handleMapClick
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Finds the clicked unit
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - MapClickEventHandlerArgs
|
||||
0: OBJECT - unit to switch to
|
||||
1: ARRAY<OBJECT> - sides
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
|
||||
private ["_args", "_currentPlayerUnit", "_sides", "_pos", "_sideNearest"];
|
||||
|
||||
_currentPlayerUnit = (_this select 0) select 0;
|
||||
_sides = (_this select 0) select 1;
|
||||
_pos = _this select 1;
|
||||
|
||||
_sideNearest = [];
|
||||
|
||||
{
|
||||
if ([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) then {
|
||||
_sideNearest pushBack _x;
|
||||
};
|
||||
} forEach (nearestObjects [_pos, ["Man"], 20]);
|
||||
|
||||
|
||||
if (count _sideNearest > 0) then {
|
||||
private ["_switchUnit"];
|
||||
|
||||
_switchUnit = _sideNearest select 0;
|
||||
[_currentPlayerUnit, _switchUnit] call AGM_SwitchUnits_fnc_switchUnit;
|
||||
|
||||
openMap false;
|
||||
};
|
48
addons/switchunits/functions/fnc_initPlayer.sqf
Normal file
48
addons/switchunits/functions/fnc_initPlayer.sqf
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Name: AGM_SwitchUnits_fnc_initPlayer
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Initializes the player
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - player
|
||||
1: ARRAY<OBJECT> - Array containing selected sides
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
|
||||
private ["_playerUnit", "_sides"];
|
||||
|
||||
_playerUnit = _this select 0;
|
||||
_sides = _this select 1;
|
||||
|
||||
if (vehicle _playerUnit == _playerUnit) then {
|
||||
|
||||
[_sides] call AGM_SwitchUnits_fnc_markAiOnMap;
|
||||
|
||||
_playerUnit setVariable ["AGM_SwitchUnits_IsPlayerUnit", true];
|
||||
_playerUnit allowDamage false;
|
||||
|
||||
AGM_SwitchUnits_OriginalUnit = _playerUnit;
|
||||
AGM_SwitchUnits_OriginalName = [_playerUnit] call AGM_Core_fnc_getName;
|
||||
AGM_SwitchUnits_OriginalGroup = group _playerUnit;
|
||||
|
||||
// remove all starting gear of a player
|
||||
removeAllWeapons _playerUnit;
|
||||
removeGoggles _playerUnit;
|
||||
removeHeadgear _playerUnit;
|
||||
removeVest _playerUnit;
|
||||
removeAllAssignedItems _playerUnit;
|
||||
clearAllItemsFromBackpack _playerUnit;
|
||||
removeBackpack _playerUnit;
|
||||
_playerUnit linkItem "ItemMap";
|
||||
removeUniform _playerUnit;
|
||||
|
||||
[_playerUnit, "AGM_SwitchUnits", true] call AGM_Core_fnc_setForceWalkStatus;
|
||||
|
||||
[_playerUnit, _sides] call AGM_SwitchUnits_fnc_addMapFunction;
|
||||
};
|
25
addons/switchunits/functions/fnc_isValidAi.sqf
Normal file
25
addons/switchunits/functions/fnc_isValidAi.sqf
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Name: AGM_SwitchUnits_fnc_isValidAi
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Checks if AI is a valid target for switching
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - unit
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
|
||||
private ["_unit"];
|
||||
|
||||
_unit = _this select 0;
|
||||
|
||||
!([_unit] call AGM_Core_fnc_isPlayer
|
||||
|| {_unit in playableUnits}
|
||||
|| {vehicle _unit != _unit}
|
||||
|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerUnit", false]}
|
||||
|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerControlled", false]})
|
64
addons/switchunits/functions/fnc_markAiOnMap.sqf
Normal file
64
addons/switchunits/functions/fnc_markAiOnMap.sqf
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
Name: AGM_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
|
||||
*/
|
||||
|
||||
private ["_sidesToShow"];
|
||||
_sidesToShow = _this select 0;
|
||||
|
||||
_sidesToShow spawn {
|
||||
|
||||
private ["_sides", "_allMarkerNames"];
|
||||
_sides = _this;
|
||||
_allMarkerNames = [];
|
||||
|
||||
while { true } do {
|
||||
sleep 1.5;
|
||||
|
||||
// delete markers
|
||||
{
|
||||
deleteMarkerLocal _x;
|
||||
} forEach _allMarkerNames;
|
||||
|
||||
// create markers
|
||||
{
|
||||
if (([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) || (_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then {
|
||||
private ["_markerName", "_marker", "_markerColor"];
|
||||
|
||||
//_markerName = format ["%1", [_x] call AGM_Core_fnc_getName];
|
||||
_markerName = str _x;
|
||||
|
||||
_marker = createMarkerLocal [_markerName, position _x];
|
||||
_markerName setMarkerTypeLocal "mil_triangle";
|
||||
_markerName setMarkerShapeLocal "ICON";
|
||||
_markerName setMarkerSizeLocal [0.5,0.7];
|
||||
_markerName setMarkerDirLocal getDir _x;
|
||||
|
||||
// commy's one liner magic
|
||||
_markerColor = format ["Color%1", side group _x];
|
||||
|
||||
if ((_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then {
|
||||
_markerName setMarkerColorLocal "ColorOrange";
|
||||
_markerName setMarkerTextLocal (_x getVariable ["AGM_SwitchUnits_PlayerControlledName",""]);
|
||||
} else {
|
||||
_markerName setMarkerColorLocal _markerColor;
|
||||
_markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName"));
|
||||
};
|
||||
|
||||
_allMarkerNames pushBack _markerName;
|
||||
};
|
||||
} forEach allUnits;
|
||||
};
|
||||
};
|
38
addons/switchunits/functions/fnc_module.sqf
Normal file
38
addons/switchunits/functions/fnc_module.sqf
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Name: AGM_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)
|
||||
*/
|
||||
|
||||
if !(isServer) exitWith {};
|
||||
|
||||
_logic = _this select 0;
|
||||
_activated = _this select 2;
|
||||
|
||||
if !(_activated) exitWith {};
|
||||
|
||||
AGM_SwitchUnits_Module = true;
|
||||
|
||||
["AGM_SwitchUnits_EnableSwitchUnits", true] call AGM_Core_fnc_setParameter;
|
||||
|
||||
[_logic, "AGM_SwitchUnits_SwitchToWest", "SwitchToWest"] call AGM_Core_fnc_readBooleanParameterFromModule;
|
||||
[_logic, "AGM_SwitchUnits_SwitchToEast", "SwitchToEast"] call AGM_Core_fnc_readBooleanParameterFromModule;
|
||||
[_logic, "AGM_SwitchUnits_SwitchToIndependent", "SwitchToIndependent"] call AGM_Core_fnc_readBooleanParameterFromModule;
|
||||
[_logic, "AGM_SwitchUnits_SwitchToCivilian", "SwitchToCivilian"] call AGM_Core_fnc_readBooleanParameterFromModule;
|
||||
|
||||
[_logic, "AGM_SwitchUnits_EnableSafeZone", "EnableSafeZone"] call AGM_Core_fnc_readBooleanParameterFromModule;
|
||||
[_logic, "AGM_SwitchUnits_SafeZoneRadius", "SafeZoneRadius"] call AGM_Core_fnc_readNumericParameterFromModule;
|
||||
|
||||
diag_log text "[AGM]: SwitchUnits Module Initialized.";
|
31
addons/switchunits/functions/fnc_nearestPlayers.sqf
Normal file
31
addons/switchunits/functions/fnc_nearestPlayers.sqf
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
Name: AGM_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
|
||||
*/
|
||||
|
||||
private ["_position", "_radius", "_nearestPlayers"];
|
||||
|
||||
_position = _this select 0;
|
||||
_radius = _this select 1;
|
||||
|
||||
_nearestPlayers = [];
|
||||
|
||||
{
|
||||
if ([_x] call AGM_Core_fnc_isPlayer && {alive _x}) then {
|
||||
_nearestPlayers pushBack _x;
|
||||
};
|
||||
} forEach (nearestObjects [_position, ["Man"], _radius]);
|
||||
|
||||
_nearestPlayers
|
29
addons/switchunits/functions/fnc_switchBack.sqf
Normal file
29
addons/switchunits/functions/fnc_switchBack.sqf
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Name: AGM_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
|
||||
*/
|
||||
|
||||
private ["_originalPlayerUnit", "_currentUnit"];
|
||||
_originalPlayerUnit = _this select 0;
|
||||
_currentUnit = _this select 1;
|
||||
|
||||
[_originalPlayerUnit] joinSilent AGM_SwitchUnits_OriginalGroup;
|
||||
|
||||
waitUntil {local _originalPlayerUnit};
|
||||
|
||||
selectPlayer _originalPlayerUnit;
|
||||
|
||||
deleteVehicle _currentUnit;
|
79
addons/switchunits/functions/fnc_switchUnit.sqf
Normal file
79
addons/switchunits/functions/fnc_switchUnit.sqf
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
Name: AGM_SwitchUnits_fnc_switchUnit
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Selects the new given player unit
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - the unit to switch to
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
|
||||
private ["_newUnit"];
|
||||
|
||||
_newUnit = _this select 1;
|
||||
|
||||
// don't switch to original player units
|
||||
if (!([_newUnit] call AGM_SwitchUnits_fnc_isValidAi)) exitWith {};
|
||||
|
||||
_newUnit spawn {
|
||||
private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"];
|
||||
|
||||
_unit = _this;
|
||||
|
||||
_leave = false;
|
||||
|
||||
if (AGM_SwitchUnits_EnableSafeZone) then {
|
||||
|
||||
_allNearestPlayers = [position _unit, AGM_SwitchUnits_SafeZoneRadius] call AGM_SwitchUnits_fnc_nearestPlayers;
|
||||
_nearestEnemyPlayers = [_allNearestPlayers, {((side AGM_SwitchUnits_OriginalGroup) getFriend (side _this) < 0.6) && !(_this getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])}] call AGM_Core_fnc_filter;
|
||||
|
||||
if (count _nearestEnemyPlayers > 0) exitWith {
|
||||
_leave = true;
|
||||
};
|
||||
};
|
||||
|
||||
// exitWith doesn't exit past the "if(EnableSafeZone)" block
|
||||
if (_leave) exitWith {
|
||||
[localize "STR_AGM_SwitchUnits_TooCloseToEnemy"] call AGM_Core_fnc_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], "{(_this select 0) setVariable ['AGM_SwitchUnits_OriginalOwner', owner (_this select 0), true]; (_this select 0) setOwner owner (_this select 1)}", 1] call AGM_Core_fnc_execRemoteFnc;
|
||||
|
||||
_oldUnit = player;
|
||||
waitUntil {sleep 0.2; local _unit};
|
||||
|
||||
_oldUnit setVariable ["AGM_SwitchUnits_IsPlayerControlled", false, true];
|
||||
_oldUnit setVariable ["AGM_SwitchUnits_PlayerControlledName", "", true];
|
||||
|
||||
_respawnEhId = _unit getVariable ["AGM_SwitchUnits_RespawnEhId", -1];
|
||||
if (_respawnEhId != -1) then {
|
||||
_oldUnit removeEventHandler ["Respawn", _respawnEhId];
|
||||
};
|
||||
|
||||
selectPlayer _unit;
|
||||
|
||||
_unit setVariable ["AGM_SwitchUnits_IsPlayerControlled", true, true];
|
||||
_unit setVariable ["AGM_SwitchUnits_PlayerControlledName", AGM_SwitchUnits_OriginalName, true];
|
||||
|
||||
_respawnEhId = _unit addEventHandler ["Respawn", {
|
||||
[AGM_SwitchUnits_OriginalUnit, _this select 0] spawn AGM_SwitchUnits_fnc_switchBack;
|
||||
}];
|
||||
_unit setVariable ["AGM_SwitchUnits_RespawnEhId", _respawnEhId, true];
|
||||
|
||||
// set owner back to original owner
|
||||
_oldOwner = _oldUnit getVariable["AGM_SwitchUnits_OriginalOwner", -1];
|
||||
if (_oldOwner > -1) then {
|
||||
[[_oldUnit, _oldOwner], "{(_this select 0) setOwner (_this select 1)}", 1] call AGM_Core_fnc_execRemoteFnc;
|
||||
};
|
||||
|
||||
[localize "STR_AGM_SwitchUnits_SwitchedUnit"] call AGM_Core_fnc_displayTextStructured;
|
||||
};
|
12
addons/switchunits/script_component.hpp
Normal file
12
addons/switchunits/script_component.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#define COMPONENT blank
|
||||
#include "\z\ace\addons\main\script_mod.hpp"
|
||||
|
||||
#ifdef DEBUG_ENABLED_BLANK
|
||||
#define DEBUG_MODE_FULL
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_SETTINGS_BLANK
|
||||
#define DEBUG_SETTINGS DEBUG_SETTINGS_BLANK
|
||||
#endif
|
||||
|
||||
#include "\z\ace\addons\main\script_macros.hpp"
|
Loading…
Reference in New Issue
Block a user