Home   Help Search Login Register  

Author Topic: board the MG when the gunner die  (Read 540 times)

0 Members and 1 Guest are viewing this topic.

Viriato

  • Guest
board the MG when the gunner die
« on: 14 Mar 2003, 12:54:27 »
Hello everybody.

I want to make a missión in wich you have to take a hill defended by several enemy scuads and some static MGs,. itÂ's intended to be hard, but once the gunners who manned the MG dies, the troops of the hill are easily overriden.

I want a script that whenever detects an empty Mg, order a man to get in the Mg.

What will be the way to acomplish this?

Thank on advance.

Offline Ranger

  • Members
  • *
  • Hoo-ah!
Re:board the MG when the gunner die
« Reply #1 on: 14 Mar 2003, 18:48:33 »
Probably a script would be best for this.  You just need to check if the MG has a gunner, and if not, order someone else to "get in" the MG.

Try the following script:

Code: [Select]
;###############################################
; NewGunner.sqs
; By Ranger @ www.ofpec.com
;
; Usage: [mg,gunner1,gunner2,...,gunnerN] exec "NewGunner.sqs"
;
; This script checks if the gunner in a machine gun is dead, and if so,
; orders another unit to use the MG.  It chooses randomly from among
; the specified replacement gunners.
;###############################################

; Take the passed parameters and assign the data to local variables.
; _mg is the machine gun.
; _gunners is an array of replacement gunners.

_mg = _this select 0
_gunners = _this - [_this select 0]

#Loop

; Wait until there is no one "in" the MG.

@ count (crew _mg) < 1

; Check if the MG itself is destroyed.  If so, exit the script.

? not alive _mg : exit

#Choose

; Choose a new gunner randomly from the array.

_newGunner = _gunners select random(count _gunners)

; Remove the gunner from the array.

_gunners = _gunners - [_newGunner]

; This script is no longer needed if there are no extra gunners left.

? count _gunners < 1 : exit

; Verify that the new gunner is alive.  If not, choose again.

? not alive _gunner : goto "Choose"

; Assign the gunner to the MG and tell him to get in.

_newGunner assignAsGunner _mg
[_newGunner] orderGetIn TRUE

goto "Loop"

Execute this script from the initialization field of the machine gun.  As I made it dynamic, you can use this same script with more than one machine gun in your mission, but naturally you'll have to run it once for each machine gun.

Let me know if it works, as this code is untested.  Obviously, you'll need to put some extra guys standing around who will be the replacement gunners.

With a little extra work, you can have a pool of gunners from which all of your machine guns go for a new gunner so that you don't need to have one group of gunners per MG.
Ranger

Viriato

  • Guest
Re:board the MG when the gunner die
« Reply #2 on: 14 Mar 2003, 19:05:13 »
As always Rangers lead the way  ;)

I am going to check your script, if i manage to get it working i will put a small demo mission here.

Thanks Ranger!

Offline Ranger

  • Members
  • *
  • Hoo-ah!
Re:board the MG when the gunner die
« Reply #3 on: 14 Mar 2003, 21:25:49 »
No problem at all. I hope it works.

Actually, I just noticed a small bug in it.  The script should work properly except when there is only one gunner left.  SO, below, I"ve pasted what should be a fixed version, as well as included some examples on the usage syntax for clarity.

Code: [Select]
;###############################################
; NewGunner.sqs
; By Ranger @ www.ofpec.com
;
; Usage: [mg,gunner1,gunner2,...,gunnerN] exec "NewGunner.sqs"
;
; This script checks if the gunner for a machine gun is dead, and if so,
; orders another unit to use the MG.  It chooses randomly from among
; the specified replacement gunners.  Example usages:
;
; [mg1,guy1,guy2,guy3] exec "NewGunner.sqs"
; ([mg1] + units group1) exec "NewGunner.sqs"
;###############################################

; Take the passed parameters and assign the data to local variables.
; _mg is the machine gun.
; _gunners is an array of replacement gunners.

_mg = _this select 0
_gunners = _this - [_this select 0]

#Loop

; Wait until there is no one "in" the MG.

@ count (crew _mg) < 1

; Check if the MG itself is destroyed.  If so, exit the script.

? not alive _mg : exit

#Choose

; Choose a new gunner randomly from the array.

_newGunner = _gunners select random(count _gunners)

; Remove the gunner from the array.

_gunners = _gunners - [_newGunner]

; This script is no longer needed if there are no extra gunners left and
; the last gunner is dead already.

? (count _gunners < 1) and (not alive _newGunner) : exit

; Verify that the new gunner is alive.  If not, choose again.

? not alive _gunner : goto "Choose"

; Assign the gunner to the MG and tell him to get in.

_newGunner assignAsGunner _mg
[_newGunner] orderGetIn TRUE

; This script is no longer needed if there are no extra gunners left.

? count _gunners < 1 : exit

goto "Loop"
Ranger

Viriato

  • Guest
Re:board the MG when the gunner die
« Reply #4 on: 15 Mar 2003, 20:12:26 »
I got a problem ranger!

I donÂ't know why, but the script only work once.

I have tried numerous combinations and started the script on the init of the mg or in a separated trigger but the died gunner is replaced only once.
 i have been cheking your script but i have not figured the problem.

May be you could find whats wrong?

Offline Ranger

  • Members
  • *
  • Hoo-ah!
Re:board the MG when the gunner die
« Reply #5 on: 17 Mar 2003, 17:48:26 »
Hi there,

I just found another bug.  Hopefully, this will solve the problem.  I haven't tested the code, yet, but I think this will do it.

Code: [Select]
;###############################################
; NewGunner.sqs
; By Ranger @ www.ofpec.com
;
; Usage: [mg,gunner1,gunner2,...,gunnerN] exec "NewGunner.sqs"
;
; This script checks if the gunner for a machine gun is dead, and if so,
; orders another unit to use the MG.  It chooses randomly from among
; the specified replacement gunners.  Example usages:
;
; [mg1,guy1,guy2,guy3] exec "NewGunner.sqs"
; ([mg1] + units group1) exec "NewGunner.sqs"
;###############################################

; Take the passed parameters and assign the data to local variables.
; _mg is the machine gun.
; _gunners is an array of replacement gunners.

_mg = _this select 0
_gunners = _this - [_this select 0]

#Loop

; Wait until there is no one "in" the MG.

@ count (crew _mg) < 1

; Check if the MG itself is destroyed.  If so, exit the script.

? not alive _mg : exit

#Choose

; Choose a new gunner randomly from the array.

_newGunner = _gunners select random(count _gunners)

; Remove the gunner from the array.

_gunners = _gunners - [_newGunner]

; This script is no longer needed if there are no extra gunners left and
; the last gunner is dead already.

? (count _gunners < 1) and (not alive _newGunner) : exit

; Verify that the new gunner is alive.  If not, choose again.

? not alive _newGunner : goto "Choose"

; Assign the gunner to the MG and tell him to get in.

_newGunner assignAsGunner _mg
[_newGunner] orderGetIn TRUE

; This script is no longer needed if there are no extra gunners left.

? count _gunners < 1 : exit

goto "Loop"


For your information, the bug was that the code was checking if _gunner was alive.  However, there is no variable named "_gunner", so I"m surprised that it even worked once.  IN any event, I fixed it, so give it another try.  Good luck!
Ranger