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

Replace createVehicleCrew with fn_createCrew #963

Open
wants to merge 18 commits into
base: v0.96.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 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
1 change: 1 addition & 0 deletions Missionframework/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class KPLIB {
class createClearance {};
class createClearanceConfirm {};
class createCrate {};
class createCrew {};
class createManagedUnit {};
class crGetMulti {};
class crGlobalMsg {};
Expand Down
130 changes: 130 additions & 0 deletions Missionframework/functions/fn_createCrew.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
File: fn_createCrew.sqf
Author: PiG13BR - https://github.com/PiG13BR/
Date: 2024-26-08
Last Update: 2024-27-08
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
Creates vehicle crew based on preset configuration only

Parameter(s):
_vehicle - Vehicle to add crew
_side - crew side: KPLIB_side_enemy or KPLIB_side_player (Default: KPLIB_side_enemy)

Returns:
Array - [Crew created, group]
*/

params[
["_vehicle", objNull, [objNull]],
["_side", KPLIB_side_enemy,[sideUnknown]]
PiG13BR marked this conversation as resolved.
Show resolved Hide resolved
];

if (isNull _vehicle) exitWith {["No vehicle provided"] call BIS_fnc_error};

private _typeCrew = "";

// Placeholder types
switch (_side) do {
case KPLIB_side_enemy : {
_typeCrew = KPLIB_o_rifleman;
};
case KPLIB_side_player : {
_typeCrew = KPLIB_b_crewUnit;
}
};

/*
Save it for later changes
switch (_side) do {
case KPLIB_side_enemy : {
if (_vehicle isKindOf "Air") then {
_typeCrew = KPLIB_o_pilot;
} else {
if ((_vehicle isKindOf "Tank") || {_vehicle isKindOf "Wheeled_APC_F"}) then {
_typeCrew = KPLIB_o_crewman;
} else {
_typeCrew = KPLIB_o_rifleman;
}
}
};
case KPLIB_side_player : {
if (_vehicle isKindOf "Air") then {
_typeCrew = KPLIB_b_heliPilotUnit;
} else {
if ((_vehicle isKindOf "Tank") || {_vehicle isKindOf "Wheeled_APC_F"}) then {
_typeCrew = KPLIB_b_crewUnit;
} else {
_typeCrew = KPLIB_b_crewStatic;
}
}
}
};
*/

// Get all available sets from the vehicle
private _seats = fullCrew [_vehicle, "", true];
/*
Return example:
[
[<NULL-object>,"driver",-1,[],false,<NULL-object>,"$STR_POSITION_DRIVER"],
[<NULL-object>,"gunner",-1,[0],false,<NULL-object>,"$STR_POSITION_GUNNER"],
[<NULL-object>,"commander",-1,[0,0],false,<NULL-object>,"$STR_POSITION_COMMANDER"]
]
*/

private _grp = createGroup [_side, true];
private _allCrew = [];

{
_checkSeat = _x select 0; // Unit - For empty seat must retun <NULL-object>
_role = _x select 1; // Role - "driver", "gunner", "turret", "cargo", "commander"
_index = _x select 2; // Index - "-1", "0", "1", etc.
_turretPath = _x select 3; // Turret Path - [number]
_crew = objNull;

// If it's empty
if (isNull _checkSeat) then {

switch (_role) do {
case "driver" : {
_crew = [_typeCrew, getPos _vehicle, _grp] call KPLIB_fnc_createManagedUnit;
_crew assignAsDriver _vehicle;
_crew moveInDriver _vehicle;
};
case "gunner" : {
_crew = [_typeCrew, getPos _vehicle, _grp] call KPLIB_fnc_createManagedUnit;
_crew assignAsGunner _vehicle;
_crew moveInGunner _vehicle;
};
case "commander" : {
_crew = [_typeCrew, getPos _vehicle, _grp] call KPLIB_fnc_createManagedUnit;
_crew assignAsCommander _vehicle;
_crew moveInCommander _vehicle;
};
case "turret" : {
//Cargo index -1 = copilot (vanilla models)
if ((_vehicle isKindOf "Air") && (_index == -1)) then {
_crew = [_typeCrew, getPos _vehicle, _grp] call KPLIB_fnc_createManagedUnit;
_crew assignAsTurret [_vehicle, _turretPath];
_crew moveInTurret [_vehicle, _turretPath];
}
}
};

// Check if the vehicle crew spawned is in the vehicle, if not, delete it
if !(_crew in (crew _vehicle)) then {
deleteVehicle _crew;
} else {
_allCrew pushBack _crew;
_crew addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
}
}
}forEach _seats;
PiG13BR marked this conversation as resolved.
Show resolved Hide resolved

// Return all the vehicle crew and its group
[_allCrew,_grp]
PiG13BR marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 5 additions & 21 deletions Missionframework/functions/fn_forceBluforCrew.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File: fn_forceBluforCrew.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-11-25
Last Update: 2020-05-25
Last Update: 2024-08-27
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
Expand All @@ -22,26 +22,10 @@ params [

if (isNull _veh) exitWith {["Null object given"] call BIS_fnc_error; false};

// Create regular config crew
private _grp = createVehicleCrew _veh;

// If the config crew isn't the correct side, replace it with the crew classnames from the preset
if ((side _grp) != KPLIB_side_player) then {
{deleteVehicle _x} forEach (units _grp);

_grp = createGroup [KPLIB_side_player, true];
while {count units _grp < 3} do {
[KPLIB_b_crewUnit, getPos _veh, _grp] call KPLIB_fnc_createManagedUnit;
};
((units _grp) select 0) moveInDriver _veh;
((units _grp) select 1) moveInGunner _veh;
((units _grp) select 2) moveInCommander _veh;

// Delete crew which isn't in the vehicle due to e.g. no commander seat
{
if (isNull objectParent _x) then {deleteVehicle _x};
} forEach (units _grp);
};
// Create crew
_crew = [_veh, KPLIB_side_player] call KPLIB_fnc_createCrew;

_grp = _crew select 1;

// Set the crew to safe behaviour
_grp setBehaviour "SAFE";
Expand Down
12 changes: 2 additions & 10 deletions Missionframework/functions/fn_spawnVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File: fn_spawnVehicle.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-12-03
Last Update: 2023-10-28
Last Update: 2024-08-27
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
Expand Down Expand Up @@ -80,15 +80,7 @@ if (_classname in KPLIB_o_helicopters) then {
if (_classname in KPLIB_o_militiaVehicles) then {
[_newvehicle] call KPLIB_fnc_spawnMilitiaCrew;
} else {
private _grp = createGroup [KPLIB_side_enemy, true];
private _crew = units (createVehicleCrew _newvehicle);
_crew joinSilent _grp;
{
_x addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
} forEach _crew;
[_newvehicle, KPLIB_side_enemy] call KPLIB_fnc_createCrew;
};

// Add Killed and GetIn EHs and enable damage again
Expand Down
2 changes: 2 additions & 0 deletions Missionframework/presets/enemies/custom.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ KPLIB_o_aaSpecialist = "O_Soldier_AA_F"; // AA Sp
KPLIB_o_medic = "O_medic_F"; // Combat Life Saver
KPLIB_o_engineer = "O_engineer_F"; // Engineer
KPLIB_o_paratrooper = "O_soldier_PG_F"; // Paratrooper
KPLIB_o_crewman = "O_crew_F"; // Crewman
KPLIB_o_pilot = "O_helipilot_F"; // Pilot

// Enemy vehicles used by secondary objectives.
KPLIB_o_mrap = "O_MRAP_02_F"; // Ifrit
Expand Down
1 change: 1 addition & 0 deletions Missionframework/presets/players/custom.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ KPLIB_b_mobileRespawn = "B_Truck_01_medical_F"; // This
KPLIB_b_potato01 = "B_Heli_Transport_03_unarmed_F"; // This is Potato 01, a multipurpose mobile respawn as a helicopter.
KPLIB_b_crewUnit = "B_crew_F"; // This defines the crew for vehicles.
KPLIB_b_heliPilotUnit = "B_Helipilot_F"; // This defines the pilot for helicopters.
KPLIB_b_crewStatic = "B_Soldier_F"; // This defines the crew for static weapons and light vehicles
KPLIB_b_addHeli = "B_Heli_Light_01_F"; // These are the additional helicopters which spawn on the Freedom or at Chimera base.
KPLIB_b_addBoat = "B_Boat_Transport_01_F"; // These are the boats which spawn at the stern of the Freedom.
KPLIB_b_logiTruck = "B_Truck_01_transport_F"; // These are the trucks which are used in the logistic convoy system.
Expand Down
4 changes: 2 additions & 2 deletions Missionframework/scripts/client/misc/fn_initArsenal.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ if (KPLIB_param_useArsenalPreset) then {
if !(configProperties [configFile >> "CBA_DisposableLaunchers"] isEqualTo []) then {
private _disposableLaunchers = ["CBA_FakeLauncherMagazine"];
{
private _loadedLauncher = cba_disposable_LoadedLaunchers getVariable _x;
private _loadedLauncher = cba_disposable_LoadedLaunchers get _x;
if (!isNil "_loadedLauncher") then {
_disposableLaunchers pushBack _loadedLauncher;
};

private _normalLauncher = cba_disposable_NormalLaunchers getVariable _x;
private _normalLauncher = cba_disposable_NormalLaunchers get _x;
if (!isNil "_normalLauncher") then {
_normalLauncher params ["_loadedLauncher"];
_disposableLaunchers pushBack _loadedLauncher;
Expand Down
2 changes: 1 addition & 1 deletion Missionframework/scripts/server/battlegroup/spawn_air.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ for "_i" from 1 to _planes_number do {
_spawnPos = markerPos _spawnPoint;
_spawnPos = [(((_spawnPos select 0) + 500) - random 1000), (((_spawnPos select 1) + 500) - random 1000), 200];
_plane = createVehicle [_class, _spawnPos, [], 0, "FLY"];
createVehicleCrew _plane;
[_plane, KPLIB_side_enemy] call KPLIB_fnc_createCrew;
_plane flyInHeight (120 + (random 180));
[_plane] call KPLIB_fnc_addObjectInit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (isNull _chopper_type) then {
};

_newvehicle = createVehicle [_chopper_type, markerpos _spawnsector, [], 0, "FLY"];
createVehicleCrew _newvehicle;
[_newvehicle, KPLIB_side_enemy] call KPLIB_fnc_createCrew;
sleep 0.1;

_pilot_group = createGroup [KPLIB_side_enemy, true];
Expand Down