Jump to content
Sign in to follow this  
das attorney

weaponslots help

Recommended Posts

Sup

I'm writing a reloading script and at one point, the script needs to determine how many total slots for magazines the unit has. I'm currently doing this by the following method:

if (getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "attendant") == 1) then
{_total_slots_main = 8} else {_total_slots_main = 12};

if (getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "attendant") == 1) then {
_total_slots_sec = 4;
} else {_total_slots_sec = 8};

This is great, but when I was testing the script in a mission the other night, I found that the US_Pilot_Light_EP1 has only 6 main magazine slots and also the Bonesetter in Takistani locals is a medic but has 12 slots in main inventory. I guess I could put an exception in for these units and use SWITCH DO but it seems a bit specific.

I want to find a method of determining the number of available slots for a unit based on it's config. Then the script would be compatible with any custom modded units too.

I was looking at the weaponSlots config entry, which determines what equipment a unit can carry, but I can't work out how to read/manipulate it so I can get the information out of it.

If I use:

diag_log format ["%1", getNumber(configFile >> "CfgVehicles" >> "US_Pilot_Light_EP1" >> "weaponslots")];

then I get something like the following returned:

1.58266e+006

I don't know what this number is (integer perhaps??).

Also I tried:

diag_log format ["%1", getText(configFile >> "CfgVehicles" >> "US_Pilot_Light_EP1" >> "weaponslots")];

which returns this string:

"1 + 4 + 6 * 256 + 2 * 4096 + 2 + 4* 16 + 12*131072"

I know the numbers I'm interested in are these:

"1 + 4 + 6 * 256 + 2 * 4096 + 2 + 4* 16 + 12*131072"

Which is primary mags and pistol/GP25/M203 slots.

I can do a bit with this, but I'm still stuck.

I wrote a little script to convert it to array, remove the spaces, + and * characters:

_weaponslots_text = getText(configFile >> "CfgVehicles" >> typeOf player >> "weaponslots");
_weaponslots_chars = toArray _weaponslots_text;
_elements_to_erase = [32, 42, 43];
_na = _weaponslots_chars - _elements_to_erase;
_nas = toString _na;

and then I can return the _na and _nas values, but it hasn't helped. I get:

"[49,9,9,52,9,54,9,9,50,53,54,9,50,9,52,48,57,54,9,9,50,9,52,9,49,54,49,50,49,51,49,48,55,50]"

"1 4 6 256 2 4096 2 4 1612131072"

The problem is I can't look through the elements of _na because the main slots might be 12 on a different unit, which would throw everything else out after by one element. I don't really know much about reading and manipulating strings either so I'm stuck there too.

Has anyone got any ideas how I could manipulate the data in a better way. I've searched around but all of the threads I could find were concerning defining the slots and not taking data from them.

Thanks for reading.

Edited by Das Attorney

Share this post


Link to post
Share on other sites

Could BIS_fnc_invSlots be of any use to you?

Although it takes a unit as an in-parameter I suppose the code could be adapted for your use...

It returns an array of slots [0,0,0,0,0,0,0,0]

in this order:

#define WeaponSlotPrimary 1 // primary weapons

#define WeaponSlotHandGun 2 // HandGun

#define WeaponSlotSecondary 4 // secondary weapons

#define WeaponSlotHandGunItem 16 // HandGun magazines

#define WeaponSlotItem 256 // items

#define WeaponSlotBinocular 4096 // binocular

#define WeaponHardMounted 65536

#define WeaponSlotInventory 131072 // inventory items

Share this post


Link to post
Share on other sites

Thank you very much for your help. This works great :)

Just ran a test to reload a few units with different sized inventories and all working perfectly.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×