reload event, some basic functions

This commit is contained in:
commy2 2015-03-18 20:17:53 +01:00
parent 0be1959934
commit 40eed0e12f
9 changed files with 138 additions and 4 deletions

View File

@ -4,3 +4,9 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

View File

@ -0,0 +1,11 @@
class CfgWeapons {
class Launcher_Base_F;
class launch_Titan_base: Launcher_Base_F {
GVAR(enabled) = 1;
};
class launch_RPG32_F: Launcher_Base_F {
GVAR(enabled) = 1;
};
};

View File

@ -0,0 +1,4 @@
// by commy2
#include "script_component.hpp"
["reloadLauncher", {_this call DFUNC(reloadLauncher)}] call EFUNC(common,addEventhandler);

View File

@ -2,6 +2,8 @@
ADDON = false;
PREP(empty);
PREP(canLoad);
PREP(load);
PREP(reloadLauncher);
ADDON = true;

View File

@ -13,3 +13,4 @@ class CfgPatches {
};
#include "CfgEventHandlers.hpp"
#include "CfgWeapons.hpp"

View File

@ -0,0 +1,56 @@
/*
* Author: commy2
*
* Check of the unit can reload the launcher of target unit.
*
* Argument:
* 0: Unit to to the reload (Object)
* 1: Unit eqipped with launcher (Object)
*
* Return value:
* NONE
*/
#include "script_component.hpp"
private ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
if (!alive _target) exitWith {false};
if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false};
private "_weapon";
_weapon = secondaryWeapon _unit;
// has secondary weapon equipped
if (_weapon == "" || {currentWeapon _target != _weapon}) exitWith {false};
// check if the target really needs to be reloaded
if (currentMagazine _target != "") exitWith {false};
// check if the launcher is compatible
private "_config";
_config = configFile >> "CfgWeapons" >> _weapon;
if (getNumber (_config >> QGVAR(enabled)) == 0) exitWith {false};
// get magazine of reloader
private "_magazines";
_magazines = magazines _unit;
{
_magazines deleteAt (_magazines find _x);
} forEach secondaryWeaponMagazine _unit;
// check if the reloader has a magazine compatible with targets launcher
private "_hasMagazine";
_hasMagazine = false;
{
if (_x in _magazines) exitWith {
_hasMagazine = true;
};
} forEach getArray (_config >> "magazines");
_hasMagazine

View File

@ -1,3 +0,0 @@
#include "script_component.hpp"
diag_log text format["This is here as an example!!!"];

View File

@ -0,0 +1,29 @@
/*
* Author: commy2
*
* Reload a launcher
*
* Argument:
* 0: Unit with magazine (Object)
* 1: Unit with launcher (Object)
* 2: weapon name (String)
* 3: missile name (String)
*
* Return value:
* NONE
*/
#include "script_component.hpp"
private ["_unit", "_target", "_weapon", "_magazine"];
_unit = _this select 0;
_target = _this select 1;
_weapon = _this select 2;
_magazine = _this select 3;
//do stuff
/**/
// reload launcher on remote machine
["reloadLauncher", _target, [_target, _weapon, _magazine]] call EFUNC(common,targetEvent);

View File

@ -0,0 +1,28 @@
/*
* Author: commy2
*
* Reload a launcher
*
* Argument:
* 0: Unit to reload (Object)
* 1: weapon name (String)
* 2: missile name (String)
*
* Return value:
* NONE
*/
#include "script_component.hpp"
private ["_unit", "_weapon", "_magazine"];
_unit = _this select 0;
_weapon = _this select 1;
_magazine = _this select 2;
_unit selectWeapon _weapon;
if (currentWeapon _unit != _weapon) exitWith {};
if (currentMagazine _unit != "") exitWith {};
// command is wip, reload time for launchers is not intended.
_unit addWeaponItem [_weapon, _magazine];