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

Refactor mission event handler #238

Open
wants to merge 2 commits into
base: main
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Compilation of scripts used during multiplayer PVE/PVP mission on Arma 3. Also f

If you want to contribute to this project, see [CONTRIBUTING.md](https://github.com/gerard-sog/arma3-macvsog-columbia-scripts/blob/main/CONTRIBUTING.md).

YouTube channel showcasing the scripts: [YouTube - RT Columbia](https://www.youtube.com/@RTColumbia/videos)

## Table of contents
- [Requirements](#requirements)
- [Installation](#installation)
Expand Down Expand Up @@ -390,7 +392,7 @@ At the death of a unit (AI/Player):
1x "ACE_morphine"
```

see [colsog_fn_firstAidConvertAce.sqf](https://github.com/gerard-sog/arma3-macvsog-columbia-scripts/blob/main/functions/colsog_fn_firstAidConvertAce.sqf)
see [fn_firstAidConvertAce.sqf](https://github.com/gerard-sog/arma3-macvsog-columbia-scripts/blob/main/functions/missionEventHandlers/entityKilled/fn_firstAidConvertAce.sqf)

</details>

Expand Down
59 changes: 0 additions & 59 deletions functions/colsog_fn_firstAidConvertAce.sqf

This file was deleted.

10 changes: 10 additions & 0 deletions functions/colsog_fn_missionEventHandlers.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if !(isClass (configFile >> "CfgPatches" >> "ace_main")) exitWith {};

if (!isServer) exitWith {};

addMissionEventHandler ["EntityKilled", {
params ["_killed"];

[_killed] execVM "functions\missionEventHandlers\entityKilled\fn_firstAidConvertAce.sqf";
[_killed] execVM "functions\missionEventHandlers\entityKilled\fn_intelOnBodies.sqf";
}];
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Convert basic medikit into ace medical items.
*
* Arguments:
* 0: killed OPFOR unit.
*
* Return values:
* None
*/

params ["_killed"];

ClassFirstAidConvertACE = "FirstAidKit";
ClassMedicConvertACE = "Medikit";
if (isClass (configFile >> "CfgPatches" >> "vn_emm")) then {
ClassFirstAidConvertACE = "vn_o_item_firstaidkit";
ClassMedicConvertACE = "vn_b_item_medikit_01";
};

if (_killed isKindOf "CAManBase") then {
private _unit = _this select 0;
private _items = items _unit;

// Medical
if (ClassMedicConvertACE in _items) then {
_unit removeItems ClassFirstAidConvertACE;
_unit removeItem ClassMedicConvertACE;
private _backpack = BackpackContainer _unit;
_backpack addItemCargoGlobal ["ACE_fieldDressing", colsog_medikit_convertAceFieldDressing];
_backpack addItemCargoGlobal ["ACE_salineIV_500", colsog_medikit_convertAceSalineIv500];
_backpack addItemCargoGlobal ["ACE_epinephrine", colsog_medikit_convertAceEpinephrine];
_backpack addItemCargoGlobal ["ACE_morphine", colsog_medikit_convertAceMorphine];
_backpack addItemCargoGlobal ["ACE_tourniquet", colsog_medikit_convertAceTourniquet];
_backpack addItemCargoGlobal ["ACE_splint", colsog_medikit_convertAceSplint];
};

if (ClassFirstAidConvertACE in _items) then {
while {({_x == ClassFirstAidConvertACE} count items _unit) > 0} do {
_unit removeItem ClassFirstAidConvertACE;
private _vest = vestContainer _unit;
_vest addItemCargoGlobal ["ACE_fieldDressing", colsog_firstAid_convertAceFieldDressing];
_vest addItemCargoGlobal ["ACE_morphine", colsog_firstAid_convertAceMorphine];
};
};
};
34 changes: 34 additions & 0 deletions functions/missionEventHandlers/entityKilled/fn_intelOnBodies.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Add intel OPFOR units when killed.
*
* Arguments:
* 0: killed OPFOR unit.
*
* Return values:
* None
*/

params ["_killed"];

if (_killed isKindOf "O_Soldier_base_F") then {
private _unit = _this select 0;
private _items = items _unit;

// Intel
private _chanceOfUnitCarryingIntel = [1, 100] call BIS_fnc_randomNum;
if (_chanceOfUnitCarryingIntel <= colsog_intel_chanceOfUnitCarryingIntel) then
{
private _chanceOfIntelFallingOnGround = [1, 100] call BIS_fnc_randomNum;
if (_chanceOfIntelFallingOnGround <= colsog_intel_chanceOfIntelFallingOnGround) then
{
// Intel can be found on the ground.
private _groundWeaponHolder = createVehicle ["groundweaponholder", getPosATL _unit, [], 1, "CAN_COLLIDE"];
_groundWeaponHolder addItemCargoGlobal [colsog_intel_inventoryItem, 1];
} else
{
// Intel can be found in the inventory of the unit.
private _uniform = uniformContainer _unit;
_uniform addItemCargoGlobal [colsog_intel_inventoryItem, 1];
};
};
};
4 changes: 2 additions & 2 deletions init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ execVM "functions\sensors\engine\init_colsog_engineSensor.sqf";
// init Gravity sensors placed by player
execVM "functions\sensors\gravity\init_colsog_gravitySensor.sqf";

// init convertMedicKit on killed units
execVM "functions\colsog_fn_firstAidConvertAce.sqf";
// init missionEventHandlers on server
execVM "functions\colsog_fn_missionEventHandlers.sqf";

// run the script to create the nice vectored map borders
// commented out by default as currently we only have borders for Cam Lao Nam
Expand Down