Jump to content
Sign in to follow this  
Tinker

Creating a counter

Recommended Posts

Would like to end a mission if the player group has less M136 magazines than the Tank counter. Not looking good so far, maybe someone can help.

Mission with 3 Tanks.

init.sqf:

[] execVM "tank_check.sqf";

tank_check.sqf

Tanks=3;

!alive Tank1;

Tanks=Tanks-1;

!alive Tank2;

Tanks=Tanks-1;

!alive Tank3;

Tanks=Tanks-1;

How to check if the number of M136 magazines available to the group is lower than the Tanks counter.

If anyone can make sense of this would be appreciated.

*Edit*

Seems more sense to have a trigger for each tank, !alive tank1 etc call tank_check.sqf

Need to find how to count m136 mags in this list/group and check if lower than counter.

Edited by Tinker

Share this post


Link to post
Share on other sites

Hm I had an rpg ammo counter in my first mission, think it was somethin like hasAmmo "className".

However if you're giving the player(s) a specific number of m136 missiles, then you already know how many they have and you can add a FIRED eventhandler which deducts 1 from the total each time the m136 is fired. But then your approach might be easier anyway.

Is this a coop mission, or sp where the player is the one with the m136? It'll dictate how many people you have to check each time with that script. Not sure if you can use hasAmmo with groups, might work.

Edit: nvm no such thing as hasAmmo lol, try this

[i]unit[/i] ammo [i]magazine[/i]

Edited by JDog

Share this post


Link to post
Share on other sites

Hi

Just trying to work out how to do this kind of a counter. My missions usually have 9 slots, usually play with around 6 guys, no respawn, and now I am to set the kits up for them all ready. Let us say there are 3 AT slots available, each holding 2 rockets. We have a mission that has 2 tanks in the brief, so we take up 2 of the slots and the others go as sniper or rifleman etc. That would give the group 4 rockets at mission start.

So I wanted to run a script every 20 seconds that checks if the groups rocket count is less than the value of the tanks count, which would be 2 in this. decrementing each time a tank is killed., and killing the script once both tanks are down.

From here I can have satchel scripts and so also, for demo missions etc.

Share this post


Link to post
Share on other sites

The command ammo does return a numerical value for the given magazine.

I was trying to do this a few evenings ago and did not get it to work.

Here is an untested stab in the dark:

while {true} do {

_count1 = _unit1 ammo "M136";

_count2 = _unit2 ammo "M136";

_count3 = _unit3 ammo "M136";

_countTot = (_count1 +_count2 + _count3);

sleep 20;

};

if (_countTot <= 2) then

endMission "END1";

};

I think my logic is reasonably sound but the syntax and script is probably way off. If anyone can correct this we will both be very happy!

Share this post


Link to post
Share on other sites
private ["_a","_t"];
while {sleep 20;true} do {
 _a = 0;
 {
   _a = _a + (_x ammo "M136");
 } foreach playableunits;
 _t = {damage _x < 0.8} count [tank1,tank2,tank3];
 if (_a < _t) exitwith {
   endmission "END1";
 };
};

Share this post


Link to post
Share on other sites

Nice work shk - Thank you!

Another interesting way of using forEach.

I have been studying your scripts. I will get there one day. :)

Share this post


Link to post
Share on other sites

If you are planning on using it just for multiplayer missions, I'd wrap it in isserver check to make the server only do the checking and then with publicvariable sync the ending so that mission will surely end on each client.

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  

×