function to return attachments, muzzles with magazines and ammo, moved stuff around

This commit is contained in:
commy2 2015-03-28 01:43:30 +01:00
parent 66c026d4a0
commit d12ba196c5
7 changed files with 79 additions and 5 deletions

View File

@ -95,6 +95,9 @@ PREP(getVehicleCrew);
PREP(getVersion);
PREP(getWeaponAzimuthAndInclination);
PREP(getWeaponIndex);
PREP(getWeaponModes);
PREP(getWeaponMuzzles);
PREP(getWeaponState);
PREP(getWeaponType);
PREP(getWindDirection);
PREP(goKneeling);

View File

@ -0,0 +1,73 @@
/*
* Author: commy2
*
* Return current state of the weapon. Attachments and magazines with ammo.
*
* Argument:
* 0: A unit (Object)
* 1: A weapon (String)
*
* Return value:
* NONE.
*/
#include "script_component.hpp"
private ["_unit", "_weapon"];
_unit = _this select 0;
_weapon = _this select 1;
private "_muzzles";
_muzzles = [_weapon] call FUNC(getWeaponMuzzles);
private "_weaponInfo";
_weaponInfo = [];
switch (_weapon) do {
case (primaryWeapon _unit): {
_weaponInfo pushBack primaryWeaponItems _unit;
};
case (secondaryWeapon _unit): {
_weaponInfo pushBack secondaryWeaponItems _unit;
};
case (handgunWeapon _unit): {
_weaponInfo pushBack handgunItems _unit;
};
default {
_weaponInfo pushBack ["","","",""];
};
};
// get loaded magazines and ammo
private ["_magazines", "_ammo"];
_magazines = [];
_ammo = [];
{
_magazines pushBack "";
_ammo pushBack 0;
} forEach _muzzles;
{
if (_x select 2) then {
private "_index";
_index = _muzzles find (_x select 4);
if (_index != -1) then {
_magazines set [_index, _x select 0];
_ammo set [_index, _x select 1];
};
};
} forEach magazinesAmmoFull _unit;
_weaponInfo append [_muzzles, _magazines, _ammo];
_weaponInfo

View File

@ -8,8 +8,6 @@ PREP(findNextGrenadeMagazine);
PREP(findNextGrenadeMuzzle);
PREP(fireSmokeLauncher);
PREP(getSelectedGrenade);
PREP(getWeaponModes);
PREP(getWeaponMuzzles);
PREP(playChangeFiremodeSound);
PREP(putWeaponAway);
PREP(selectGrenadeAll);

View File

@ -29,8 +29,8 @@ if (_weapon in (_unit getVariable [QEGVAR(safemode,safedWeapons), []])) exitWith
private ["_muzzles", "_modes"];
_muzzles = [_weapon] call FUNC(getWeaponMuzzles);
_modes = [_weapon] call FUNC(getWeaponModes);
_muzzles = [_weapon] call EFUNC(common,getWeaponMuzzles);
_modes = [_weapon] call EFUNC(common,getWeaponModes);
private ["_index", "_muzzle", "_mode"];

View File

@ -19,7 +19,7 @@ _weapon = _this select 1;
if (_weapon == "") exitWith {};
private "_muzzles";
_muzzles = [_weapon] call FUNC(getWeaponMuzzles);
_muzzles = [_weapon] call EFUNC(common,getWeaponMuzzles);
if (currentWeapon _unit != _weapon) exitWith {
if (count _muzzles > 1) then {