Home   Help Search Login Register  

Author Topic: Randomised Patrol Script  (Read 2201 times)

0 Members and 1 Guest are viewing this topic.

Offline XCess

  • Former Staff
  • ****
Randomised Patrol Script
« on: 28 May 2006, 20:46:44 »
The following is a script I created for the second mission in my Invasion series. It will give a squad three randomised waypoints which they will go to in order. Then they will return to a central position (in my mission this is a list trigger) for five minutes. After these five minutes they will conduct another randomised patrol.

The patrol will be carried out inside an 800 metre radius, and was made without the use of a gameLogic or any other object to define the waypoints to keep lag to a minimum (infact I have experience no lag whatsoever)

syntax:
[leaderName,centralName] exec"infPatrol.sqs"

where leadername is the leader of the group (can actually be any member of the group)

where centralName is the name of an object that will define the centre of the patrol area.

Code: [Select]
; Infantry Patrol Scripts v1.1
; by XCess

_group = _this select 0
_town = _this select 1

_center = getPos _town

; patrol dimensions
_x = 0
_y = 0

_xD = 0
_yD = 0

_x2 = 0
_y2 = 0

_posCount = 0
_posMax = 4

_loopCount = 0

#Start

_posCount = _posCount + 1
?(_posCount >= _posMax) : goto"return"

_center = getPos _town
_x = Random(800)-400
_y = Random(800)-400

_mPos = [(_center select 0)+_x, (_center select 1)+_y]

(leader _group) move _mpos
~2

#posCheck

_x2 = (getPos (leader _group) select 0)
_y2 = (getPos (leader _group) select 1)

_xD = (_mpos select 0) - _x2
_yD = (_mpos select 1) - _y2


? (_yD < 2 && _xD < 2) && (_yd > -2 && _xD > -2)  :goto "start"
? !(alive (leader _group)) : goto"start"
?(count units _group) <= 4 : goto"retreat"

_loopCount = _loopCount + 1
?(_loopCount > 50) : goto "waterCheck"

~5
goto"posCheck"

#return

_posCount = 0
(leader _group) move (getPos _town)

_x = getPos _town select 0
_y = getPos _town select 1

#PosCheck2
_x2 = (getPos (leader _group) select 0)
_y2 = (getPos (leader _group) select 1)

_xD = _x - _x2
_yD = _y - _y2

? !(alive (leader _group)) : goto"return"
? !(_yD < 2 && _xD < 2) && (_yd > -2 && _xD > -2) :goto "posCheck2"

~300
goto"Start"



#retreat

(leader _group) move (getPos _town)
exit


#waterCheck
_loopCount = 0
_wPosX = getPos (leader _group) select 0
_wPosY = getPos (leader _group) select 1

_count = 0

#wLoop

_x2 = (getPos (leader _group) select 0)
_y2 = (getPos (leader _group) select 1)

_xD = (_mpos select 0) - _x2
_yD = (_mpos select 1) - _y2


? (_yD < 2 && _xD < 2) && (_yd > -2 && _xD > -2)  :goto "start"
? !(alive (leader _group)) : goto"start"

_count = _count + 1
?(_count == 10) : goto"checkSame"

~1
goto"wLoop"

#checkSame
cPosX = getPos (leader _group) select 0
cPosY = getPos (leader _group) select 1

?(_cPosX == _wPosX) && (_cPosY == _wPosY) : goto"start"
goto"posCheck"



Offline schuler

  • Contributing Member
  • **
Re: Randomised Patrol Script
« Reply #1 on: 04 Jun 2006, 16:43:37 »
 hello XCess, seems to work very well, though just noteing the syntax:
[leaderName,centralName] exec"infPatrol.sqs" is just missing the space between the exec and ".   ;)
   also i allways like it when the script includes the syntax at the top, i sometimes get confused because calling the script i would probley forget the "centralName" part of it. but iam not that advanced in scripting !

; Infantry Patrol Scripts v1.1
; by XCess
; [leaderName,centralName] exec "infPatrol.sqs"
Semper Fi

Offline XCess

  • Former Staff
  • ****
Re: Randomised Patrol Script
« Reply #2 on: 06 Jun 2006, 00:57:37 »
Glad you like the script schuler. I don't think you actually need any space between exec and the scriptname string. syntax is in the post. you're welcome to put it into the script too, as well as any other adjustmnts. Remember the credits :P ;D

Offline Killzone

  • Members
  • *
  • War is the true Enemy
Re: Randomised Patrol Script
« Reply #3 on: 09 Jun 2006, 20:44:40 »
Hello,

I am attempting to use this script but I keep coming up with an "unknown operator" message. yet I have the leader of a 3 man squad (his name is leader1) and I have an object (I am using a palm tree named, tree)  and here is the line of code: [leader1,tree] exec"Patrol.sqs"   

I dont understand why this keeps coming up.  please help I am sure it is something silly  :P
"Everyone dies so deal with it and move on"

                                                      ME

Offline XCess

  • Former Staff
  • ****
Re: Randomised Patrol Script
« Reply #4 on: 10 Jun 2006, 06:30:20 »
Try renaming the centre object, tree maybe reserved.
Also the following line of code will have to be changed as you are using a smaller group.

?(count units _group) <= 4 : goto"retreat"

Don't know why it's coming up with unknown operator though ???