Jump to content
Sign in to follow this  
gunterlund

Getting a unit to move to another unit

Recommended Posts

Working on code to get a carbomb to move to a unit. Im new at this so Im sure something simple is missing. I want the carbomb to move to the unit that triggered the trigger and explode. I can identify the carbomb and the unit but when I trigger the trigger the bomb explodes immediately before it moves. It should explode when the carbomb is within 10 meters of the target. I also get an error on the sleep 0.2 for some reason. Can anyone help

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; get unit firing trigger and carbomb for trigger

_unitlist = _this select 0;

_unitgroup = _unitlist select 0;

_carbomb = _this select 1;

;set behaviour of bomber

_carbomb setbehaviour "COMBAT";

;set distance between carbomb and target

_meters = (_carbomb distance _unitgroup);

_meters2 = (_carbomb distance _unitgroup)+10;

;move carbomb to target

_carbomb domove (position _unitgroup);

;if carbomber is initially killed blow the car;

if (!alive _carbomb)then

[_carbomb, "Large"] exec "ied.sqs";

else

exitWith{};

;if car within 10 meters of target, blow it

while {alive _carbomb} do

{

if ((_carbomb distance _unitgroup)>10) then

{

sleep 0.2 + random 0.3;

else

[_carbomb, "Large"] exec "ied.sqs";

};

sleep 0.2;

};

Share this post


Link to post
Share on other sites

ok well you made a big mistakes!

You have mixed .sqs and .sqf

In .sqs you have to add a ; in front of the commant

In .sqf you have to add a // in front of the commant

Take a look at this page .sqs to .sqf

Also compare your script with the one i corrected, you have had missed several braces too!

Okay try this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// get unit firing trigger and carbomb for trigger

_unitlist = _this select 0;

_unitgroup = _unitlist select 0;

_carbomb = _this select 1;

// set behaviour of bomber

_carbomb setbehaviour "COMBAT";

// move carbomb to target

_carbomb move (getPos _unitgroup);

// if car within 10 meters of target or not alive, then blow it

// Explanation: Do this while loop, till condition match

while {True} do

{

       // Explanation: Exit the script, if car within 10 meters of target or if the car is destroyed/killed, then blow it

       if (((_carbomb distance _unitgroup) < 10) || !(alive _carbomb)) exitWith

       {

               [_carbomb, "Large"] exec "ied.sqs";

       };

       sleep 1;

};

NOTE: You now have to call the script with:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

nul = [argument] execVM "myscript.sqf" (for SQF scripts)

Becouse it's .sqf

Share this post


Link to post
Share on other sites

Yes you have to.

while, exitWith and sleep are commands, which do work in .sqf only!

Simply create a script text file and call it .sqf insted of .sqs and you are ready to go.

Copy and past the code i corrected into the script and it should work.

Share this post


Link to post
Share on other sites

how bout this in an sqs file?

_unitlist = _this select 0;

_unitgroup = _unitlist select 0;

_carbomb = _this select 1;

;set behaviour of bomber

_carbomb setbehaviour "COMBAT";

; move carbomb to target

#LOOP

_carbomb move (getPos _unitgroup);

_meters = (_carbomb distance _unitgroup);

player sideChat format["_meters = %1", _meters];

~ 2

?_meters < 10:goto "LOOP";

[_carbomb, "Large"] exec "ied.sqs";

Share this post


Link to post
Share on other sites

Yes sure this would work too.

But you have to change the condition to:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

?_meters > 10:goto "LOOP";

Becouse the script should loop till the bomb is within the 10 meters.

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  

×