Skip to content

Commit

Permalink
Merge pull request #939 from KillahPotatoes/v0.96.8-pr-killManager
Browse files Browse the repository at this point in the history
Replace kill manager with cba server event
  • Loading branch information
some-evil-kitty authored Oct 29, 2023
2 parents d1136d9 + e4d4f8d commit 6cc1b74
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 45 deletions.
3 changes: 3 additions & 0 deletions Missionframework/KPLIB_config.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,6 @@ KPLIB_surrender_chance = 80;
KPLIB_battlegroup_clearance = [
"song_bin_tanh"
];

// Delay after death for wrecks and corpses to be deleted
KPLIB_cleanup_delay = 1200;
8 changes: 6 additions & 2 deletions Missionframework/functions/fn_createManagedUnit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File: fn_createManagedUnit.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-10-04
Last Update: 2019-12-04
Last Update: 2023-10-28
License: MIT License - http://www.opensource.org/licenses/MIT
Description:
Expand Down Expand Up @@ -34,7 +34,11 @@ isNil {
private _groupTemp = createGroup [CIVILIAN, true];

_unit = _groupTemp createUnit [_type, _spawnPos, [], _placement, "FORM"];
_unit addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
_unit addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];

_unit setRank _rank;

// Join to target group to preserve Side
Expand Down
12 changes: 9 additions & 3 deletions Missionframework/functions/fn_handlePlacedZeusObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File: fn_handlePlacedZeusObject.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2020-04-11
Last Update: 2020-05-10
Last Update: 2023-10-28
License: MIT License - http://www.opensource.org/licenses/MIT
Description:
Expand Down Expand Up @@ -32,14 +32,20 @@ if (_vehicle) then {

// Add kill manager and object init to possible crew units
{
_x addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
_x addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
[_x] call KPLIB_fnc_addObjectInit;
} forEach (crew _obj);
};

// Apply kill manager, if it's not a crate
if !(_crate) then {
_obj addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
_obj addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
} else {
// Otherwise apply all needed values/functionalities
_obj setMass 500;
Expand Down
16 changes: 12 additions & 4 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: 2020-05-15
Last Update: 2023-10-28
License: MIT License - http://www.opensource.org/licenses/MIT
Description:
Expand Down Expand Up @@ -84,11 +84,19 @@ if (_classname in KPLIB_o_militiaVehicles) then {
private _crew = units (createVehicleCrew _newvehicle);
_crew joinSilent _grp;
sleep 0.1;
{_x addMPEventHandler ["MPKilled", {_this spawn kill_manager}];} forEach _crew;
{
_x addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
} forEach _crew;
};

// Add MPKilled and GetIn EHs and enable damage again
_newvehicle addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
// Add Killed and GetIn EHs and enable damage again
_newvehicle addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
sleep 0.1;
_newvehicle allowDamage true;
_newvehicle setDamage 0;
Expand Down
19 changes: 14 additions & 5 deletions Missionframework/scripts/client/build/do_build.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ while { true } do {
if ( manned ) then {
_grp = createGroup KPLIB_side_player;
};
_classname createUnit [_pos, _grp,"this addMPEventHandler [""MPKilled"", {_this spawn kill_manager}]", 0.5, "private"];
_classname createUnit [_pos, _grp,"this addMPEventHandler ['MPKilled', {['KPLIB_manageKills', _this] call CBA_fnc_localEvent}]", 0.5, "private"];
build_confirmed = 0;
} else {
if ( buildtype == 8 ) then {
Expand All @@ -65,9 +65,9 @@ while { true } do {
if(_idx == 0) then { _unitrank = "sergeant"; };
if(_idx == 1) then { _unitrank = "corporal"; };
if (_classname isEqualTo KPLIB_b_squadPara) then {
_x createUnit [_pos, _grp,"this addMPEventHandler [""MPKilled"", {_this spawn kill_manager}]; removeBackpackGlobal this; this addBackpackGlobal ""B_parachute""", 0.5, _unitrank];
_x createUnit [_pos, _grp,"this addMPEventHandler ['MPKilled', {['KPLIB_manageKills', _this] call CBA_fnc_localEvent}]; removeBackpackGlobal this; this addBackpackGlobal 'B_parachute'", 0.5, _unitrank];
} else {
_x createUnit [_pos, _grp,"this addMPEventHandler [""MPKilled"", {_this spawn kill_manager}];", 0.5, _unitrank];
_x createUnit [_pos, _grp,"this addMPEventHandler ['MPKilled', {['KPLIB_manageKills', _this] call CBA_fnc_localEvent}]", 0.5, _unitrank];
};
_idx = _idx + 1;

Expand Down Expand Up @@ -333,8 +333,17 @@ while { true } do {
_vehicle setDamage 0;

if(buildtype != 6) then {
_vehicle addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
{ _x addMPEventHandler ["MPKilled", {_this spawn kill_manager}]; } foreach (crew _vehicle);
_vehicle addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];

{
_x addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
} foreach (crew _vehicle);
};
};

Expand Down
5 changes: 4 additions & 1 deletion Missionframework/scripts/client/init_client.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ execVM "scripts\client\ui\ui_manager.sqf";
execVM "scripts\client\ui\tutorial_manager.sqf";
execVM "scripts\client\markers\update_production_sites.sqf";

player addMPEventHandler ["MPKilled", {_this spawn kill_manager;}];
player addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
player addEventHandler ["GetInMan", {[_this select 2] spawn kp_fuel_consumption;}];
player addEventHandler ["GetInMan", {[_this select 2] call KPLIB_fnc_setVehiclesSeized;}];
player addEventHandler ["GetInMan", {[_this select 2] call KPLIB_fnc_setVehicleCaptured;}];
Expand Down
14 changes: 12 additions & 2 deletions Missionframework/scripts/server/battlegroup/spawn_air.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ for "_i" from 1 to _planes_number do {
_plane = createVehicle [_class, _spawnPos, [], 0, "FLY"];
createVehicleCrew _plane;
_plane flyInHeight (120 + (random 180));
_plane addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
[_plane] call KPLIB_fnc_addObjectInit;
{_x addMPEventHandler ["MPKilled", {_this spawn kill_manager}];} forEach (crew _plane);

_plane addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
{
_x addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit,_killer]] call CBA_fnc_localEvent;
}];
} forEach (crew _plane);

(crew _plane) joinSilent _grp;
sleep 1;
};
Expand Down
5 changes: 4 additions & 1 deletion Missionframework/scripts/server/game/save_manager.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,10 @@ if (!isNil "_saveData") then {

// Apply kill manager handling, if not excluded
if !((toLower _class) in _noKillHandler) then {
_object addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
_object addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
};

// Set enemy vehicle as captured
Expand Down
7 changes: 7 additions & 0 deletions Missionframework/scripts/server/init_server.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ execVM "scripts\server\asymmetric\init_module.sqf";
// Groupcheck for deletion when empty
execVM "scripts\server\offloading\group_diag.sqf";

// Server event(s)
["KPLib_manageKills", {
params ["_unit", "_killer"];
[_unit, _killer] call kill_manager;
}] call CBA_fnc_addEventHandler;


{
if ((_x != player) && (_x distance (markerPos KPLIB_respawn_marker) < 200 )) then {
deleteVehicle _x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ while { KPLIB_endgame == 0 } do {
[selectRandom KPLIB_c_units, _spawnpos, _grp, "PRIVATE", 0.5] call KPLIB_fnc_createManagedUnit;
_civveh = (selectRandom KPLIB_c_vehicles) createVehicle _spawnpos;
_civveh setpos _spawnpos;
_civveh addMPEventHandler ['MPKilled', {_this spawn kill_manager}];
_civveh addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
_civveh addEventHandler ["HandleDamage", { private [ "_damage" ]; if (( side (_this select 3) != KPLIB_side_player ) && ( side (_this select 3) != KPLIB_side_enemy )) then { _damage = 0 } else { _damage = _this select 2 }; _damage } ];
((units _grp) select 0) moveInDriver _civveh;
((units _grp) select 0) disableAI "FSM";
Expand Down
12 changes: 10 additions & 2 deletions Missionframework/scripts/server/patrols/send_paratroopers.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ if (isNull _chopper_type) then {
_pilot_group = createGroup [KPLIB_side_enemy, true];
(crew _newvehicle) joinSilent _pilot_group;

_newvehicle addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
{_x addMPEventHandler ["MPKilled", {_this spawn kill_manager}];} forEach (crew _newvehicle);
_newvehicle addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit,_killer]] call CBA_fnc_localEvent;
}];
{
_x addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
} forEach (crew _newvehicle);
} else {
_newvehicle = _chopper_type;
_pilot_group = group _newvehicle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ if ( KPLIB_enemyReadiness < 50 ) then {
private _vehtospawn = [];
private _spawnchances = [75,50,15];
{if (random 100 < _x) then {_vehtospawn pushBack (selectRandom _vehicle_pool);};} foreach _spawnchances;
{([(getpos _helowreck) getPos [30 + (random 30), random 360], _x, true] call KPLIB_fnc_spawnVehicle) addMPEventHandler ['MPKilled', {_this spawn kill_manager}]; } foreach _vehtospawn;
{
private _vehicle = [(getpos _helowreck) getPos [30 + (random 30), random 360], _x, true] call KPLIB_fnc_spawnVehicle;
_vehicle addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
["KPLIB_manageKills", [_unit, _killer]] call CBA_fnc_localEvent;
}];
} foreach _vehtospawn;

secondary_objective_position = getpos _helowreck;
secondary_objective_position_marker = secondary_objective_position getPos [800, random 360];
Expand Down
34 changes: 11 additions & 23 deletions Missionframework/scripts/shared/kill_manager.sqf
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
params ["_unit", "_killer"];

if (isServer) then {


if (KPLIB_kill_debug > 0) then {[format ["Kill Manager executed - _unit: %1 (%2) - _killer: %3 (%4)", typeOf _unit, _unit, typeOf _killer, _killer], "KILL"] call KPLIB_fnc_log;};

// Get Killer, when ACE enabled, via lastDamageSource
if (KPLIB_ace) then {
if (local _unit) then {
_killer = _unit getVariable ["ace_medical_lastDamageSource", _killer];
if (KPLIB_kill_debug > 0) then {["_unit is local to server", "KILL"] call KPLIB_fnc_log;};
} else {
if (KPLIB_kill_debug > 0) then {["_unit is not local to server", "KILL"] call KPLIB_fnc_log;};
if (isNil "KPLIB_ace_killer") then {KPLIB_ace_killer = objNull;};
waitUntil {sleep 0.5; !(isNull KPLIB_ace_killer)};
if (KPLIB_kill_debug > 0) then {["KPLIB_ace_killer received on server", "KILL"] call KPLIB_fnc_log;};
_killer = KPLIB_ace_killer;
KPLIB_ace_killer = objNull;
publicVariable "KPLIB_ace_killer";
};
};

// Failsafe if something gets killed before the save manager is finished
if (isNil "infantry_weight") then {infantry_weight = 33};
Expand Down Expand Up @@ -158,11 +143,14 @@ if (isServer) then {
};
};
};
} else {
// Get Killer and send it to server, when ACE enabled, via lastDamageSource
if (KPLIB_ace && local _unit) then {
if (KPLIB_kill_debug > 0) then {[format ["_unit is local to: %1", debug_source], "KILL"] remoteExecCall ["KPLIB_fnc_log", 2];};
KPLIB_ace_killer = _unit getVariable ["ace_medical_lastDamageSource", _killer];
publicVariable "KPLIB_ace_killer";

// Body/wreck cleanup
if (!isPlayer _unit) then {
[{
params ["_unit"];
if (_unit isKindOf "CAManBase") exitWith {
hideBody _unit;
};
deleteVehicle _unit;
}, [_unit], KPLIB_cleanup_delay] call CBA_fnc_waitAndExecute;
};
};

0 comments on commit 6cc1b74

Please sign in to comment.