Home   Help Search Login Register  

Author Topic: [SOLVED] Checking existed unit.  (Read 2492 times)

0 Members and 1 Guest are viewing this topic.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
[SOLVED] Checking existed unit.
« on: 07 Nov 2012, 13:58:12 »
I have eight playable soldier: p1,p2...p7,p8.

It's really important to me how many of them is exits in the mission. Players can disable units in multiplayer dialog, before start the mission and I must know which of them exits. I tried
Code: [Select]
if (p1 != objNull) thenbut it rise an exception if p1 not exists to p1 is unknown variable.
What can I do?

Why I need to know?

1. In the init script I armed an unarmed soldier (p7), but I don't want to do that if he is not play.
2. These players have to meet and join to a squad and I need a trigger to detect when all of them is ready in the squad. If all are in play, it's easy. But if the players decided to turn of one of them, how can I check the squad is full or they need to find anybody else?
3. These players can select weapons in the briefing, but in the beginning of the mission I remove all of these and put it in different containers (two persons' equipment in each container) and I have to remove the unused containers.
« Last Edit: 09 Nov 2012, 21:29:49 by bardosy »
Fix bayonet!

Offline Pirin

  • Members
  • *
Re: Checking existed unit.
« Reply #1 on: 08 Nov 2012, 02:04:24 »
You can use playableUnits to get an array of currently active slots (player or AI).  This command only works in MP though, not the editor so don't be surprised if the count is off in the editor.

To test if a specific unit is active you can use:

Code: [Select]
if (p7 in playableUnits) then {
    // arm P7 here
};

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: Checking existed unit.
« Reply #2 on: 08 Nov 2012, 08:00:11 »
Thank you for the quick answer! I will try it.

EDIT:

Sorry, but it is worst then the previous one. I tried it and I got the same error message:
"Error Undefined variable in expression: p7"
But the script stop working. But when I tried "if (p7 != objNull) then" it drop the same error message, but the script run and works fine.
Now, I'm totally confused... ???
« Last Edit: 08 Nov 2012, 09:41:16 by bardosy »
Fix bayonet!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Checking existed unit.
« Reply #3 on: 08 Nov 2012, 19:51:44 »
Instead of objNull, try isNil  :dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: Checking existed unit.
« Reply #4 on: 09 Nov 2012, 11:08:22 »
Thanks -h!
So far (I could test only alone as server) seems much better: no error messages and everyting seems to work fine.
Fix bayonet!