Home   Help Search Login Register  

Author Topic: Reinforcements  (Read 1454 times)

0 Members and 1 Guest are viewing this topic.

Offline Killzone

  • Members
  • *
  • War is the true Enemy
Reinforcements
« on: 01 Oct 2004, 18:08:16 »
I am trying to make a script that automatically calls for reinforcements when the group drops below a certain number.  What is the condition I use for this?

Thanks ;D
"Everyone dies so deal with it and move on"

                                                      ME

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Reinforcements
« Reply #1 on: 01 Oct 2004, 19:12:00 »
Try:

("alive _x" count units thenameofyourgroup) <= n

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re:Reinforcements
« Reply #2 on: 01 Oct 2004, 20:06:12 »
I tried this in a trigger condition:

("alive _x" count units thenameofyourgroup) <= n

But it only works if you don't kill the original leader of the group.  Once the leader of the group is killed, he is unassigned fromt he group, and the count goes to zero.

So I wrote and tested this script.  It works.

; count_members.sqs
; By: JohnnyBoy
; To call, put this line in leader unit's init:
; [this,5] exec "count_members.sqs"

_grp = units (_this select 0)
_reduced_count = _this select 1

TitleText ["in count_members.sqs","Plain Down"]
#loop

; count the members in the group that meet the "alive" condition
? ("alive _x" count _grp) <= 5 : goto "do_something"
; wait 2 seconds, and try again
~2
goto "loop"

#do_something
; put whatever code here you want to happen when squad size reduced below desired number
hint format ["Alive member count now =%1","alive _x" count _grp]

exit


Since you capture entire array of units before anyone is killed, it doesn't matter when leader gets killed.  Hope this helps you. 8)
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Killzone

  • Members
  • *
  • War is the true Enemy
Re:Reinforcements
« Reply #3 on: 01 Oct 2004, 20:49:53 »
Thanks for the quick response people. I will give it a try

"Everyone dies so deal with it and move on"

                                                      ME

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re:Reinforcements
« Reply #4 on: 01 Oct 2004, 20:53:40 »
I just spotted a problem in my script.  I meant not to hardcode the 5 in the if condition.  Replace the hardcoded 5 with the input parameter variable _reduced_count, then you can pass in whatever your reduced member count threshold is...
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Reinforcements
« Reply #5 on: 01 Oct 2004, 21:12:13 »
I believe it does work if you name the group and don't just refer to the leader of the group.  In other words if you use

groupname = group this

in the init field of any member of the group and then you do a

("alive _x" count units thenameofyourgroup) <= n

I have never known it not to work

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re:Reinforcements
« Reply #6 on: 01 Oct 2004, 21:25:38 »
You are probably right.  Where I couldn't get it to work was directly as a condition in a trigger.  In the trigger condition, you can't pre-capture the group name in a variable, so for me anyway, the count always went to zero when the leader was killed...  I tried "count units grp_name", "count units group grp_name" and "count units group leader grp_name" in the trigger, and all behaved the same way for me (i.e., returned zero when leader killed).

It would be cleaner to do this as a trigger condition only (less hassle than a script), so if there is a way, I'd like to know!
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Reinforcements
« Reply #7 on: 01 Oct 2004, 21:48:09 »
Put the following in the init field of your group leader:

alphagrp = group this

and put this in the condition field of your trigger:

("alive _x" count units alphagrp) <= 5

You seem to prefer triggers.  Triggers with conditions like this are checked multiple times a second.  If you put the code in a script you can control how often the condition is checked and so help reduce lag in the mission.
« Last Edit: 01 Oct 2004, 21:50:29 by THobson »

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re:Reinforcements
« Reply #8 on: 01 Oct 2004, 23:37:56 »
Thanks dude.  Your suggestion worked.  By naming the group in the leader's init, the trigger condition no longer has the problem when the leader is killed.

Also, point taken on triggers vs. scripts.   The script gives you more control, and I'm guessing consumes less CPU if looping every few seconds.
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Killzone

  • Members
  • *
  • War is the true Enemy
Re:Reinforcements
« Reply #9 on: 02 Oct 2004, 13:58:18 »
Thanks for all the help I learned a little bit more about scripting.

I was using the code: ? count units GroupA <5

But it would not work if the Group leader was killed. It was frustrating but that has been put to rest.  Thanks ;D
"Everyone dies so deal with it and move on"

                                                      ME

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Reinforcements
« Reply #10 on: 02 Oct 2004, 16:27:32 »
Take care with count units.  

It can take many seconds - even minutes for the count instruction to register that someone has been killed.  It the squad has been wiped out it can be a very long time before count units returns zero.  That is why if you want to know exactly how many units there are (not how many the leader thinks there are) you need the bit about "alive _x"

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:Reinforcements
« Reply #11 on: 05 Oct 2004, 16:30:19 »
yeah, I've had that count unit prolem too, and the "alive _x" is a life saver.

and just for the record, i've had a count unit trigger that took 24 minutes to execute :P
don't ask, its kinda long
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Reinforcements
« Reply #12 on: 06 Oct 2004, 08:07:43 »
The count command depends on the knowledge of the leader of the group.

You know all the "Oh no, 3 is down" messages you get?
Notice how sometimes it can take a while for those to come through?
The leader's knowledge of the members of his group relies on those.

This is the reason that count can take a while.
When the whole group dies, (so the leader is dead too) it can take an incredibly long time to register... :P

Another alternative to "alive _x" is the countside command. This doesn't count dead units either ;)

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:Reinforcements
« Reply #13 on: 07 Oct 2004, 00:11:25 »
howd u use that?

player countEnemy thislist?

"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Reinforcements
« Reply #14 on: 07 Oct 2004, 02:16:56 »
You use the side... eg

? west countside (units alpha) > 0: (leader alpha) sidechat "Alpha squad, still alive"

That does exactly the same thing as:

? "alive _x" count (units alpha) > 0: (leader alpha) sidechat "Alpha squad, still alive"

So it's really up to your personal preference which one to use ;)