Home   Help Search Login Register  

Author Topic: Determining distance from vehicle and whoever is leader of a group  (Read 1272 times)

0 Members and 1 Guest are viewing this topic.

I am trying to keep an infantry group and a tank group moving along the same path in proximity enough to support each other and am trying to find a good way to do it.  I don't like to put armor and infantry in the same group, because the vehicles are RPG magnets and that tends to take out the infantry too.  Also, the crewman in the vehicles limit the number of infantry that can be in a group.

To do this I wrote a simple script to check distance between the tank and the leader of the infantry group, and then stops the tanks if too far away by removing its fuel.  The problem I have is the script will stop working if the leader dies.  I would like a way for the script to check the leader of the group and measure the distance between him and the tank.  However, I don't know much about coding and cannot get it to work.

I pass the tank name and leader name to my script by putting this in the initialization field of the tank:

[Tank1, L1] exec "KeepInFront.sqs"

and the code is as follows:

Code: [Select]
_tank = _this select 0
_man = _this select 1

#Here
?(_tank distance _man > 100):_tank setFuel 0
~10

_tank setFuel 1

goTo "Here"

I tried putting "Infantry1 = group this" in the init field of the leader of the infantry group (L1), then have the script check "leader Infantry1", but it didn't work.

So does anyone know an efficient method to make a script that will do what I want?  Thanks.
« Last Edit: 18 Jan 2009, 21:22:36 by Planck »

Offline zwobot

  • Members
  • *
I tried putting "Infantry1 = group this" in the init field of the leader of the infantry group (L1), then have the script check "leader Infantry1", but it didn't work.
This is the way to do it. Did the script tell you any errors in the preview of the mission?
Try using brackets in your script when you pass the name of the group to the script:
Code: [Select]
_group = _this select 1
?(_tank distance (leader _group) > 100):_tank setFuel 0
« Last Edit: 18 Jan 2009, 21:23:03 by Planck »
"Executing tactics in real combat is the hardest thing one can ever do...well I've never given birth but..well whatever."

That is how I was doing it, and I don't get any error messages.  I decided to add one line--the hint line--to see just what the result of the calculation is, changing the code to:

Code: [Select]
_tank = _this select 0
_group = _this select 1

#Here
?(_tank distance (leader _group) > 100):_tank setFuel 0
hint format["Distance = %1", _tank distance (leader _group)]
~10

_tank setFuel 1

goTo "Here"

If I pass "L1" to the script, I get a number showing the distance.  However, if I pass "Infantry1" to the script, the hint says, "Distance = scalar".  Below, first is the init field of the man, L1, and second is the init of the tank.

Infantry1 = group this

[Tank1, Infantry1] exec "KeepInFront.sqs"

So to sum up, it works if I use "L1" and not "Infantry1" in the second init field.

I think there is something about the result returned from "Infantry1 = group this" that I don't understand.
« Last Edit: 18 Jan 2009, 21:23:19 by Planck »

Offline zwobot

  • Members
  • *
Try not to call
[Tank1, Infantry1] exec "KeepInFront.sqs"
in the init line of the tank unit. It could be that the variable Infantry1 is not initialised at the time of execution. Put the script call into a trigger with condition time > 1
Hopefully the Infantry1 variable will contain the group by then.
« Last Edit: 18 Jan 2009, 21:23:37 by Planck »
"Executing tactics in real combat is the hardest thing one can ever do...well I've never given birth but..well whatever."

It works!  Thanks again--you ended something that was frustrating me.