Home   Help Search Login Register  

Author Topic: operating on unnamed units of a group  (Read 999 times)

0 Members and 1 Guest are viewing this topic.

Silverfoot

  • Guest
operating on unnamed units of a group
« on: 10 Apr 2003, 15:58:50 »
Hi Iam creating my first ever 'serious' mission after over a year of on and off dabling and nobrainer designs!

I keep getting this reoccuring problem when I want to check for a condition for each member of a group:

Quote
?(leader _patrol KnowsAbout aP > 2): goto "detected"
?(leader _patrol KnowsAbout black0 > 2): goto "detected"
?(leader _patrol KnowsAbout black1 > 2): goto "detected"
?(leader _patrol KnowsAbout black2 > 2): goto "detected"
?(leader _patrol KnowsAbout black3 > 2): goto "detected"
?(leader _patrol KnowsAbout black4 > 2): goto "detected"
?(leader _patrol KnowsAbout black5 > 2): goto "detected"
?(leader _patrol KnowsAbout black6 > 2): goto "detected"
?(leader _patrol KnowsAbout black7 > 2): goto "detected"
?(leader _patrol KnowsAbout black8 > 2): goto "detected"

pretty long winded, but works.....what if I wanted to check units within a group that do not have unit names, only a groupname?

Case in point:
Quote
? NOT(alive leader patrol1) && (patrol1 distance _theunit < 50): goto"detected"

_the unit is supposed to represent a unitName retrieved from a group.  How can I assign _unitname with a member of a group?

This does not work:
Quote
_grouparray = units _patrol
_theunit = _grouparray select 1
....are groups arrays or what?  :-[
Am I missing something...please help!

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:operating on unnamed units of a group
« Reply #1 on: 10 Apr 2003, 16:23:05 »
Your last snippet should work, i.e. _grouparray should be an array of all units in the group, and _theunit should be the second (when using "select", the index starts with 0) unit among them. This should work fine as long as your group contains two or more units. With
Code: [Select]
_N = count _grouparrayyou can determine the number of units. The allowed range of ID numbers  is then 0, 1, ..., _N -1.

Why do you check for "NOT(alive leader patrol1)"? This should only be true if the whole patrol1 group is dead.

A nice way to solve problems like your first one, is to use the "extended" count command:
Code: [Select]
?("leader _patrol KnowsAbout _x > 2" count (units _groups)) > 0: goto "detected"This counts how many units of _group have a knowsAbout value larger than 2. If there is atleast one unit, "detected" is triggered. This should be equivalent to your snippet.
The _x in the "condition string" is a placeholder for the elements to be counted and is reserved.

Silverfoot

  • Guest
Re:operating on unnamed units of a group
« Reply #2 on: 10 Apr 2003, 17:59:43 »
Thanks Spinor, I think your last quote was what I needed to know!
...Let me go try it  ;)

Silverfoot

  • Guest
Re:operating on unnamed units of a group
« Reply #3 on: 10 Apr 2003, 21:07:45 »
Blast! Iam still stuck, and I feel so close!
Here is a dump of the sqs:
Quote
_patrol = _this select 0

#main
?(stopscript): exit
;/////////////////////////////////////////////////
; D E T E C T I N G    G R O U P   B L A C K

; spinor's clever code to check if _patrol group knows about group 'black'
;?("leader _patrol KnowsAbout _x > 2" count (units black)) > 0: goto "detected"



;/////////////////////////////////////////////////
; H U N T I N G    F O R   U N H I D D E N    B O D D I E S

; convert group to array
_grouparray = units _patrol

; add element 1 to a variable
_theunit = _grouparray select 0

; only check for bodies with the patrols that are alive
#check1
? (alive leader patrol1): goto"search_patrol1"
#check2
;? (alive leader patrol2): goto"search_patrol2"
;#check3
;? (alive leader elite): goto"search_elite"

;loop the script
goto "main"

#search_patrol1
; if group patrol2 is wiped out and group patrol1 is near the boddies, raise alarm!
? NOT(alive leader patrol2) && ((leader patrol2) distance (leader patrol1) < 200): goto"detected"
? NOT(alive leader elite) && ((leader elite) distance (leader patrol1) < 20): goto"detected"
goto "check2"


;//////////////////////////////////////////////////
#detected
hint"detected"
~10
?(alive leader _patrol): goto "soundalarm"
exit

#soundalarm
hint"alarmed!"
detected = true;
exit
OK, this script is executed 3 time silultaniously by groups: elite, patrol1 and patrol2....I may be adding more :)

I have only been testing for patrol2 to find bodies thus far and the script doesnt work.  However, if I change((leader elite) distance (leader patrol1) < 20) to a silly figure like <20000 the script does work!  Iam going nuts with the logic on this.....whats going on?

Some of this code has got a bit ugly I know.....any better ideas of achieving the same thing?

Thanks, and sorry to ask so many questions  :P

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:operating on unnamed units of a group
« Reply #4 on: 10 Apr 2003, 21:28:08 »
if u wanna check 4 unhiden bodies  :)

here is script u want

if u want help in makein it work feel free 2 ask ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:operating on unnamed units of a group
« Reply #5 on: 10 Apr 2003, 22:53:42 »
A problem could be that if patrol2 is wiped out, its leader is simply not defined (objNull or so). Often it is the case that the position [0,0,0] is used which means you probably calculate the distance to the map origin, hence the positive result for <20000.

Silverfoot

  • Guest
Re:operating on unnamed units of a group
« Reply #6 on: 10 Apr 2003, 23:57:15 »
Cheers Iam 'a trying it now  :D

Silverfoot

  • Guest
Re:operating on unnamed units of a group
« Reply #7 on: 12 Apr 2003, 13:25:28 »
OK, here I go again!  If it wasnt for being here before, I would swear that OFP script has a mind of its own, check this:

When exicuting this script from a trigger like this:
Quote
[patrol1] exec "alarm.sqs";

to do this:
Quote
_patrol = _this select 0
hint"alarm.sqs"
#main
?(stopscript): exit
;/////////////////////////////////////////////////
; D E T E C T I N G    G R O U P   B L A C K

;spinor's clever code to check if _patrol group knows about group 'black'
;?("leader _patrol KnowsAbout _x > 2" count (units black)) > 0: goto "detected"

;loop the script
goto "main"

the script doesnt goto 'detected'!  (It used to)
However if I hard code it:
Quote
?("leader patrol1 KnowsAbout _x > 2" count (units black)) > 0: goto "detected"
It WORKS!  :-\

What does this mean?  _patrol appear to be passed ok into the script (I traced a hint in the sqs of _patrol and it errored, saying it was a group and not a string)

How stable is this language?  ???
« Last Edit: 12 Apr 2003, 13:31:27 by Silverfoot »

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:operating on unnamed units of a group
« Reply #8 on: 13 Apr 2003, 02:33:00 »
What OFP version are you using?
I know that you canÂ't use local variables (like _patrol) in the count command in older versions.
In the latest version this should have changed (take a look at the ComRef under Scripting Topics/Local variables for variable scoping issues).
As a workaround, make the variable global like
Code: [Select]
patrolTemp = _this select 0and use this in the count command.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:operating on unnamed units of a group
« Reply #9 on: 13 Apr 2003, 04:30:23 »
Not sure if you have missed on what you pass to the script. But it looks as if your not passing the leaders name, that is the only one that would work in the case you use _grouparray = units _patrol, which would be the same as _grouparray = units patrol1 (if that is the name of the leader). If you are passing  a group name (patrol1 = group this written in the leaders init), then use _grouparray = units group patrol1....

on 2nd thought you could just put in any group members init:
Quote
[units group this] exec "scriptname.sqs"
or in a trigger
Quote
[units group anymembername] exec "scriptname.sqs"

Then the script:
Quote
_grouparray = _this select 0

?("(_grouparray select 0) KnowsAbout _x > 2" count (units black)) > 0: goto "detected"
and so on...
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Silverfoot

  • Guest
Re:operating on unnamed units of a group
« Reply #10 on: 13 Apr 2003, 13:27:53 »
Hehe..its still not working!  This is my current alarm.sqs
Quote
_patrolTemp = _this select 0

#main
?(stopscript): exit

;/////////////////////////////////////////////////
; D E T E C T I N G    G R O U P  B L A C K

; spinor's clever code to check if _patrol group knows about group 'black'
?("leader _patrolTemp KnowsAbout _x > 2" count (units black)) > 0: goto "detected"


;loop the script
goto "main"


#detected
hint"detected"
~10
?(alive leader _patrolTemp): goto "soundalarm"
exit

#soundalarm
hint"alarmed!"
detected = true;
exit

So, whats going on in this code?  As before (for testing) I execute a trigger with a radio command with:
Quote
[patrol1] exec "alarm.sqs"
and 'patrol1' has:
Quote
patrol1 = group this
in it's init field.....the crazy thing is that this was working a few days ago!  :o

As you can see MI_Fred, I have scrapped the idea of detecting bodies for now, LCD's script requires 1.85 and Iam on 1.46 (Resistance is on order!)  ;D
I will bear your advice in mind though. Thanks all.  :)

Silverfoot

  • Guest
Re:operating on unnamed units of a group
« Reply #11 on: 13 Apr 2003, 13:42:47 »
OK, I just tried doing this:
Quote
;_patrolTemp = _this select 0
_patrolTemp = patrol1

and the script STILL didnt work!  That eliminates the problem being out of the script since it works if you hardcode patrol1 in the line:
Quote
?("leader patrol1 KnowsAbout _x > 2" count (units black)) > 0: goto "detected"

...doesnt it?  ???

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:operating on unnamed units of a group
« Reply #12 on: 13 Apr 2003, 14:09:17 »
Yep, the reason is OFP 1.46, Resistance is indeed in order  ;D.
As for my workaround, donÂ't use
Code: [Select]
_patrolTemp = _this select 0but

Code: [Select]
patrolTemp = _this select 0i.e. without underline. This makes patrolTemp a global variable, thus being visible not only in the script you are running. You should be able to use it in the count command (even in the outdated 1.46  ;D).

Silverfoot

  • Guest
Re:operating on unnamed units of a group
« Reply #13 on: 13 Apr 2003, 18:29:46 »
Thanks Spinor, I tried that and it worked a treat!   ;D ;D ;D ;D ;D ;D

I cant thank you guys enough for supporting me through this.....if it wasnt for you this mission would be in the bin by now!    :-*  ...the Jesuses of Nazerath of the OFP world  ;D