Jump to content

Recommended Posts

hey guys,

with this code i can check how much ammo/bullet in the currentweapon magzine left:

Trigger:

Condition:
player ammo currentWeapon player == 0

On Activation:
null = [] execVM "SpawnAmmo.sqf"

but how would i check if  0 magazines for the currentweapon left ?

Share this post


Link to post
Share on other sites

 

Hiho

 

Spoiler

_magazine = currentMagazine player;

Quote

 

should return "" if no magazine is inserted, so you could check for an empty string (" ") 

Quote

 

Condition (_magazine == "")

Or (currentMagazine player == "") 

 

 

Do you also want to check if matching magazines are left in the inventory? 

 

Then you would have to build in a check like:

 

Quote

"magazineClassName" in magazines player;

 

Or, if you want to check for all matching magazines for your current weapon:

Quote

 

_weapon = currentWeapon player;

_magazines =  getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");

 

_magazines in magazines player;

 

 

So your combined and condensed condition could be:

 

Quote

currentMagazine player == "" & & ! ((getArray (configFile >> "CfgWeapons" >> currentweapon player >> "magazines")) in magazines player) 

 

I do admit that i am on my handheld and can not test the code myself right now. But will double check the condition on the evening and post a correction here if i made a mistake. 

Posting it anyway as it might point you into the direction of a possible solution:) 

 

Cheers

Vd

Edited by Vandeanson
  • Thanks 1

Share this post


Link to post
Share on other sites
31 minutes ago, Vandeanson said:

 

Hiho

 

  Reveal hidden contents

_magazine = currentMagazine player;

should return "" if no magazine is inserted, so you could check for an empty string (" ") 

 

Do you also want to check if matching magazines are left in the inventory? 

 

Then you would have to build in a check like:

 

 

Or, if you want to check for all matching magazines for your current weapon:

 

So your combined and condensed condition could be:

 

 

I do admit that i am on my handheld and can not test the code myself right now. But will double check the condition on the evening and post a correction here if i made a mistake. 

Posting it anyway as it might point you into the direction of a possible solution:) 

 

Cheers

Vd

Thank you for your reply!

i did like this to check how much magazines are left regardless for which weapon:

((count magazines player) == 0)

and it does work.

but offcurse what you posted is better, checking magazines only for currentweapon.

34 minutes ago, Vandeanson said:

currentMagazine player == "" & & ! ((getArray (configFile >> "CfgWeapons" >> currentweapon player >> "magazines")) in magazines player) 

but i got an error:

missing " ) "

 

 

Share this post


Link to post
Share on other sites

Ok.. hm then it will be a bit of a guessing game for me until i get to a pc:)

 

I am not very solid with checking for false conditions like the below.. 

 

Try this, else i will figure it out later tonight and send it to you. 

 

currentMagazine player == "" & & ! (getArray (configFile >> "CfgWeapons" >> currentweapon player >> "magazines") in magazines player) 

 

 

Share this post


Link to post
Share on other sites
15 minutes ago, Vandeanson said:

Ok.. hm then it will be a bit of a guessing game for me until i get to a pc:)

 

I am not very solid with checking for false conditions like the below.. 

 

Try this, else i will figure it out later tonight and send it to you. 

 

currentMagazine player == "" & & ! (getArray (configFile >> "CfgWeapons" >> currentweapon player >> "magazines") in magazines player) 

 

 

thx 😃

also throw the same error, messed abit around and got it working like this:

((count magazines player) == 0) && !((getArray (configFile >> "CfgWeapons" >> currentWeapon player >> "magazines") in magazines player))

thank you very much for your help.

  • Haha 1

Share this post


Link to post
Share on other sites

Aaah nice! Those damn brackets get me every time:) 

  • Like 1

Share this post


Link to post
Share on other sites
19 hours ago, Alert23 said:

((count magazines player) == 0) && !((getArray (configFile >> "CfgWeapons" >> currentWeapon player >> "magazines") in magazines player))

Doesn't take magazineWells into account.
There might be weapons with dozens of supported magazines, but empty magazines array in config.

 

also the second condition will never work properly, you are checking if an array is inside an array of strings. A string is never an array though so it will never be inside there.

The second part is always !(false) thus always true.
So you might aswell remove the whole second part.

 

((count magazines player) == 0)

 

If you want to check how many compatible magazines for current weapon the player has


 

private _compatibleMagazines = getArray (configFile >> "CfgWeapons" >> currentWeapon player >> "magazines");
private _availableMagCount = {_x in _compatibleMagazines} count magazines player;


There you have number of magazines, though again not magazine wells compatible. I'd say just use the CBA Function but I don't know if you have CBA.

 

 

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites
47 minutes ago, AlecW said:

getArray (configFile / "C

 

The / seems wrong here, that should be >> i believe. 

 

That might prevent your script from working. 

With regards to your for.. Do code, i dont understand what you want to do there sorry:( but that might just be due to a lack of knowledge on my end. 

Share this post


Link to post
Share on other sites
1 minute ago, Vandeanson said:

 

The / seems wrong here, that should be >> i believe. 

 

That might prevent your script from working. 

With regards to your for.. Do code, i dont understand what you want to do there sorry:( but that might just be due to a lack of knowledge on my end. 

I posted a topic with a bit more info here 🙂

 

Share this post


Link to post
Share on other sites
2 hours ago, Vandeanson said:

The / seems wrong here, that should be >> i believe. 

Both are valid.

 

Share this post


Link to post
Share on other sites

This is what i'm using :

_Mags = {_x in getArray (configFile >> "CFGWeapons" >> (currentWeapon player) >> "magazines")}count (magazines player);

 

  • Like 2

Share this post


Link to post
Share on other sites
12 hours ago, GEORGE FLOROS GR said:

This is what i'm using :

Exact same result as my code. 90% the same code as my code. But vastly less efficient as you do config lookups on every iteration.

  • Like 1

Share this post


Link to post
Share on other sites
12 hours ago, Dedmen said:

less efficient

 

Maybe now is better ?

_Mags = {_x == currentMagazine player}count(magazines player);

 

Share this post


Link to post
Share on other sites
8 hours ago, GEORGE FLOROS GR said:

Maybe now is better ?

Performance wise yes, but that doesn't work if the player has different types of magazines or no magazine loaded.

  • Like 1

Share this post


Link to post
Share on other sites
TAG_fnc_numMagsAvailable = {
	params[ [ "_weapon", currentWeapon player, [ "" ] ] ];

	_magazines = [];

	{
		{
			_magazines append getArray( _x );
		}forEach configProperties[ configFile >> "CfgMagazineWells" >> _x ];
	}count getArray( configFile >> "CfgWeapons" >> _weapon >> "magazineWell" );

	_compatibleMagazines = getArray( configFile >> "CfgWeapons" >> _weapon >> "magazines" );
	_magazines append _compatibleMagazines;
	_magazines = _magazines arrayIntersect _magazines;
	_magazines = _magazines apply{ toLower _x };

	{
		toLower _x in _magazines
	}count magazines player;

};

[ primaryWeapon player ] call TAG_fnc_numMagsAvailable

Doesn't include loaded mag as OP said he is already counting that mags available ammo.

Tested on B_soldier_F carrying standard loadout of arifle_MX_F and mags. Roughly 0.056ms from console test.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, Larrow said:

false }count

forEach is faster than count if you have to insert a true/false to make it work.

 

6 hours ago, Larrow said:

_x in _magazines

That is not reliable, "in" is case-sensitive, but the magazines that you get out of magazines array or CfgMagazineWells might not be correct capitalization.

 

On 5/14/2019 at 11:45 AM, Dedmen said:

I'd say just use the CBA Function but I don't know if you have CBA

Guess I'm not getting any answer to that?

 

CBA variant:

private _compatibleMagazines = [primaryWeapon player] call CBA_fnc_compatibleMagazines;

private _magazineCount = {_x in _compatibleMagazines} count magazines player;

CBA function caches the compatible magazines which makes it fast, and it makes sure classnames are correct capitalization thus "in" will work reliably.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
12 hours ago, Dedmen said:

forEach is faster than count if you have to insert a true/false to make it work.

true, but what if you use a variable assignment instead?

 

{

 _d =

 {

 } count array;

} count array2;

Share this post


Link to post
Share on other sites
11 hours ago, Dedmen said:
On 5/14/2019 at 11:45 AM, Dedmen said:

I'd say just use the CBA Function but I don't know if you have CBA

Guess I'm not getting any answer to that? 

hey sry that i dident answer,

yes i always use cba =) just because of the debug consol :)

i will try that and thank you very much for your help.

  • Like 1

Share this post


Link to post
Share on other sites
12 hours ago, Dedmen said:

forEach is faster than count if you have to insert a true/false to make it work.

With this particular code on my hardware there was very little difference( talking +/-0.002ms ) but on multiple test foreach seemed to spike longer more often than count with false, so that why I left it like that.

 

12 hours ago, Dedmen said:

That is not reliable, "in" is case-sensitive, but the magazines that you get out of magazines array or CfgMagazineWells might not be correct capitalization.

Aye true, naming consistency in configs, even in official content, is a pain in the arse. My original post did take this into account, but then after messing around testing performance I changed it and forgot all about testing case.

Updated code for those who need magazines checking without having to install CBA just for that.

 

Share this post


Link to post
Share on other sites
Result:
0.477783 ms

Cycles:
2093/10000

Code:
_array = [1,4,65,6,7,4,3,2,4,6,7,8,5,3,2,4,6,7,7,5,4,3,2,2,3,5,6,7,87,4,2,2,3,4,5];  
{   
 {  
 } count _array; 
 true 
} count _array;

 

Result:
0.476872 ms

Cycles:
2097/10000

Code:
_array = [1,4,65,6,7,4,3,2,4,6,7,8,5,3,2,4,6,7,7,5,4,3,2,2,3,5,6,7,87,4,2,2,3,4,5];  
{   
 _d = {
 } count _array; 
} count _array;
Result:
0.71736 ms

Cycles:
1394/10000

Code:
_array = [1,4,65,6,7,4,3,2,4,6,7,8,5,3,2,4,6,7,7,5,4,3,2,2,3,5,6,7,87,4,2,2,3,4,5];  
{   
 {
 } forEach _array; 
} count _array;

 

Share this post


Link to post
Share on other sites
On 5/25/2019 at 1:22 PM, sarogahtyp said:

{ { } forEach _array; } count _array

In the first two pieces of code you were measuring the outer loop, now you replace the inner one?

 

_array = [1,4,65,6,7,4,3,2,4,6,7,8,5,3,2,4,6,7,7,5,4,3,2,2,3,5,6,7,87,4,2,2,3,4,5];  

The others are this combined with the code. This takes 0.0074ms, could deduct that from the time if one wanted.

 

{0; true} count _array;

0.0559ms

{_d = 0;} count _array;

0.0483ms

{0;} forEach _array;

0.0443ms

 

Aaand because I can
 

_array fastForEach {0;}

0.041ms

 

AMD CPU vs Intel might make a difference here.

 

On 5/25/2019 at 1:22 PM, sarogahtyp said:

Cycles: 1394/10000

With that low precision the results aren't worth that much.

 

On 5/25/2019 at 10:23 AM, sarogahtyp said:

but what if you use a variable assignment instead?

Genius idea, haven't thought of that myself yet. Its alot cheaper than using true/false/nil but still not as cheap as a normal forEach.

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

×