Advertisement

Author Topic: Groupchain.sqs  (Read 806 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
Groupchain.sqs
« on: 28 Jul 2004, 17:37:19 »
This script fixes a behavior issue when one AI group got attacked by the enemy while the other groups in the area keep patrolling in SAFE behavior.
When somebody got killed or somebody changes his behaviour all the other groups will change theirs too.

Here it is, groupchain..sqs, simple but very useful

Code: [Select]

; ***************************************
; GROUPCHAIN.sqs by Blanco
; 28 / 07 / 04
; ***************************************
; Execute it with :
; [name of the groups seperated by a comma] exec "groupchain.sqs"
;
; example
;
; [grp1,grp2,grp3] exec "groupchain.sqs"
;=========================================

_c = count _this

_allunits = []
_grpcount = 0

#REPEAT
_b = 0
_grp =  _this select _grpcount
_u = units _grp



#CYCLE
_man = _u select _b
_allunits = _allunits + [_man]
_b =_b + 1
~0.2
?_b < count _u : goto "CYCLE"

?_grpcount < _c : _grpcount = _grpcount + 1;goto "REPEAT"


#CHECK
?"behaviour _x != ""SAFE""" count _allunits > 0 OR "!alive _x" count _allunits > 0 : goto "CHANGEBEH"
~1
goto "CHECK"


#CHANGEBEH
"_x SetBehaviour ""AWARE""" foreach _allunits

~1

#PICKONE
_countall = count _allunits
_r = random _countall
_r = _r - _r %1

_alarmguy = _allunits select _r

if (alive _alarmguy) then {goto "CHECKSIDE"} else {goto "PICKONE"}


#CHECKSIDE

?side _alarmguy == WEST : goto "W"
?side _alarmguy == EAST or side _alarmguy == RESISTANCE : goto "E"



#W
_WESTVOICES = ["eng20","eng21","eng40","eng18","eng19","eng12"]

_r = random (count _WESTVOICES)
_r = _r - _r %1

_alarmguy say (_WESTVOICES select _r)

exit

#E
_EASTVOICES = ["rus15","rus10","rus6","rus1"]
_r = random (count _EASTVOICES)
_r = _r - _r %1

_alarmguy say (_EASTVOICES select _r)

exit


Initialise your groups first with the group command and run it with

[groupnames seperated by a comma] exec "groupchain.sqs"

Example

[grp1,grp2,grp2] exec "groupchain.sqs"


You can also run it with a individual unit(s) (eg : A1)  & groups (eg : grp1,grp2,grp3) with:

[grp1,grp2,grp2, group A1] exec "groupchain.sqs"


NOTE :
=====
- Make sure that every group or unit is in SAFE behavior when the script starts!

BUGS :
=====
None.
« Last Edit: 29 Jul 2004, 21:26:04 by Blanco »
Search or search or search before you ask.

Nulear_Man

  • Guest
Re:Groupchain.sqs
« Reply #1 on: 29 Jul 2004, 14:13:09 »
Nice
Good Script you got there

Offline Blanco

  • Former Staff
  • ****
Re:Groupchain.sqs
« Reply #2 on: 10 Aug 2004, 17:57:56 »
thx, it works very well but I need help to improve it.

What I would like to see :

- Activate it with a trigger covering the whole map (WEST - EAST...present) and run it in the onactivation field [thislist] exec "groupchain.sqs". That's easy to do, but...
- When somebody spots enemy the leader should shout something like alaaaarm!!!  :P
-When somebody got killed, they shout (man down!!! or something like that

...and every group within a certain radius (like 200m) should be alarmed too to simulate they are hearing it.
(also doable, that part works already), but...
- The script should check if there' aren't any other groups in the area to create a chain of shouts and that's were I'm stuck...

Anybody?







« Last Edit: 10 Aug 2004, 18:01:00 by Blanco »
Search or search or search before you ask.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Groupchain.sqs
« Reply #3 on: 12 Aug 2004, 20:42:12 »
Quote
- The script should check if there' aren't any other groups in the area to create a chain of shouts and that's were I'm stuck...

Alright, I ripped this from my hand signals mission, and even did some improvements to it. Later, I'll see about integrating this into your script, but I haven't looked at it yet. Anyway, the code may be a bit hard to understand at first, but logicially it isn't very difficult. Basically, it works in a loop like this:

  One person starts the shout by (as if they just "heard" the shout)

LOOP
  Add the unit that just heard the shout, and everybody in his group, to an array of units _heard
  Execute code on all the units in the group that just heard the shout
  Find all units within range of the person who just heard the shout or anyone in his group
  Add them to an array of units _inRange
  Loop through the _inRange array until somebody is found who hasn't heard the shout already

Go to "LOOP"

You are going to need this function for this code:

Code: [Select]
;array of all units who will hear/repeat the shout
_friendArray = ARRAY OF FRIENDLY UNITS

;this array gets added to as other units hear/repeat the call
;it starts out with the
_heard = []

;this array is added to as units are found to be in range of
;someone who is passing along the shout
_inRange = []

; max range to hear/repeat calls from
_range = 100
_i = 0

;-----------------------------
; Start shout by simulating that the first unit just heard the shout
; from someone else
_selected = UNIT TO START THE SHOUT
;-----------------------------


;-----------------------------
#HeardYell
; _selected has heard the yell
; execute commands and make him repeat the shout
;-----------------------------

~random 1
_selected say SHOUT SOUND
{EXECUTE CODE} foreach units _selected

; Add the units in this unit's group to the _heard list
; if they aren't in it already
{if (NOT (_x in _heard) ) then { _heard = _heard + [_x]} } foreach units _selected

; Find everyone in range of anyone in _selected's group
; (the ones who just heard the shout)
_inRange2 = []
{_inRange2 = _inRange2 + ([_x, _range, _friendArray, false] call findUnits)} foreach units _selected

; Add them to the _inRange array if they haven't heard the shout already
{if (NOT (_x in _heard) ) then { _inRange = _inRange + [_x]} } foreach _inRange2

; Increment counter and continue on the loop
_i = _i + 1
goto "YellLoop"



;-----------------------------
#YellLoop
; Loop through all units _inRange, looking
; for ones who haven't heard the shout yet
;-----------------------------

_max = count _inRange
_selected = _inRange select _i

; If they haven't heard the yell, goto "HeardYell"
? NOT (_selected in _heard) : goto "HeardYell"

_i = _i + 1
? _i < _max : goto "YellLoop"



;-----------------------------
;everyone who can has heard the shout by this point
;continue on the script however you want
goto "WHATEVER IS NEXT"
;-----------------------------



EDIT
  And oh yeah, you should always attatch a small demo mission when you want people to test your scripts. Makes it quicker for us to see what the script does.  :-*
« Last Edit: 12 Aug 2004, 20:47:00 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!