Home   Help Search Login Register  

Author Topic: Detect if a unit is present or not  (Read 1529 times)

0 Members and 1 Guest are viewing this topic.

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Detect if a unit is present or not
« on: 13 Sep 2006, 15:30:34 »
I've got a script that I have to initalize from the init.sqs for all units that are playable, but I don't want the script to be executed for the units who is disabled. Now, I know it works to add
Code: [Select]
? (Unitname != ObjNull) : infront of the execution line, however, since this is for a addon, I want to add that line in the script that is executed from the init.sqs...

i.e, u1, u2, u3 and u4 are playable units. In the init.sqs I have something like this:

Code: [Select]
[u1] exec "script.sqs"
[u2] exec "script.sqs"
[u3] exec "script.sqs"
[u4] exec "script.sqs"

and then in script.sqs I have some check which exits the script if _this select 0 is not present. So if u1, u2 and u3 are present, then the script runs for them, but not for u4, since he was disabled before the mission started.

Offline tommi

  • Members
  • *
Re: Detect if a unit is present or not
« Reply #1 on: 13 Sep 2006, 17:24:50 »
I'm not quite sure what you mean, but try this:           

name the units e.g.    u1  u2 u3 u4  for west and for east  r1  r2  r3  r4                 

then make a trigger for each unit

size: 0/0
activation: none
text: Scriptr1
condition: local r1
onActivation: r1 exec "script.sqs";                                  (where it says r1 you put your units name...)

I'm not 100% sure of that, but it should work like that...   :)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Detect if a unit is present or not
« Reply #2 on: 13 Sep 2006, 17:51:49 »
Name each unit like you did it already

;init.sqs

Code: [Select]
units_array = []

"if alive _x then {units_array = units_array + [_x]" forEach [u1,u2,u3,u4,r1,r2,r3,r4]

What it does?

It initializes an array (units_array) and then puts each alive unit of given units
inside the brackets into the array.

At the end units_array would look like this: [u1,u2,u3,u4,r1,r2,r3,r4]
if all of these units were choosen and/or enabled.
If one of the units doesn't exist, it will not be inside
units_array.

whatever you want to with the units later, you can do it - forEach units_array


@tommi

When opening this thread i would have expected a similar anwer of you, especially because
i spent one and a half week of showing you this method (remember the init.sqs of your money script problem).

:edit - btw - there's another variant, using the same technique but executing the script straight without putting
them into an array;

Code: [Select]
"if alive _x then {[_x] exec {script.sqs}}" forEach [u1,u2,u3,u4,r1,r2,r3,r4]
~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Detect if a unit is present or not
« Reply #3 on: 13 Sep 2006, 18:19:02 »
@ CD

I'm too tired to think  ::) so I put the system what BIS used on Real Paint Ball