Jump to content
Sign in to follow this  
Papua

Triggers - !Alive or Null

Recommended Posts

OK I need a command that checks whether a unit exists or not. I have

!(alive tank1) && !(alive tank2) && !(alive tank2) && ... etc 

as the trigger for the end of my mission. But tanks 1,2 and 3 are all on a 50% probability of spawning.

If tank1 doesn't spawn to begin with then

!(alive tank1)

never gets activated because tank1 isn't actually dead, it was just never there from the start.

So basically I'd like the function for

(!(alive tank1) or !([i]exists?/spawned?/null?[/i] tank1))

Does that make sense?

Either that or I was thinking I could set a up variable and +1 to it for each tank that spawns, then -1 for every tank that is destroyed, and have the trigger listen for when the variable == 0. But I'm really not sure how to approach that either. Any tips gratefully received.

Edited by Papua

Share this post


Link to post
Share on other sites

Try adding a radio command with:

hint format ["%1",tank1];

In the on activate line. Then run the radio trigger in game. You'll note the different outputs you see when the tank exists or not. I'm at work, so I can't recall what the "it doesn't exist" output is (something like "null undefined" or etc...), but basically write that down exactly (case sensitive), wrap it in quotes, and then try and detect it in game, i.e.:

(!(alive tank1) or (format ["%1",tank1] == "<insert null text>"))

P.S. You can then delete the radio command, thats just for testing :)

Share this post


Link to post
Share on other sites

If the tanks are placed in the editor and not added by script you can set the condition of presence to alive tank1 for the two additional tanks, in addition to their probability of presence.

Share this post


Link to post
Share on other sites

Put this init for each tank:

tanks = + [this]

The trigger Condition:

d=true; {d=d and not alive _x} foreach tanks; d

No need to give tanks a name.

Share this post


Link to post
Share on other sites
Put this init for each tank:
tanks = + [this]

The trigger Condition:

d=true; {d=d and not alive _x} foreach tanks; d

No need to give tanks a name.

Thanks alot alef, this seems to work, but could I be a pain and ask exactly what its doing? A variable called tanks that gets +1 when a tank spawns in the init field, I get that bit. But what is the trigger doing? Specifically what are d and _x all about?

Also whilst playing multiplayer earlier it triggered when only 3 of 6 the tanks present had been destroyed. Could you shed any light? Thanks!

Share this post


Link to post
Share on other sites
The trigger Condition:
d=true; {d=d and not alive _x} foreach tanks; d

This trigger condition is absolute nonsense to me. d=true isn't a condition, neither {d=d and not alive _x} foreach tanks. Only "d" maybe a condition.

Share this post


Link to post
Share on other sites

Ok, I also don't have any idea what alefs code is doing and after a bit of further testing it seems that it doesn't work as I thought. So back to the drawing board...

Thanks for the advice from Rocket as well. That gives me 'any' as the command but when I put it into the trigger as you described it doesn't seem to work either...

To summarise -

I have a multiplayer co-op mission.

I have a set of 10 tanks scattered across a city that spawn on a Probability of Presence of 50%. This works great.

Markers appear on the tanks that spawn and are updated by triggers when they are killed to indicate on the map that they've already been destroyed. This also works perfectly.

Now the bit i'm struggling with is -

When the spawned tanks are all dead I want a trigger to go true.

This shouldn't be that difficult to achieve should it? Any more help gratefully received.

Share this post


Link to post
Share on other sites

I've tested on SP only.

However, "tanks" is an array containing each spawned tank. The syntax tanks = + [this] is the only I've found that allow an array to de defined while the content is added. This helps because you don't need to care which is the first init line that gets executed in the mission.sqm. Otherwise, you should have put a line tanks = [] somewhere, maybe in a GameLogic, and edit the mission.sqm to be sure that line gets executed first than the tanks init lines.

The trigger condition is a piece of code that run every half second. It starts defining d as boolean "true". Then, for-each of the elements in the array "tanks", that d is assigned to the value of d and the fact the that tank (_x) is dead. This means, if any of the tanks is alive, d became false. Then, d is returned as result of the trigger.

Sorry, but I don't know how to help this working in MP.

Share this post


Link to post
Share on other sites

interesting condition you have there alef, but a bit more complicated than necessary:

condition:

{alive _x} count tanks == 0

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  

×