Jump to content
Sign in to follow this  
joeanorak

Problems with 'Distance' Command

Recommended Posts

I'm trying to produce a small script that allows a player to call a Helicopter to a position onmapsingleclick where it will briefly touch down, spawn a few ammo crates then return to its original location (I know the heli extraction insertion thing has been done to death but i'm using this as a means of furthering my extremely limited scripting ability).

Thus far I can get the heli to fly to the clicked location with no problems and have been using a distance command to initiate it landing and dropping the supplies (see below).

_Marker = createmarker ["REPLENLZ", _this]
_Marker setMarkerType "Destroy"
_Marker setMarkerColor "ColorRed"
_Marker setMarkertext  "REPLEN LZ"

LZpad = "HeliH" CreateVehicle (getMarkerPos "REPLENLZ")

Replenbird doMove (getMarkerPos "REPLENLZ")

#ENROUTE
? ([color="Red"]Replenbird distance "REPLENLZ"[/color] < 200) : goto "LAND";
~0.01;
goto "ENROUTE"

#LAND
LZsmoke = "SmokeShellRed" CreateVehicle getMarkerPos "REPLENLZ";  
hint "Smoke Out.";
doStop Replenbird;
Replenbird land "GETIN";

#Wait
? ([color="red"]Replenbird distance "REPLENLZ"[/color] < 5) : goto "CARGOEJECT"
goto "WAIT"

#CARGOEJECT
Crate = "USSpecialWeaponsBox" createVehicle (getMarkerPos "REPLENLZ")

exit

My problem areas are those highlighted in red. If I use distance between Player and Replenbird the script works but its not ideal as the player has to stay relatively close to the intended LZ for an extended period. If I use distance between the LZ marker or the spawned Helipad and the player the script does not execute and the heli simply hovers just short of the single-clicked location.

Can a distance command only measure between the player and another object or is there another reason for the behaviour i'm seeing?

Share this post


Link to post
Share on other sites

Let me quote the BIWIKI:

Returns the distance in meters between two Objects, Positions or (since VBS2 1.24) Locations.

If you still can't figure it out whats wrong, look into the spoiler:

? (Replenbird distance (markerPos "REPLENLZ") < 200) : goto "LAND";

Share this post


Link to post
Share on other sites

Myke, cheers for that. I was sure I had tried this and that it didn't work hence me asking a question that the Com Ref had already given me the answer to. Probably incorrect syntax on my part. I think that whilst I can now for the most part understand scripts my ability to use the correct syntax needs some serious work!

Just as an aside, when a heli lands on a pad why does it always perform a 180 spin before setting down? I seem to remember someone saying it way aligning itself to the pad?

Share this post


Link to post
Share on other sites

To be honest, i don't know. I always thought it is to simulate the pilot taking a last 360 degree check view before goin finally down....you know, last check of situation on the ground, obstacles that could cause problems while landing. But i guess this is just what i hope it is.

Share this post


Link to post
Share on other sites
_Marker = createmarker ["REPLENLZ", _this]
_Marker setMarkerType "Destroy"
_Marker setMarkerColor "ColorRed"
_Marker setMarkertext  "REPLEN LZ"

LZpad = "HeliH" CreateVehicle (getMarkerPos "REPLENLZ")

Replenbird doMove (getMarkerPos "REPLENLZ")

#ENROUTE
? [color="Red"](Replenbird distance getMarkerPos "REPLENLZ" < 200)[/color] : goto "LAND";
~0.01;
goto "ENROUTE"

#LAND
LZsmoke = "SmokeShellRed" CreateVehicle getMarkerPos "REPLENLZ";  
hint "Smoke Out.";
doStop Replenbird;
Replenbird land "GETIN";

#Wait
? [color="Red"](Replenbird distance getMarkerPos "REPLENLZ" < 5)[/color] : goto "CARGOEJECT"
goto "WAIT"

#CARGOEJECT
Crate = "USSpecialWeaponsBox" createVehicle (getMarkerPos "REPLENLZ")

exit

Share this post


Link to post
Share on other sites

I suggest to add some time to #WAIT because now it's going to be a little FPS killer :)

for example: sleep 0.1 or ~0.1

Share this post


Link to post
Share on other sites

Yes correct. ;)

I also would suggest to use .sqf instead of .sqs. ;)

.sqf

_Marker = createmarker ["REPLENLZ", _this];
_Marker setMarkerType "Destroy";
_Marker setMarkerColor "ColorRed";
_Marker setMarkertext  "REPLEN LZ";

LZpad = "HeliH" CreateVehicle (getMarkerPos "REPLENLZ");

Replenbird doMove (getMarkerPos "REPLENLZ");

while { (Replenbird distance getMarkerPos "REPLENLZ" < 200) } do
{
       sleep 0.1;
};

LZsmoke = "SmokeShellRed" CreateVehicle getMarkerPos "REPLENLZ";  
hint "Smoke Out.";
doStop Replenbird;
Replenbird land "GETIN";

while { (Replenbird distance getMarkerPos "REPLENLZ" < 5) } do
{
      sleep 0.1;
};

Crate = "USSpecialWeaponsBox" createVehicle (getMarkerPos "REPLENLZ");

Looking good now. :)

Share this post


Link to post
Share on other sites

SNKMAN, Bartchie thanks for the additional input. I know .sqf is the way to go but I find .sqs easier to read at the moment - all the brackets in .sqf make my head spin! Still 'learning is doing' so perhaps I should learn now rather than have to re-learn later on.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×