more common code cleanup

This commit is contained in:
commy2 2015-09-21 13:08:10 +02:00
parent ef099861a3
commit 9fa6eb0651
22 changed files with 279 additions and 242 deletions

View File

@ -1,23 +1,31 @@
/** /*
* fn_getFirstIntersection.sqf * Author: Ruthberg
* @Descr: Returns the the first intersection with an object between two positions * Returns the the first intersection with terrain between two positions. @todo rewrite using lineIntersectsSurfaces?
* @Author: Ruthberg
* *
* @Arguments: [position PositionASL, position PositionASL, accuracy FLOAT] * Arguments:
* @Return: [intersects BOOL, intersection PositionASL] * 0: PositionASL <ARRAY>
* @PublicAPI: true * 1: PositionATL <ARRAY>
* 2: Accuracy <NUMBER>
*
* Return Value:
* 0: Intersects <BOOL>
* 1: Intersection Position ASL <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_distance", "_lower", "_upper", "_mid", "_intersections", "_result", "_dir"]; params ["_source", "_destination", "_accuracy"];
PARAMS_3(_source,_destination,_accuracy); private ["_result", "_distance"];
_result = [false, [0, 0, 0]]; _result = [false, [0, 0, 0]];
_distance = _source vectorDistance _destination; _distance = _source vectorDistance _destination;
if (count (lineIntersectsWith [_source, _destination]) > 0) then { if !(lineIntersectsWith [_source, _destination] isEqualTo []) then {
private ["_lower", "_upper", "_mid", "_dir"];
_lower = 0; _lower = 0;
_upper = 1; _upper = 1;
_mid = 0.5; _mid = 0.5;
@ -27,9 +35,7 @@ if (count (lineIntersectsWith [_source, _destination]) > 0) then {
while {(_upper - _lower) * _distance > _accuracy} do { while {(_upper - _lower) * _distance > _accuracy} do {
_mid = _lower + (_upper - _lower) / 2; _mid = _lower + (_upper - _lower) / 2;
_intersections = count (lineIntersectsWith [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]); if !(lineIntersectsWith [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))] isEqualTo []) then {
if (_intersections > 0) then {
_upper = _mid; _upper = _mid;
} else { } else {
_lower = _mid; _lower = _mid;

View File

@ -1,23 +1,31 @@
/** /*
* fn_getFirstIntersection.sqf * Author: Ruthberg
* @Descr: Returns the the first intersection with an object between two positions * Returns the the first intersection with an object between two positions. @todo rewrite using lineIntersectsSurfaces?
* @Author: Ruthberg
* *
* @Arguments: [position PositionASL, position PositionASL, accuracy FLOAT] * Arguments:
* @Return: [intersects BOOL, intersection PositionASL] * 0: PositionASL <ARRAY>
* @PublicAPI: true * 1: PositionATL <ARRAY>
* 2: Accuracy <NUMBER>
*
* Return Value:
* 0: Intersects <BOOL>
* 1: Intersection Position ASL <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_distance", "_lower", "_upper", "_mid", "_intersection", "_result", "_dir"]; params ["_source", "_destination", "_accuracy"];
PARAMS_3(_source,_destination,_accuracy); private ["_result", "_distance"];
_result = [false, [0, 0, 0]]; _result = [false, [0, 0, 0]];
_distance = _source vectorDistance _destination; _distance = _source vectorDistance _destination;
if (terrainIntersectASL [_source, _destination]) then { if (terrainIntersectASL [_source, _destination]) then {
private ["_lower", "_upper", "_mid", "_dir"];
_lower = 0; _lower = 0;
_upper = 1; _upper = 1;
_mid = 0.5; _mid = 0.5;
@ -27,9 +35,7 @@ if (terrainIntersectASL [_source, _destination]) then {
while {(_upper - _lower) * _distance > _accuracy} do { while {(_upper - _lower) * _distance > _accuracy} do {
_mid = _lower + (_upper - _lower) / 2; _mid = _lower + (_upper - _lower) / 2;
_intersection = terrainIntersectASL [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]; if (terrainIntersectASL [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]) then {
if (_intersection) then {
_upper = _mid; _upper = _mid;
} else { } else {
_lower = _mid; _lower = _mid;

View File

@ -1,18 +1,16 @@
/* /*
* Author: commy2 * Author: commy2
*
* Get a number from the mission.sqm file. Mission has to be saved in the Editor. * Get a number from the mission.sqm file. Mission has to be saved in the Editor.
* On non-existing entries, it might return 0 or the value of an entry with the same name of another calss.
* *
* Argument: * Arguments:
* 0: Path of the entry in the mission.sqm (Array) * 0: Path of the entry in the mission.sqm <ARRAY>
* *
* Return value: * Return Value:
* Value of the entry. Note: If the entry does not exist, it might return 0 or an entry with the same name of another class! (Number) * Entry value <NUMBER>
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private "_number"; parseNumber (_this call FUNC(getStringFromMissionSQM)) // return
_number = _this call FUNC(getStringFromMissionSQM);
parseNumber _number;

View File

@ -1,26 +1,30 @@
/** /*
* fn_getNumberMagazinesIn.sqf * Author: Glowbal
* @Descr: * Count magazines of unit.
* @Author: Glowbal
* *
* @Arguments: [] * Arguments:
* @Return: * 0: Unit <OBJECT>
* @PublicAPI: true * 1: Magazine <STRING>
*
* Return Value:
* Magazine amount <NUMBER>
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_magazine); params ["_unit", "_magazine"];
private ["_return"];
private "_return";
_return = 0; _return = 0;
if (_unit isKindOf "CAManBase") then { if (_unit isKindOf "CAManBase") then {
_return = {_x == _magazine} count magazines _unit; _return = {_x == _magazine} count magazines _unit;
} else { } else {
{ {
_return = _return + {_x == _magazine} count magazines _x; _return = _return + {_x == _magazine} count magazines _x;
} forEach (crew _unit); false
} count crew _unit;
_return = _return + ({_x == _magazine} count getMagazineCargo _unit); _return = _return + ({_x == _magazine} count getMagazineCargo _unit);
}; };

View File

@ -14,6 +14,6 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_vehicle"]; params ["_vehicle"];
(_vehicle call BIS_fnc_getPitchBank) + [getDir _vehicle] (_vehicle call BIS_fnc_getPitchBank) + [getDir _vehicle]

View File

@ -3,29 +3,32 @@
* Returns the metadata of a setting if it exists * Returns the metadata of a setting if it exists
* *
* Arguments: * Arguments:
* 0: Name of the setting (String) * 0: Setting Name <STRING>
* *
* Return Value: * Return Value:
* Setting Data (Array) * Setting Data (Array)
* 0: _name * 0: Name <STRING>
* 1: _typeName * 1: Type Name <STRING>
* 2: _isClientSetable * 2: Is Client Settable <BOOL>
* 3: _localizedName * 3: Localized Name <STRING>
* 4: _localizedDescription * 4: Localized Description <STRING>
* 5: _possibleValues * 5: Possible Values <ARRAY>
* 6: _isForced * 6: Is Forced <BOOL>
* 7: _defaultValue * 7: Default Value <ANY>
* 8: Localized Category <STRING>
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_name); params ["_name"];
private ["_value"]; private "_value";
_value = []; _value = [];
{ {
if ((_x select 0) == _name) exitWith {_value = _x}; if (_x select 0 == _name) exitWith {_value = _x};
} forEach GVAR(settings); false
} count GVAR(settings);
_value _value

View File

@ -1,28 +1,34 @@
/* /*
* Author: commy2 * Author: commy2
* Get a string from the mission.sqm file. Mission has to be saved in the Editor.
* The string cannot contain the ; character.
* If the entry does not exist, it might return an empty string or an entry with the same name of another class!
* *
* Get a string from the mission.sqm file. Mission has to be saved in the Editor. The string cannot contain the ; character. * Arguments:
* 0: Path of the entry in the mission.sqm <ARRAY>
* *
* Argument: * Return Value:
* 0: Path of the entry in the mission.sqm (Array) * Value of the entry. <STRING>
* *
* Return value: * Public: No
* Value of the entry. Note: If the entry does not exist, it might return an empty string or an entry with the same name of another class! (String)
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_path", "_mission", "_a", "_class", "_index", "_array", "_b", "_entry"]; private ["_path", "_mission", "_class", "_index", "_array", "_entry"];
_path = _this; _path = _this;
if (missionName == "") exitWith {""}; if (missionName == "") exitWith {""};
_mission = toArray toLower loadFile "mission.sqm"; _mission = toArray toLower loadFile "mission.sqm";
_mission resize 65536; _mission resize 65536;
{ {
if (_x < 33) then { if (_x < 33) then {
_mission set [_forEachIndex, -1]; _mission set [_forEachIndex, -1];
} }
} forEach _mission; } forEach _mission;
_mission = toString (_mission - [-1]); _mission = toString (_mission - [-1]);
{_path set [_forEachIndex, toLower _x]} forEach _path; {_path set [_forEachIndex, toLower _x]} forEach _path;
@ -33,9 +39,11 @@ for "_a" from 0 to (count _path - 2) do {
_index = _mission find _class; _index = _mission find _class;
_array = toArray _mission; _array = toArray _mission;
for "_b" from 0 to (_index + count toArray _class - 1) do { for "_b" from 0 to (_index + count toArray _class - 1) do {
_array set [_b, -1]; _array set [_b, -1];
}; };
_array = _array - [-1]; _array = _array - [-1];
_mission = toString _array; _mission = toString _array;
@ -43,16 +51,20 @@ for "_a" from 0 to (count _path - 2) do {
_entry = format ["%1=", _path select (count _path - 1)]; _entry = format ["%1=", _path select (count _path - 1)];
_index = _mission find _entry; _index = _mission find _entry;
if (_index == -1) exitWith {""}; if (_index == -1) exitWith {""};
_array = toArray _mission; _array = toArray _mission;
for "_b" from 0 to (_index + count toArray _entry - 1) do { for "_b" from 0 to (_index + count toArray _entry - 1) do {
_array set [_b, -1]; _array set [_b, -1];
}; };
_mission = toString (_array - [-1]); _mission = toString (_array - [-1]);
_index = _mission find ";"; _index = _mission find ";";
_mission = toArray _mission; _mission = toArray _mission;
_mission resize _index; _mission resize _index;
format ["%1", toString _mission];
format ["%1", toString _mission] // return

View File

@ -1,14 +1,15 @@
/* /*
* Author: commy2 * Author: commy2
* Get players viewing direction and slope.
* *
* Get players viewing direction and slope * Arguments:
* None
* *
* Argument: * Return Value:
* None. * 0: Azimuth <NUMBER>
* 1: Inclination <NUMBER>
* *
* Return value: * Public: Yes
* 0: Azimuth (Number)
* 1: Inclination or 'slope' (Number)
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,21 +1,22 @@
/* /*
* Author: commy2 * Author: commy2
*
* Get the distance to the next object the player is looking at. Used for laser distance measurements. * Get the distance to the next object the player is looking at. Used for laser distance measurements.
* *
* Argument: * Arguments:
* 0: How accurate will the measurement be? In meters. (Number) * 0: Messurement Accuracy <NUMBER>
* 1: Maximal distance to measure. (Number) * 1: Maximal messure distance <NUMBER>
* 2: Minimal distance to measure. (optional, Number) * 2: Minimal messure distance (default: nil) <NUMBER>
* *
* Return value: * Return Value:
* Measured distance in meters. Can return maximal or minimal distance (Number) * Distance in meters <NUMBER>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_position", "_laser", "_line", "_distance", "_iteration"]; params ["_interval", "_maxDistance", "_minDistance"];
PARAMS_3(_interval,_maxDistance,_minDistance); private ["_position", "_laser", "_line", "_distance", "_iteration"];
_position = ATLToASL positionCameraToWorld [0, 0, 0]; _position = ATLToASL positionCameraToWorld [0, 0, 0];
_position set [2, (_position select 2) - (getTerrainHeightASL _position min 0)]; _position set [2, (_position select 2) - (getTerrainHeightASL _position min 0)];
@ -42,6 +43,6 @@ _distance = _interval * round (_distance / _interval);
_distance = _distance min _maxDistance; _distance = _distance min _maxDistance;
if !(isNil "_minDistance") then {_distance = _distance max _minDistance}; if (!isNil "_minDistance") then {_distance = _distance max _minDistance};
_distance _distance

View File

@ -1,19 +1,20 @@
/* /*
* Author: commy2 * Author: commy2
*
* Get the nearest object the player is looking at. Used for laser designator instead of cursorTarget. * Get the nearest object the player is looking at. Used for laser designator instead of cursorTarget.
* *
* Argument: * Arguments:
* 0: Maximal distance to search. (Number) * 0: Maximum search distance <NUMBER>
* *
* Return value: * Return Value:
* Nearest object directly in line of sight, if none objNull (Object) * Nearest object in line of sight, objNull if none are found <OBJECT>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_position", "_laser", "_intersects"]; params ["_maxDistance"];
PARAMS_1(_maxDistance); private ["_position", "_laser", "_intersects"];
_position = ATLToASL positionCameraToWorld [0, 0, 0]; _position = ATLToASL positionCameraToWorld [0, 0, 0];
_position set [2, (_position select 2) - (getTerrainHeightASL _position min 0)]; _position set [2, (_position select 2) - (getTerrainHeightASL _position min 0)];
@ -23,4 +24,6 @@ _laser set [2, (_laser select 2) - (getTerrainHeightASL _laser min 0)];
_intersects = lineIntersectsObjs [_position, _laser, objNull, objNull, true, 2]; _intersects = lineIntersectsObjs [_position, _laser, objNull, objNull, true, 2];
if (count _intersects == 0) then {objNull} else {_intersects select 0} if (_intersects isEqualTo []) exitWith {objNull};
_intersects select 0 // return

View File

@ -1,21 +1,22 @@
/* /*
* Author: commy2 * Author: commy2
*
* Returns all turned on lights of any vehicle or streetlamp. * Returns all turned on lights of any vehicle or streetlamp.
* *
* Arguments: * Arguments:
* 0: A vehicle, not the classname (Object) * 0: Vehicle <OBJECT>
* *
* Return Value: * Return Value:
* All burning lights (Array) * All burning lights <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_vehicle); params ["_vehicle"];
if (!isLightOn _vehicle) exitWith {[]}; if (!isLightOn _vehicle) exitWith {[]};
private ["_reflectorsWithSelections", "_lights", "_hitpoints"]; private ["_reflectorsWithSelections", "_lights", "_hitpoints", "_turnedOnLights"];
_reflectorsWithSelections = [[_vehicle], FUNC(getReflectorsWithSelections), uiNamespace, format [QEGVAR(cache,%1_%2), QUOTE(DFUNC(getReflectorsWithSelections)), typeOf _vehicle], 1E11] call FUNC(cachedCall); _reflectorsWithSelections = [[_vehicle], FUNC(getReflectorsWithSelections), uiNamespace, format [QEGVAR(cache,%1_%2), QUOTE(DFUNC(getReflectorsWithSelections)), typeOf _vehicle], 1E11] call FUNC(cachedCall);
//_reflectorsWithSelections = [_vehicle] call FUNC(getReflectorsWithSelections); //_reflectorsWithSelections = [_vehicle] call FUNC(getReflectorsWithSelections);
@ -23,13 +24,12 @@ _reflectorsWithSelections = [[_vehicle], FUNC(getReflectorsWithSelections), uiNa
_lights = _reflectorsWithSelections select 0; _lights = _reflectorsWithSelections select 0;
_hitpoints = _reflectorsWithSelections select 1; _hitpoints = _reflectorsWithSelections select 1;
private "_turnedOnLights";
_turnedOnLights = []; _turnedOnLights = [];
{ {
if (_vehicle getHit _x <= 0.9) then { if (_vehicle getHit _x <= 0.9) then {
_turnedOnLights pushBack (_lights select _forEachIndex); _turnedOnLights pushBack (_lights select _forEachIndex);
}; };
} forEach _hitpoints; } forEach _hitpoints;
_turnedOnLights _turnedOnLights

View File

@ -1,32 +1,34 @@
/* /*
Name: FUNC(getUavControlPosition) * Author: PabstMirror
* Returns the seat position of a UAV that the unit is activly controling.
Author: Pabst Mirror *
* Arguments:
Description: * 0: Unit <OBJECT>
Gets the seat position of a UAV that the unit is activly controlling. *
"" - not connected to anything or not activly controling * Return Value:
"DRIVER" * Position <STRING>
"GUNNER" * "" = not connected to anything or activly controling
* "DRIVER"
Parameters: * "GUNNER"
0: OBJECT - Unit *
* Example:
Returns: * [ACE_Player] call ace_common_fnc_getUavControlPosition
STRING - Position in the UAV that is currently being controled by the unit. *
* Public: Yes
Example: */
[ACE_Player] call FUNC(getUavControlPosition)
*/
#include "script_component.hpp" #include "script_component.hpp"
params ["_unit"];
private ["_uav", "_positionArray", "_playerIndex"]; private ["_uav", "_positionArray", "_playerIndex"];
PARAMS_1(_unit);
_uav = getConnectedUAV _unit; _uav = getConnectedUAV _unit;
if (isNull _uav) exitWith {""}; if (isNull _uav) exitWith {""};
_positionArray = UAVControl _uav; _positionArray = UAVControl _uav;
_playerIndex = _positionArray find _unit; _playerIndex = _positionArray find _unit;
if (_playerIndex == -1) exitWith {""}; if (_playerIndex == -1) exitWith {""};
_positionArray select (_playerIndex + 1) _positionArray select (_playerIndex + 1)

View File

@ -1,19 +1,20 @@
/* /*
* Author: commy2 * Author: commy2
*
* Get the vehicle cargo positions. Codrivers and ffv positions are not listed. * Get the vehicle cargo positions. Codrivers and ffv positions are not listed.
* *
* Argument: * Arguments:
* 0: Vehicle type (String) * 0: Vehicle type <STRING>
* *
* Return value: * Return Value:
* Vehicle cargo positions. (Array) * Vehicle cargo positions <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_config", "_cargo", "_codrivers", "_index"]; params ["_vehicle"];
PARAMS_1(_vehicle); private ["_config", "_cargo", "_codrivers"];
_config = configFile >> "CfgVehicles" >> _vehicle; _config = configFile >> "CfgVehicles" >> _vehicle;
@ -25,4 +26,5 @@ for "_index" from 0 to (getNumber (_config >> "transportSoldier") - 1) do {
_cargo pushBack _index; _cargo pushBack _index;
}; };
}; };
_cargo _cargo

View File

@ -1,19 +1,20 @@
/* /*
* Author: commy2 * Author: commy2
*
* Get the vehicle codriver positions. * Get the vehicle codriver positions.
* *
* Argument: * Arguments:
* 0: Vehicle type (String) * 0: Vehicle type <STRING>
* *
* Return value: * Return Value:
* Vehicle codriver positions. (Array) * Vehicle codriver positions <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_config", "_cargo", "_codrivers", "_index"]; params ["_vehicle"];
PARAMS_1(_vehicle); private ["_config", "_cargo", "_codrivers"];
_config = configFile >> "CfgVehicles" >> _vehicle; _config = configFile >> "CfgVehicles" >> _vehicle;
@ -25,4 +26,5 @@ for "_index" from 0 to (getNumber (_config >> "transportSoldier") - 1) do {
_cargo pushBack _index; _cargo pushBack _index;
}; };
}; };
_cargo _cargo

View File

@ -1,21 +1,21 @@
/* /*
* Author: commy2 * Author: commy2
*
* Returns array of crew member objects. * Returns array of crew member objects.
* *
* Argument: * Arguments:
* 0: Vehicle (Object) * 0: Vehicle <OBJECT>
* 1: Slot types. Can contain "driver", "commander", "gunner", "turret", "cargo" and "ffv". Case sensitive (Array) * 1: Slot types filter (default: ["driver", "commander", "gunner", "turret", "cargo", "ffv"]) <ARRAY>
* *
* Return value: * Return Value:
* Crew (Array) * Crew <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_crew"]; params ["_vehicle", ["_types", ["driver", "commander", "gunner", "turret", "cargo", "ffv"]]];
PARAMS_2(_vehicle,_types);
private "_crew";
_crew = []; _crew = [];
// iterate through all crew members // iterate through all crew members
@ -31,6 +31,7 @@ _crew = [];
_crew pushBack (_x select 0); _crew pushBack (_x select 0);
}; };
}; };
} forEach fullCrew _vehicle; false
} count fullCrew _vehicle;
_crew _crew

View File

@ -1,11 +1,15 @@
/** /*
* fn_getVersion.sqf * Author: Glowbal
* @Descr: Get the version number of the current ACE Build * Get the version number of the current ACE build.
* @Author: Glowbal
* *
* @Arguments: [] * Arguments:
* @Return: STRING String containing the version * None
* @PublicAPI: true *
* Return Value:
* ACE Version <STRING>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
getText (configFile >> "cfgPatches" >> "ACE_main" >> "version");
getText (configFile >> "CfgPatches" >> "ACE_main" >> "version") // return

View File

@ -1,20 +1,21 @@
/* /*
* Author: commy2 * Author: commy2
* Get local players weapon direction and slope.
* *
* Get players weapon direction and slope * Arguments:
* 0: Weapon name <STRING>
* *
* Argument: * Return Value:
* 0: Weapon name (String) * 0: Azimuth <NUMBER>
* 1: Inclination <NUMBER>
* *
* Return value: * Public: Yes
* 0: Azimuth (Number)
* 1: Inclination or 'slope' (Number)
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_direction", "_azimuth", "_inclination"]; params ["_weapon"];
PARAMS_1(_weapon); private ["_direction", "_azimuth", "_inclination"];
_direction = ACE_player weaponDirection _weapon; _direction = ACE_player weaponDirection _weapon;

View File

@ -1,20 +1,23 @@
/* /*
* Author: commy2 * Author: commy2
* Get the index of the weapon. * Get the index of the weapon.
* 0 = primary, 1 = secondary, 2 = handgun, -1 = other
* *
* Argument: * Arguments:
* 0: Unit <OBJECT> * 0: Unit <OBJECT>
* 1: Weapon <STRING> * 1: Weapon <STRING>
* *
* Return value: * Return Value:
* Weapon index <NUMBER> * Weapon index <NUMBER>
* 0 = primary
* 1 = secondary
* 2 = handgun
* -1 = other
* *
* Public: No * Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_weapon); params ["_unit", "_weapon"];
if (_weapon == "") exitWith {-1}; if (_weapon == "") exitWith {-1};
@ -22,4 +25,4 @@ if (_weapon == "") exitWith {-1};
primaryWeapon _unit, primaryWeapon _unit,
secondaryWeapon _unit, secondaryWeapon _unit,
handgunWeapon _unit handgunWeapon _unit
] find _weapon ] find _weapon // return

View File

@ -1,30 +1,34 @@
/* /*
* Author: commy2 * Author: commy2
* Get the available firing modes of a weapon. Will ignore the AI helper modes.
* *
* Get the available firing modes of a weapon. Will ignore the ai helper modes. * Arguments:
* 0: Weapon <STRING>
* *
* Argument: * Return Value:
* 0: A weapon in cfgWeapons (String) * Firing Modes <ARRAY>
* *
* Return value: * Public: Yes
* All firing modes (Array)
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_modes"]; params ["_weapon"];
PARAMS_1(_weapon); private ["_config", "_modes"];
_config = configFile >> "CfgWeapons" >> _weapon;
_modes = []; _modes = [];
{ {
if (getNumber (configFile >> "CfgWeapons" >> _weapon >> _x >> "showToPlayer") == 1) then { if (getNumber (_config >> _x >> "showToPlayer") == 1) then {
_modes pushBack _x; _modes pushBack _x;
}; };
if (_x == "this") then { if (_x == "this") then {
_modes pushBack _weapon; _modes pushBack _weapon;
}; };
false
} forEach getArray (configfile >> "CfgWeapons" >> _weapon >> "modes"); } count getArray (_config >> "modes");
_modes _modes

View File

@ -1,20 +1,20 @@
/* /*
* Author: commy2 * Author: commy2
*
* Get the muzzles of a weapon. * Get the muzzles of a weapon.
* *
* Argument: * Arguments:
* 0: A weapon in cfgWeapons (String) * 0: Weapon <STRING>
* *
* Return value: * Return Value:
* All weapon muzzles (Array) * All weapon muzzles <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_muzzles"]; params ["_weapon"];
PARAMS_1(_weapon);
private "_muzzles";
_muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles"); _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");
if ("this" in _muzzles) then { if ("this" in _muzzles) then {

View File

@ -1,46 +1,28 @@
/* /*
* Author: commy2 * Author: commy2
*
* Return current state of the weapon. Attachments and magazines with ammo. * Return current state of the weapon. Attachments and magazines with ammo.
* *
* Argument: * Arguments:
* 0: A unit (Object) * 0: unit <OBJECT>
* 1: A weapon (String) * 1: weapon <STRING>
* *
* Return value: * Return Value:
* Weapon info, format: [attachments, muzzles, magazines, ammo] (Array) * 0: Attachements <ARRAY>
* 1: Muzzles <ARRAY>
* 2: Magazines <ARRAY>
* 3: Ammo <ARRAY>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_weapon); params ["_unit", "_weapon"];
private ["_muzzles", "_weaponInfo"];
private "_muzzles";
_muzzles = [_weapon] call FUNC(getWeaponMuzzles); _muzzles = [_weapon] call FUNC(getWeaponMuzzles);
private "_weaponInfo"; _weaponInfo = [["","","",""], primaryWeaponItems _unit, secondaryWeaponItems _unit, handgunItems _unit] select ((["", primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit] find _weapon) max 0);
_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 // get loaded magazines and ammo
private ["_magazines", "_ammo"]; private ["_magazines", "_ammo"];
@ -51,7 +33,8 @@ _ammo = [];
{ {
_magazines pushBack ""; _magazines pushBack "";
_ammo pushBack 0; _ammo pushBack 0;
} forEach _muzzles; false
} count _muzzles;
{ {
if (_x select 2) then { if (_x select 2) then {
@ -63,7 +46,8 @@ _ammo = [];
_ammo set [_index, _x select 1]; _ammo set [_index, _x select 1];
}; };
}; };
} forEach magazinesAmmoFull _unit; false
} count magazinesAmmoFull _unit;
_weaponInfo append [_muzzles, _magazines, _ammo]; _weaponInfo append [_muzzles, _magazines, _ammo];

View File

@ -1,19 +1,24 @@
/* /*
* Author: commy2 * Author: commy2
* Check what kind of weapon the given class name is.
* *
* Check what kind of weapon the given class name is. (primary, secondary or handgun) * Arguments:
* 0: Weapons <STRING>
* *
* Argument: * Return Value:
* 0: Class name of the weapon (String) * Slot index <NUMBER>
* 1 = primary
* 2 = secondary
* 3 = handgun
* -1 = other
* *
* Return value: * Public: Yes
* Slot index of the given class name, 1: primary, 2: secondary, 3: handgun, else: -1 (Number)
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_type", "_index"]; params ["_weapon"];
PARAMS_1(_weapon); private ["_type", "_index"];
_type = [getNumber (configFile >> "CfgWeapons" >> _weapon >> "type")] call FUNC(binarizeNumber); _type = [getNumber (configFile >> "CfgWeapons" >> _weapon >> "type")] call FUNC(binarizeNumber);
@ -23,9 +28,4 @@ while {!(_type select _index) && {_index < 16}} do {
_index = _index + 1; _index = _index + 1;
}; };
switch (_index) do { [-1, 1, 3, 2] select (([0, 1, 2] find _index) + 1) // return
case 0 : {1};
case 1 : {3};
case 2 : {2};
default {-1};
}