Home   Help Search Login Register  

Author Topic: Random patrol script help please  (Read 820 times)

0 Members and 1 Guest are viewing this topic.

mjb

  • Guest
Random patrol script help please
« on: 11 Dec 2005, 04:50:30 »
G'day again,

Anyone with a suggestion feel free to chime in.

I got a spwan script up and running with a bit of help, but my spawned group is then not conducting the patrol I'm trying to get it to do.

My patrol script is pretty much a blatant rip-off from Dr Strangelove's Spawnmanager2 (thanks!!!) but attempted to be tailored for my needs.

The background of this script is that it spawns a random group and then they patrol to a random waypoint with a given radius of their spawn point.

*The spawn part is working*
*The patrol part is not - the group just stands there, even after I observe them for a few minutes to see if they a pausing*

Here is the script:
Code: [Select]
; init command line is: [0,1,2,3,4] exec "patrolteamday.sqs"
; where:
; value 0 is name of group, e.g. teamy
; value 1 is the marker position where troops are spawned (x,y,z), e.g getMarker Pos "markery"
; value 2 is the number of units to be spawned, from 2-12, e.g. 4
; values 3 the patrol radius from spawn point in m, e.g. 200
; value 4 is the pause at each waypoint in sec, e.g. 40
; so e.g. would be [teamy, getMarkerPos "markery", 4, 200, 40] exec "patrolteamday.sqs"

;=================GET PARAMETERS========================
;get parameters
_team = grpNull
_team = _this select 0
_base = _this select 1
_scale = _this select 2
_range = _this select 3
_pause = _this select 4

;============INIT VALUES================================
_cycle = 0
_types=["BAS_RebelOfficerHD","BAS_RebelSoldierHD","BAS_RebelSoldier2HD","BAS_RebelSoldier3HD","BAS_RebelSoldier4HD","BAS_RebelSoldier5HD","BAS_RebelMGunnerHD","BAS_RebelRPGSoldierHD","BAS_RebelRTOHD","BAS_RebelMedicHD","BAS_MilitiaAKMHD", "BAS_MilitiaSKSHD","BAS_MilitiaFALHD","BAS_MilitiaG3HD","BAS_MilitiaRPDHD","BAS_MilitiaPKMHD","BAS_MilitiaRPGHD", "BAS_MilitiaRPGAAHD","BAS_MilitiaRPGAPHD","BAS_MilitiaWAKMHD","BAS_MilitiaWSKSHD","BAS_MilitiaWFALHD","BAS_MilitiaWG3HD","BAS_MilitiaWRPDHD","BAS_MilitiaWPKMHD","BAS_MilitiaWRPGHD","BAS_MilitiaWRPGAAHD","BAS_MilitiaWRPGAPHD"]

;=============================SPAWN TEAM=====================
#spawnteam
_z = (random (count _types))
_z = (_z -(_z mod 1))
_guy = _types select _z
_guy createUnit [_base, _team, "", 0.1]
_cycle = _cycle + 1
?(_cycle < _scale):goto "spawnteam"
_team setBehaviour "SAFE"
formLeader (units _team select 0)

;===========PATROLLING=========================
#moveout
_team setSpeedMode "NORMAL"

#patrol_again
({_x setBehaviour "SAFE"} forEach units _team)
units _team commandMove [(_base select 0) - _range + (random (2 * _range)), (_base select 1) - _range + (random (2 * _range))]

;go on if group has reached WP
@(unitready leader _team)
({_x setBehaviour "AWARE"} forEach units _team)
~_pause
goto "patrol again"

#exit
exit;

Note in the =spawnteam= section I created a leader (well no error message came up).  I did this in the hope it would help get a group to move to its random waypoint easier if I'm using commandMove.  I think DrStrangelove's spawn script creates a leader too, so I just copied using my noob script skillz.

Note in the =patrolling= section, I've attempted iterations of group move position and unit doMove as well, but no success.

Anyone see where I'm going wrong?

EDIT: I spotted the #patrol again and goto "patrol_again" anomoly and it didn't fix.
« Last Edit: 11 Dec 2005, 09:58:09 by mjb »

LoTekK

  • Guest
Re:Random patrol script help please
« Reply #1 on: 11 Dec 2005, 09:10:06 »
Quote
#patrol_again
({_x setBehaviour "SAFE"} forEach units _team)
units _team commandMove [(_base select 0) - _range + (random (2 * _range)), (_base select 1) - _range + (random (2 * _range))]
I could be mistaken, but that seems like it wouldn't work. Either use a forEach to iterate through each team member, or simply assign the move command to the group leader. The rest of the group should follow along happily.

mjb

  • Guest
Re:Random patrol script help please
« Reply #2 on: 11 Dec 2005, 10:51:07 »
Thanks LoTekk, I got the script working.

I added a few extra parameters to see if I could kick start some reactions out of the AI (see below)

Code: [Select]
; init command line is: [0,1,2,3,4] exec "patrolteamday.sqs"
; where:
; value 0 is name of group, e.g. teamy
; value 1 is the marker position where troops are spawned (x,y,z), e.g getMarker Pos "markery"
; value 2 is the number of units to be spawned, from 2-12, e.g. 4
; values 3 the patrol radius from spawn point in m, e.g. 200
; value 4 is the pause at each waypoint in sec, e.g. 40
; so e.g. would be [teamy, getMarkerPos "markery", 4, 200, 40] exec "patrolteamday.sqs"

;=================GET PARAMETERS========================
;get parameters
_team = grpNull
_team = _this select 0
_base = _this select 1
_scale = _this select 2
_range = _this select 3
_pause = _this select 4

;============INIT VALUES================================
_cycle = 0
_types=["BAS_RebelOfficerHD","BAS_RebelSoldierHD","BAS_RebelSoldier2HD","BAS_RebelSoldier3HD","BAS_RebelSoldier4HD","BAS_RebelSoldier5HD","BAS_RebelMGunnerHD","BAS_RebelRPGSoldierHD","BAS_RebelRTOHD","BAS_RebelMedicHD","BAS_MilitiaAKMHD", "BAS_MilitiaSKSHD","BAS_MilitiaFALHD","BAS_MilitiaG3HD","BAS_MilitiaRPDHD","BAS_MilitiaPKMHD","BAS_MilitiaRPGHD", "BAS_MilitiaRPGAAHD","BAS_MilitiaRPGAPHD","BAS_MilitiaWAKMHD","BAS_MilitiaWSKSHD","BAS_MilitiaWFALHD","BAS_MilitiaWG3HD","BAS_MilitiaWRPDHD","BAS_MilitiaWPKMHD","BAS_MilitiaWRPGHD","BAS_MilitiaWRPGAAHD","BAS_MilitiaWRPGAPHD"]

;========================SPAWN LEADER==================
#spawnleader
_z = (random (count _types))
_z = (_z -(_z mod 1))
_guy = _types select _z
_guy createUnit [_base, _team, "", 0.1, "CAPTAIN"]
_leader = (units _team select 0)
formLeader _leader
_cycle = _cycle + 1

;=============================SPAWN TEAM=====================
#spawnteam
_z = (random (count _types))
_z = (_z -(_z mod 1))
_guy = _types select _z
_guy createUnit [_base, _team, "", 0.1]
_cycle = _cycle + 1
?(_cycle < _scale):goto "spawnteam"

;===========PATROLLING=========================
#moveout
_team setBehaviour "SAFE"
_team setSpeedMode "LIMITED"
_team setCombatMode "RED"
_team setFormation "WEDGE"

#patrolagain
({_x setBehaviour "SAFE"} forEach units _team)
_team move [(_base select 0) - _range + (random (2 * _range)), (_base select 1) - _range + (random (2 * _range))]

;go on if group has reached WP
@(unitready _leader)
({_x setBehaviour "AWARE"} forEach units _team)
~_pause
goto "patrolagain"

#exit
exit;

This worked, but only after some massaging: I had put the spawning marker too close to some buildings and the group got stuck within the built-up area.

By moving the marker to an open area, it got things moving.

I noticed in the preview, if I shot a leader, they lost coherence.

I might add a check if _leader is alive subroutine and if != then appoint a new one.