profcupcake 11 Posted October 22, 2013 Is there any easy way to find a vehicle ammo value for any given vehicle as a value between 0 and 1? I.E. Like the value you would enter for setVehicleAmmo. Failing that, how would I go about finding the max. ammo for any given vehicle's weapons? That way I could try something like this: (Total ammo in vehicle)/(maximum ammo for vehicle) Share this post Link to post Share on other sites
jacmac 2 Posted October 22, 2013 (edited) You are in luck because "magazinesAmmo vehicle" will return an array of all magazines and their ammo counts. Also check magazinesAmmoFull and magazinesTurret. This used to be a near impossible task. You can look up the vehicle's config for magazines and the vehicle's turrets for magazines and then look up the magazines themselves to find the max ammo counts. When you setVehicleAmmo 1, you are basically saying to fill the vehicle and all turrets with the default ammo for that vehicle's config. If you setVehicleAmmo 0.5, I guess you would probably end up with half ammo for each magazine type in that vehicle's config, but I'm not sure how it reacts. Edited October 22, 2013 by Jacmac Share this post Link to post Share on other sites
profcupcake 11 Posted October 22, 2013 (edited) You are in luck because "magazinesAmmo vehicle" will return an array of all magazines and their ammo counts. Also check magazinesAmmoFull and magazinesTurret. This used to be a near impossible task. You can look up the vehicle's config for magazines and the vehicle's turrets for magazines and then look up the magazines themselves to find the max ammo counts.When you setVehicleAmmo 1, you are basically saying to fill the vehicle and all turrets with the default ammo for that vehicle's config. If you setVehicleAmmo 0.5, I guess you would probably end up with half ammo for each magazine type in that vehicle's config, but I'm not sure how it reacts. I've got the first part of this working, but I'm still not so sure how I can get the magazine capacity. You mentioned looking in the vehicle's or the magazine's config - is there a way to do this on-the-fly? This is really annoying. I just found this: http://community.bistudio.com/wiki/magazinesDetail I could probably work with this, but lacking any knowledge about string handling in Arma's scripting language, I have no idea if the potential solution I have in mind is even possible. Is there any support for regular expressions (or similar)? Wait, I'm looking into toArray now. Gonna try and work something in using this. It won't be neat, but it should work. What I'd give for Lua support right now. Ack. Screw it. I'm giving up to work on something else for now, but before I do the metaphorical walk of shame, here's what I have so far: _magazinesDetail = magazinesDetail vehicle player; _currentTotal = 0; _maximumTotal = 0; { _array = toArray _x; _beginPose = 0; _endPos = 0; _middlePos = 0; { if (_x == 40) then { _beginPos = _forEachIndex; }; if (_x = 47) then { _middlePos = _forEachIndex; }; if (_x = 41) then { _endPos = _forEachIndex; }; } forEach _array; _tick = 0; _currentArray = []; _maximumArray = []; for "_i" from (_beginPos + 1) to (_middlePos) do { _currentArray set [_tick, (_array select _i)]; _tick = _tick + 1; }; _tick = 0; for "_i" from (_middlePos + 1) to (_endPos) do { _maximumArray set [_tick, (_array select _i)]; _tick = _tick + 1; }; _current = parseNumber toString _currentArray; _maximum = parseNumber toString _maximumArray; _currentTotal = _currentTotal + _current; _maximumTotal = _maximumTotal + _maximum; } forEach _magazinesDetail; _getVehicleAmmo = _currentTotal/_maximumTotal; cutText [format ["%1/%2 = %3", _currentTotal, _maximumTotal, _getVehicleAmmo], "PLAIN"]; Yes, I know, it's a mess. Edited October 22, 2013 by ProfCupcake Share this post Link to post Share on other sites
jacmac 2 Posted October 22, 2013 Is there any support for regular expressions (or similar)? Look at the BIS functions library in the ARMA editor (fx). You can filter the functions to strings and see many functions available. I wouldn't say there is regular expression capability, but simple string handling is there. With regard to configs, look a this: http://browser.six-projects.net/cfg_vehicles Share this post Link to post Share on other sites
Hypnomatic 10 Posted October 23, 2013 The following should get the value you're looking for: _maxAmmo = getNumber(configFile >> "CfgMagazines" >> _magazineClassName >> "count") ; And as a usage example, the following will generate an array of 2 element arrays formatted as [magazineClassName, maxAmmoCount] for every magazine in the player's vehicle (or inventory if they're on foot). _output = []; { _output set [count _output, [_x, getNumber(configFile >> "CfgMagazines" >> _x >> "count") ]]; } forEach (magazines (vehicle player)); hint str _output; Now are far at parsing the string goes, I actually wrote a script to do exactly this before magazinesAmmo was imlpemented, as it was the only way I could find to get the ammo of magazines not currently loaded. It's not pretty, and it's more or less completely outdated thanks to magazinesAmmo/magazinesAmmoFull and the config check, but it may be interesting: private["_output","_lParen","_rParen","_fwdSlash","_magazinesDetail"]; _output = []; _lParen = toArray("(") select 0; _rParen = toArray(")") select 0; _fwdSlash = toArray("/") select 0; _magazinesDetail = (magazinesDetail (vehicle player)); { private["_currentAmmo","_maxAmmo","_inCurrentAmmo","_inMaxAmmo"]; //Arrays to store the characters of the values we're getting _currentAmmo = []; _maxAmmo = []; //Bools to keep track of which chunk of the string we're in _inCurrentAmmo = false; //True once Left Paren is hit, and false again if it hits an unexpected character _inMaxAmmo = false; //True once the forward slash is hit, and _inCurrentAmmo is true { /* Quick explanation: These if statements are expected to evaluate true from the bottom up. Ie: _x will be a useless character until it's a left paren. Then _x will be a digit in the current ammo until it's a forward slash. And until _x is a right paren, it is a digit in the max ammo count. Once _x hits a right paren after that, quit parsing because everything desired has been found. Note the extra check in if(_inCurrentAmmo) exitWith {...}; This check is needed as some magazine names have Parenthesis too. */ if (_x == _rParen && _inMaxAmmo && _inCurrentAmmo) exitWith {}; //Hit the closing paren of the ammo counts if true then { //Create a new scope so exitWith doesn't break the loop, effectively other language's "continue" if (_inMaxAmmo) exitWith { _maxAmmo set [count _maxAmmo, _x]; }; if (_x == _fwdSlash && _inCurrentAmmo) exitWith { _inMaxAmmo = true; }; if (_inCurrentAmmo) exitWith { if (_x in toArray("01234567890-.")) then { _currentAmmo set [count _currentAmmo, _x]; } else { _currentAmmo = []; _inCurrentAmmo = false; }; }; if (_x == _lParen) exitWith { _inCurrentAmmo = true; }; }; } forEach toArray(_x); //Convert the two arrays of characters to their corresponding values _currentAmmo = parseNumber(toString(_currentAmmo)); _maxAmmo = parseNumber(toString(_maxAmmo)); //Push them to outputas a 2 element array, where element 0 = current ammo, and element 1 = max ammo _output set [count _output, [_currentAmmo, _maxAmmo]]; } forEach _magazinesDetail; //At this point output contains all values for magazine ammo hint str _output; Share this post Link to post Share on other sites
profcupcake 11 Posted October 24, 2013 The following should get the value you're looking for: _maxAmmo = getNumber(configFile >> "CfgMagazines" >> _magazineClassName >> "count") ; Worked perfectly, thank you very much. Share this post Link to post Share on other sites
BEAKSBY 11 Posted July 17, 2014 (edited) Hi Folkes, Here it is...but I had to cheat for the B_G_Offroad_01_armed_F as getArray (configFile >> "CfgVehicles" >> typeOf cursorTarget >> "Turrets" >> "MainTurret" >> "magazines"); is not not defined in CfgVehicles. // Gets how much ammunition (compared to a full state defined by the vehicle in the cursorTarget) the vehicle has. The value ranges from 0 to 1. // Need to test in MP for remote objects _magCount = 0; _mags = []; _totalCurAmmo = 0; _VehAmmoArray = []; _getVehicleAmmoDef = 0; while {alive player} do { _maxAmmoArray = []; _VehAmmoArray = []; _defAmmoCount = 0; // default ammo per magazine _VehAmmoArray = getArray (configFile >> "CfgVehicles" >> typeOf cursorTarget >> "Turrets" >> "MainTurret" >> "magazines"); _defAmmoCount = getNumber (configFile >> "CfgMagazines" >> ((magazines cursorTarget) select 0) >> "count"); _defTotalAmmo = 0; { _defTotalAmmo = _defTotalAmmo + (getNumber (configFile >> "CfgMagazines" >> _x >> "count")); } forEach _VehAmmoArray; if (typeOf cursorTarget == "B_G_Offroad_01_armed_F") then {_defTotalAmmo = 400}; // cheat as it's not defined in CfgVehicles // need to update this for O_G_Offroad_01_armed_F _magCount = count (magazines (cursorTarget)); _totalCurAmmo = 0; { _totalCurAmmo = _totalCurAmmo + (_x select 1); } forEach (magazinesAmmo cursorTarget); //Hint format ["magazinesAmmo: %1 \n\n getDamage: %2 \n\n typeOf: %3 \n\n _VehAmmoArray: %4 \n\n _defAmmoCount: %5 \n\n _magCount: %6 \n\n _totalCurAmmo: %7 \n\n magazines cursorTarget %8 \n\n _defTotalAmmo: %9 \n\n _getVehicleAmmoDef: %10", // magazinesAmmo cursorTarget, getDammage cursorTarget, str typeOf cursorTarget, _VehAmmoArray, _defAmmoCount, _magCount, _totalCurAmmo, magazines cursorTarget, _defTotalAmmo, _getVehicleAmmoDef]; _getVehicleAmmoDef = 0; _getVehicleAmmoDef = (_totalCurAmmo/_defTotalAmmo); Hint format ["magazinesAmmo: %1", _getVehicleAmmoDef]; sleep 1; }; Edited July 18, 2014 by BEAKSBY 1 Share this post Link to post Share on other sites
BEAKSBY 11 Posted July 18, 2014 The script above should really be called getVehicleAmmoDef which is analogous to setVehicleAmmoDef. Share this post Link to post Share on other sites
pSiKO 124 Posted April 10, 2020 based on beaksby script, I made a function : // to get vehicle ammo _ammo = [_vehicle ] call getVehicleAmmoDef; // to set vehicle ammo _vehicle setVehicleAmmoDef _ammo; //define function getVehicleAmmoDef = compileFinal preprocessFileLineNumbers "scripts\shared\functions\getVehicleAmmoDef.sqf"; getVehicleAmmoDef.sqf params ["_vehicle"]; _totalCurAmmo = 0; _getVehicleAmmoDef = 0; _VehAmmoArray = []; _defAmmoCount = 0; // default ammo per magazine _VehAmmoArray = getArray (configFile >> "CfgVehicles" >> typeOf _vehicle >> "Turrets" >> "MainTurret" >> "magazines"); _defAmmoCount = getNumber (configFile >> "CfgMagazines" >> ((magazines _vehicle) select 0) >> "count"); _defTotalAmmo = 0; { _defTotalAmmo = _defTotalAmmo + (getNumber (configFile >> "CfgMagazines" >> _x >> "count")); } forEach _VehAmmoArray; if (typeOf _vehicle == "B_G_Offroad_01_armed_F") then {_defTotalAmmo = 400}; // cheat as it's not defined in CfgVehicles // need to update this for O_G_Offroad_01_armed_F _totalCurAmmo = 0; { _totalCurAmmo = _totalCurAmmo + (_x select 1); } forEach (magazinesAmmo _vehicle); _getVehicleAmmoDef = 0; _getVehicleAmmoDef = (_totalCurAmmo/_defTotalAmmo); _getVehicleAmmoDef; Share this post Link to post Share on other sites