mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
e2ac18a05d
* advanced_ballistics * advanced_fatigue * advanced_throwing * ai * aircraft * arsenal * atragmx * attach * backpacks * ballistics * captives * cargo * chemlights * common * concertina_wire * cookoff * dagr * disarming * disposable * dogtags * dragging * explosives * fastroping * fcs * finger * frag * gestures * gforces * goggles * grenades * gunbag * hearing * hitreactions * huntir * interact_menu * interaction * inventory * kestrel4500 * laser * laserpointer * logistics_uavbattery * logistics_wirecutter * magazinerepack * map * map_gestures * maptools * markers * medical * medical_ai * medical_blood * medical_menu * microdagr * minedetector * missileguidance * missionmodules * mk6mortar * modules * movement * nametags * nightvision * nlaw * optics * optionsmenu * overheating * overpressure * parachute * pylons * quickmount * rangecard * rearm * recoil * refuel * reload * reloadlaunchers * repair * respawn * safemode * sandbag * scopes * slideshow * spectator * spottingscope * switchunits * tacticalladder * tagging * trenches * tripod * ui * vector * vehiclelock * vehicles * viewdistance * weaponselect * weather * winddeflection * yardage450 * zeus * arsenal defines.hpp * optionals * DEBUG_MODE_FULL 1 * DEBUG_MODE_FULL 2 * Manual fixes * Add SQF Validator check for #include after block comment * explosives fnc_openTimerUI * fix uniqueItems
83 lines
2.5 KiB
Plaintext
83 lines
2.5 KiB
Plaintext
#include "script_component.hpp"
|
|
/*
|
|
* Author: bux578
|
|
* Switches to the new given player unit
|
|
*
|
|
* Arguments:
|
|
* 0: the unit to switch to <OBJECT>
|
|
*
|
|
* Return Value:
|
|
* None
|
|
*
|
|
* Example:
|
|
* [_unit] call ace_switchunits_fnc_switchUnit
|
|
*
|
|
* Public: Yes
|
|
*/
|
|
|
|
params ["_unit"];
|
|
|
|
// don't switch to original player units
|
|
if (!([_unit] call FUNC(isValidAi))) exitWith {};
|
|
|
|
// exit var
|
|
private _leave = false;
|
|
|
|
if (GVAR(EnableSafeZone)) then {
|
|
private _allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers);
|
|
private _nearestEnemyPlayers = _allNearestPlayers select {((side GVAR(OriginalGroup)) getFriend side _x < 0.6) && !(_x getVariable [QGVAR(IsPlayerControlled), false])};
|
|
|
|
if (count _nearestEnemyPlayers > 0) exitWith {
|
|
_leave = true;
|
|
};
|
|
};
|
|
|
|
// exitWith doesn't exit past the "if(EnableSafeZone)" block
|
|
if (_leave) exitWith {
|
|
[localize LSTRING(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;
|
|
[QGVAR(switchLocality), [_unit, player]] call CBA_fnc_serverEvent;
|
|
|
|
[{
|
|
params ["_args", "_pfhId"];
|
|
_args params ["_unit", "_oldUnit"];
|
|
|
|
[localize LSTRING(TryingToSwitch)] call EFUNC(common,displayTextStructured);
|
|
|
|
if (local _unit) exitWith {
|
|
_oldUnit setVariable [QGVAR(IsPlayerControlled), false, true];
|
|
_oldUnit setVariable [QGVAR(PlayerControlledName), "", true];
|
|
|
|
private _killedEhId = _unit getVariable [QGVAR(KilledEhId), -1];
|
|
if (_killedEhId != -1) then {
|
|
_oldUnit removeEventHandler ["Killed", _killedEhId];
|
|
};
|
|
|
|
selectPlayer _unit;
|
|
|
|
_unit setVariable [QGVAR(IsPlayerControlled), true, true];
|
|
_unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true];
|
|
|
|
|
|
_killedEhId = _unit addEventHandler ["Killed", {
|
|
[GVAR(OriginalUnit), _this select 0] call FUNC(switchBack);
|
|
}];
|
|
_unit setVariable [QGVAR(KilledEhId), _killedEhId, true];
|
|
|
|
|
|
// set owner back to original owner
|
|
private _oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1];
|
|
if (_oldOwner > -1) then {
|
|
["ace_setOwner", [_oldUnit, _oldOwner]] call CBA_fnc_serverEvent;
|
|
};
|
|
|
|
[localize LSTRING(SwitchedUnit)] call EFUNC(common,displayTextStructured);
|
|
|
|
[_pfhId] call CBA_fnc_removePerFrameHandler;
|
|
};
|
|
}, 0.2, [_unit, player]] call CBA_fnc_addPerFrameHandler;
|