Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of Gear_Selection Module #159

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 48 additions & 35 deletions modules/EG_Spectator_Mode/init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ if (!isDedicated) then {
};
};
};

eg_keyHandler_display_hidden = false;

eg_keyHandler = {
params ["_control", "_code", "_shift", "_control", "_alt"];

Expand All @@ -34,25 +34,25 @@ if (!isDedicated) then {
call _action;
};
};

if (_code == 35 && !_shift && _control && !_alt) then {
if (!eg_keyHandler_display_hidden) then {
(findDisplay 60492) closedisplay 1;
eg_keyHandler_display_hidden = true;
};
};
};

eg_keyHandler2 = {
params ["_control", "_code", "_shift", "_control", "_alt"];

if (_code == 35 && !_shift && _control && !_alt &&
!isNil "eg_keyHandler_display_hidden" &&
{eg_keyHandler_display_hidden}
) then {
([] call BIS_fnc_displayMission) createDisplay "RscDisplayEGSpectator";
eg_keyHandler_display_hidden = false;

eg_keyHandle = (findDisplay 60492) displayAddEventHandler ["keyDown", {call eg_keyHandler;}];
if (killcam_active) then {
killcam_keyHandle = (findDisplay 60492) displayAddEventHandler ["keyDown", {call killcam_toggleFnc;}];
Expand Down Expand Up @@ -82,10 +82,10 @@ if (!isDedicated) then {
params ["_unit", "_killer"];
//let's remove hit EH, it's not needed
player removeEventHandler ["hit", killcam_hitHandle];

//we check if player didn't kill himself or died for unknown reasons
if (vehicle _killer != vehicle _unit && _killer != objNull) then {

//this is the standard case (killed EH got triggered by getting shot)
DEBUG_MSG("using killed EH")
killcam_unit_pos = ASLtoAGL eyePos _unit;
Expand All @@ -98,7 +98,7 @@ if (!isDedicated) then {
if (!isNil "killcam_LastHit") then {
_last_hit_info = killcam_LastHit;
};

//hit info retrieved, now we check if it's not caused by fall damage etc.
//also we won't use info that's over 10 seconds old
private _damage = 0.5;
Expand Down Expand Up @@ -141,9 +141,9 @@ if (!isDedicated) then {
sleep 1.01-_damage;
0 fadeSound 0;
sleep 0.89+_damage;

["<t color='#FF0000'>YOU ARE DEAD</t>", 0, 0.4, 2, 0.5, 0, 1000] spawn BIS_fnc_dynamicText;

sleep 3;
cutText ["\n","BLACK IN", 5];
["FW_death", 0, false] call ace_common_fnc_setHearingCapability;
Expand All @@ -164,7 +164,7 @@ if (!isDedicated) then {
call BIS_fnc_VRFadeIn;
};
};

}];
//END OF KILLED EH///////////

Expand Down Expand Up @@ -197,14 +197,14 @@ if (!isDedicated) then {

cutText [format ['%1 %2', FW_RespawnTickets, _text], 'PLAIN DOWN'];
player setVariable ["FW_Body", player, true];
}
}
else {

player setVariable ["FW_Dead", true, true]; //Tells the framework the player is dead

player remoteExecCall ["hideObject", 0];
player remoteExecCall ["hideObjectGlobal", 2];

player setCaptive true;
player allowdamage false;
[player, true] remoteExec ["setCaptive", 2];
Expand All @@ -221,10 +221,23 @@ if (!isDedicated) then {
player setVariable ["FW_Spectating", true, true];
[true] call acre_api_fnc_setSpectator;

//If babel is enabled, allowed spectator to hear all languages present in mission.
if (!isNil "FW_enable_babel" && FW_enable_babel) then {
Copy link
Collaborator

@BlackHawkPL BlackHawkPL Jan 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add lazy evaluation (wrap FW_enable_babel in {}) to avoid game trying to retrieve value even if it's nil.

_missionLanguages = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add private

{
{
if (!(_x in _missionLanguages)) then {
_missionLanguages pushback _x;
};
} foreach _x;
} forEach FW_languages_babel;
_missionLanguages call acre_api_fnc_babelSetSpokenLanguages;
};

//we set default pos in case all methods fail and we end up with 0,0,0
_pos = [2000, 2000, 100];
_dir = 0;

//our function is called from Respawned EH, so select 1 is player's body
_body = (_this select 1);
if (getMarkerColor eg_spectator_marker == "") then {
Expand All @@ -236,12 +249,12 @@ if (!isDedicated) then {
} else {
_pos = getmarkerpos eg_spectator_marker;
};

if (abs(_pos select 0) < 2 && abs(_pos select 1) < 2) then {
_pos = [2000, 2000, 100];
};

["Initialize",
["Initialize",
[
player,
eg_Whitelisted_Sides,
Expand All @@ -255,18 +268,18 @@ if (!isDedicated) then {
eg_Show_Entities_And_Locations_Lists
]
] call BIS_fnc_EGSpectator;

_cam = missionNamespace getVariable ["BIS_EGSpectatorCamera_camera", objNull];

if (_cam != objNull) then {

[{!isNull (findDisplay 60492)}, {
DEBUG_MSG("Display loaded, attaching key EH")
eg_keyHandle = (findDisplay 60492) displayAddEventHandler ["keyDown", {call eg_keyHandler;}];
eg_keyHandle = (findDisplay 46) displayAddEventHandler ["keyDown", {call eg_keyHandler2}];
}, []] call CBA_fnc_waitUntilAndExecute;


if (!killcam_active) then {
//we move 2 meters back so player's body is visible
_pos = ([_pos, -2, _dir] call BIS_fnc_relPos);
Expand All @@ -275,23 +288,23 @@ if (!isDedicated) then {
}
else {
missionNamespace setVariable ["killcam_toggle", false];

//this cool piece of code adds key handler to spectator display
//it takes some time for display to create, so we have to delay it.
[{!isNull (findDisplay 60492)}, {
DEBUG_MSG("Display loaded, attaching key EH")
killcam_keyHandle = (findDisplay 60492) displayAddEventHandler ["keyDown", {call killcam_toggleFnc;}];
}, []] call CBA_fnc_waitUntilAndExecute;

if (!isNull killcam_killer) then {
DEBUG_MSG("found valid killer")
_pos = ([_pos, -1.8, ([(_this select 1), killcam_killer] call BIS_fnc_dirTo)] call BIS_fnc_relPos);
_cam setposATL _pos;

//vector magic
_temp1 = ([getposASL _cam, getposASL killcam_killer] call BIS_fnc_vectorFromXToY);
_temp = (_temp1 call CBA_fnc_vect2Polar);

//we check if camera is not pointing up, just in case
if (abs(_temp select 2) > 89) then {_temp set [2, 0]};
[_cam, [_temp select 1, _temp select 2]] call BIS_fnc_setObjectRotation;
Expand All @@ -301,15 +314,15 @@ if (!isDedicated) then {
_cam setposATL _pos;
_cam setDir _dir;
};

killcam_texture = "a3\ui_f\data\gui\cfg\debriefing\enddeath_ca.paa";

killcam_drawHandle = addMissionEventHandler ["Draw3D", {
//we don't draw hud unless we toggle it by keypress
if (missionNamespace getVariable ["killcam_toggle", false]) then {

if ((killcam_killer_pos select 0) != 0) then {

_u = killcam_unit_pos;
_k = killcam_killer_pos;
if ((_u distance _k) < 2000) then {
Expand All @@ -331,16 +344,16 @@ if (!isDedicated) then {
}];//draw EH
};//killcam (not) active
};//checking camera

_killcam_msg = "";
if (killcam_active) then {
_killcam_msg = "Press <t color='#FFA500'>K</t> to toggle indicator showing location where you were killed from.<br/>";
};
_text = format ["<t size='0.5' color='#ffffff'>%1
Close spectator HUD by pressing <t color='#FFA500'>CTRL+H</t>.<br/>
Press <t color='#FFA500'>SHIFT</t>, <t color='#FFA500'>ALT</t> or <t color='#FFA500'>SHIFT+ALT</t> to modify camera speed. Open map by pressing <t color='#FFA500'>M</t> and click anywhere to move camera to that postion.<br/>
Press <t color='#FFA500'>SHIFT</t>, <t color='#FFA500'>ALT</t> or <t color='#FFA500'>SHIFT+ALT</t> to modify camera speed. Open map by pressing <t color='#FFA500'>M</t> and click anywhere to move camera to that postion.<br/>
Spectator controls can be customized in game <t color='#FFA500'>options->controls->'Camera'</t> tab.</t>", _killcam_msg];

[_text, 0.55, 0.8, 20, 1] spawn BIS_fnc_dynamicText;

[] spawn {
Expand Down
69 changes: 55 additions & 14 deletions modules/ai_drivers/init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "settings.sqf"

aidrivers_toggle = {
params ["_target", "_caller", "_id"];
params ["_target", "_caller"];
if (!isNull (_target getVariable ["aidrivers_driver", objNull])) then {
[_target] call aidrivers_removeUnit;
} else {
Expand All @@ -18,13 +18,22 @@ aidrivers_removeUnit = {

if (!isNull _driver) then {
deleteVehicle _driver;
private _handle = _target getVariable ["aidrivers_pfhID", -1];
if (_handle != -1) then {
[_handle] call CBA_fnc_removePerFrameHandler;
};
_target removeEventHandler ["getIn", _target getVariable ["aidrivers_getInID", -1]];
};
hint "Driver removed";
};

aidrivers_createUnit = {
params ["_target", "_caller"];

if (!isNull driver _target) exitWith {};
private _turret = (assignedVehicleRole _player) select 1;
_caller moveInDriver _target;
_caller moveInTurret [_target, _turret];

private _class = "B_Soldier_F";
if (side _caller == EAST) then {
Expand All @@ -33,32 +42,64 @@ aidrivers_createUnit = {
if (side _caller == INDEPENDENT) then {
_class = "I_Soldier_F";
};

_unit = group _caller createUnit [_class, [0,0,0], [], 0, "CAN_COLLIDE"];

_target setVariable ["aidrivers_driver", _unit];
_unit = createAgent [_class, [0,0,0], [], 0, "CAN_COLLIDE"];

removeAllWeapons _unit;
removeUniform _unit;
removeVest _unit;
removeHeadgear _unit;
removeGoggles _unit;

_unit forceAddUniform uniform _caller;
_unit addVest vest _caller;
_unit addHeadGear headGear _caller;

_target setVariable ["aidrivers_driver", _unit];

_unit moveInDriver _target;
_unit setBehaviour "COMBAT";

[{vehicle (_this select 0) != _this select 0}, {
(_this select 1) params ["_unit", "_target", "_caller", "_id2"];
[{
(_this select 0) params ["_unit", "_target", "_caller", "_id2"];
doStop _unit;

private _getInID = _target addEventHandler ["GetIn", {
params ["_vehicle", "_position", "_unit"];
if (!isNull (_target getVariable ["aidrivers_driver", objNull])) then {
(_target getVariable ["aidrivers_driver", objNull]) setDamage 1;
hint "Existing AI driver has been removed";
};
}];
_target setVariable ["aidrivers_getInID", _getInID];

[{vehicle (_this select 0) != _this select 0}, { //waiting for spawned unit to get into vehicle
private _pfhID = [{
_this select 0 params ["_unit", "_target", "_caller"];

private _handle = _this select 1;
if (vehicle _caller != _target) then {
_unit disableAI "PATH";
doStop _unit;
} else {
_unit enableAI "PATH";
};
if (!alive _target || !alive _caller || !alive _unit || (vehicle _unit) != _target || (driver _target) != _unit) then {
[_target, _caller] call aidrivers_removeUnit;
[_handle] call CBA_fnc_removePerFrameHandler;
};
}, 1, [_unit, _target, _caller, _id2]] call CBA_fnc_addPerFrameHandler;
}, [_unit, [_unit, _target, _caller, _id2]]] call CBA_fnc_WaitUntilAndExecute;

}, 1, _this] call CBA_fnc_addPerFrameHandler;
(_this select 1) setVariable ["aidrivers_pfhID", _pfhID];
}, [_unit, _target, _caller]] call CBA_fnc_WaitUntilAndExecute;

hint "Driver added";

};

private _action = ["ai_driver","Add/Remove AI driver","",{
[_target, _player] call aidrivers_toggle;
},
{
vehicle _player == _target && ((assignedVehicleRole _player) select 0) == "Turret"
}] call ace_interact_menu_fnc_createAction;

{
_x addAction ["Add/Remove AI driver", {_this remoteExecCall ["aidrivers_toggle", 2, false];}, [], 0, false, true, "", "vehicle _this == _target"];
} foreach VEHS;
[_x, 1, ["ACE_SelfActions"], _action] call ace_interact_menu_fnc_addActionToObject;
} foreach VEHS;
18 changes: 18 additions & 0 deletions modules/gear_selection/root.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifdef framework

#include "scripts\init.sqf"

#endif

#ifdef description_functions

#include "scripts\functions.hpp"

#endif

#ifdef description

#include "scripts\defines.hpp"
#include "scripts\gearSelection.hpp"

#endif
Loading