Jump to content
Sign in to follow this  
PhelanKA7

Randomly select from set of WPs

Recommended Posts

Really new to scripting and I have a question about what I thought should be a pretty simple first script. Apparently I'm a moron, because it doesn't work.

I'm trying to create a script that I'm putting in an NPC's Init line. It's supposed to randomly choose from a set of "AddWaypoints" in the script. I am placing it in my Init line as

nul = []execVM "Random.sqf";

Anyways... here's the script:

_posnum = round(random 2);

if _posnum = 0 then {
_wp0 = this AddWaypoint[[10430.728,6,2259.363], 0];
_wp0 SetWaypointType"MOVE";
//_wp0 SetWaypointTimeout[60, 120, 180];

_wp1 = this AddWaypoint[[10443.817,6,2270.8374], 0];
_wp1 SetWaypointType"MOVE";

_wp2 = this AddWaypoint[[10455.811,6,2283.5322],0];
_wp2 SetWaypointType"GETIN NEAREST";

_wp3 = this AddWaypoint[GetMarkerPos "StarySoborWP", 0];
_wp3 SetWaypointType"MOVE";

_wp4 = this AddWaypoint[[11859.793,147.4823,12396.931], 0];
_wp4 SetWaypointType"GETOUT";

_wp5 = this AddWaypoint[[12024.746,159,12693.832], 0];
_wp5 SetWaypointType"MOVE";

_wp6 = this AddWaypoint[[12255.699,159,12602.938], 0];
_wp6 SetWaypointType"GETIN NEAREST";

}
else 

if _posnum = 1 then {

_wp0 = this AddWaypoint[[10430.728,6,2259.363], 0];
_wp0 SetWaypointType"MOVE";
//_wp0 SetWaypointTimeout[60, 120, 180];

_wp1 = this AddWaypoint[[10443.817,6,2270.8374], 0];
_wp1 SetWaypointType"MOVE";

_wp2 = this AddWaypoint[[[10455.811,6,2283.5322],0], 0];
_wp2 SetWaypointType"GETIN NEAREST";

_wp3 = this AddWaypoint[GetMarkerPos "PolanaWP", 0];
_wp3 SetWaypointType"MOVE";

_wp4 = this AddWaypoint[[11859.793,147.4823,12396.931], 0];
_wp4 SetWaypointType"GETOUT";

_wp5 = this AddWaypoint[[12024.746,159,12693.832], 0];
_wp5 SetWaypointType"MOVE";

_wp6 = this AddWaypoint[[12255.699,159,12602.938], 0];
_wp6 SetWaypointType"GETIN NEAREST";

}
else

if _posnum = 2 then {

_wp0 = this AddWaypoint[[10430.728,6,2259.363], 0];
_wp0 SetWaypointType"MOVE";
//_wp0 SetWaypointTimeout[60, 120, 180];

_wp1 = this AddWaypoint[[10443.817,6,2270.8374], 0];
_wp1 SetWaypointType"MOVE";

_wp2 = this AddWaypoint[[[10455.811,6,2283.5322],0], 0];
_wp2 SetWaypointType"GETIN NEAREST";

_wp3 = this AddWaypoint[GetMarkerPos "SolWP", 0];
_wp3 SetWaypointType"MOVE";

_wp4 = this AddWaypoint[[11859.793,147.4823,12396.931], 0];
_wp4 SetWaypointType"GETOUT";

_wp5 = this AddWaypoint[[12024.746,159,12693.832], 0];
_wp5 SetWaypointType"MOVE";

_wp6 = this AddWaypoint[[12255.699,159,12602.938], 0];
_wp6 SetWaypointType"GETIN NEAREST";

};



Edited by PhelanKA7

Share this post


Link to post
Share on other sites

Let me guess, none of the waypoints are ever being created? :P

---------- Post added at 11:59 PM ---------- Previous post was at 11:57 PM ----------

"random" generates a number less than or equal to what you designate after the command, in your case "2". However it generates numbers to a degree of I think 5 or more decimals. The chance it will ever equal 0, 1, or 2 is next to never. Use less than instead of equal to. Otherwise your script looks like.

Share this post


Link to post
Share on other sites
Let me guess, none of the waypoints are ever being created? :P

Heck if I know. The NPC sure doesn't move though :p

Share this post


Link to post
Share on other sites

Hm you caused me to look this up and teach myself something. If you want random numbers, do this from the wiki:

x=round(random 5) will return 0,1,2,3,4 or 5.
x=floor(random 5) will return 0,1,2,3 or 4.
x=ceil(random 5) will return 0, 1,2,3,4 or 5. (0 is very unlikely, but possible, as ceil 0 is 0)

http://community.bistudio.com/wiki/random

Share this post


Link to post
Share on other sites

The decimal issue of random was a good thought, but unfortunately there's something still wrong with my script. Thanks for the quick reply.

EDIT: I also figured out that I needed to put brackets around the numerical coordinates. Still doesn't work though...lol

Edited by PhelanKA7

Share this post


Link to post
Share on other sites

nul = [this] execVM "random.sqf";

_unit = _this select 0;
_group = group leader _unit;
_posnum = round(random 2);

if (_posnum == 0) then {
	hint format ["selected random option : %1 \ngroup : %2 from %3", _posnum,_group,_unit];   //DEBUG
	sleep 3;  //DEBUG
_wp1 = _group addWaypoint [[5000,5000,0], 0];
[_group, 1] setWaypointType "MOVE";
//_wp0 SetWaypointTimeout[60, 120, 180];
	hint format ["waypoint created. \ngroup : %1 \nwaypoint index number: %2", _wp1 select 0, _wp1 select 1];  //DEBUG
               sleep 3;  //DEBUG
_wp2 = _group AddWaypoint[[10443.817,6,0], 0];
[_group, 2] SetWaypointType"MOVE";
	hint format ["waypoint created. \ngroup : %1 \nwaypoint index number: %2", _wp2 select 0, _wp2 select 1];  //DEBUG
_wp3 = _group AddWaypoint[[10455.811,6,0],0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "StarySoborWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[[11859.793,147.4823,0], 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[[12024.746,159,0], 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[[12255.699,159,0], 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
//	_group setCurrentWaypoint [_group, 1]; 
}
else { 

BLAH BLAH BLAH .......................

init line : [this] = pass unit to the script

script :

_unit = _this select 0; : get the 1rst parameter passed to the script in this case "this" (the unit)

_group = group leader _unit; :waypoints refers to groups not unit so u need to get the grp of the unit

_wp1 = _group addWaypoint [[5000,5000,0], 0]; : renamed to _wp1 because a waypoint with index 0 is automaticaly created when unit spawn, this way the waypoint name will have the same numeric value as is index. NOTE : ur position values are wrong,when tested with your values the grp didnt move. the 3rd value (height above ground) should be 0

[_group, 1] setWaypointType "MOVE"; : setWaypointType need two parameters, the group wich the waypoint is assigned/linked too and the waypoint index number [_group, 1]

[_wp1 select 0, _wp1 select 1] might work aswell

(Lines with "// debug" at the end need to be deleted )

Edited by Ka-Oz

Share this post


Link to post
Share on other sites

Hrm, that doesn't work either. I'll keep tinkering with it. Thanks though.

Share this post


Link to post
Share on other sites

I just tried it and it does seem to work, I had to change the WP locations as I only use Utes, the problem is that it goes to the last waypoint7 as there's nothing to slow it down.

Share this post


Link to post
Share on other sites

yes as i stated in my comments the POSITION values are wrong and need to be changed.

dont get the positions from the mission.sqm instead use getpos

make a trigger , activation as radio alpha, repeatable.

inside on act put

pos = getpos your_marker_or_whatever_name ; hint format ["position = %1",pos];

Share this post


Link to post
Share on other sites
yes as i stated in my comments the POSITION values are wrong and need to be changed.

dont get the positions from the mission.sqm instead use getpos

make a trigger , activation as radio alpha, repeatable.

inside on act put

pos = getpos your_marker_or_whatever_name ; hint format ["position = %1",pos];

I tried using marker positions for the waypoints and it still doesn't work. If it's working for other people then hopefully I'll figure out what I'm doing wrong. Thanks for the help.

I'm probably not doing the else statements right.

_unit = _this select 0;
_group = group leader _unit;
_posnum = round(random 2);

if (_posnum == 0) then 
{
_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "StarySoborWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP7", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
}

else { 	

if (_posnum == 1) then {

_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "PolanaWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP7", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
}
}
else {

if (_posnum == 2) then {

_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "SolWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP7", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
}
}

That's what I have in there now. I took out the debug because I just made my player standing right behind him to see if the NPC does anything. And of course I have the init line for the NPC as you said:

nul = [this] execVM "random.sqf";

Edited by PhelanKA7

Share this post


Link to post
Share on other sites

not sure u can use 2 times ELSE in the same IF statement

it work fine without any else

_unit = _this select 0;
_group = group leader _unit;
_posnum = round(random 2);

if (_posnum == 0) then 
{
_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "StarySoborWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP7", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
};



if (_posnum == 1) then {

_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "PolanaWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP7", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
};


if (_posnum == 2) then {

_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "SolWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP7", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
};

Share this post


Link to post
Share on other sites
not sure u can use 2 times ELSE in the same IF statement

it work fine without any else

That's what I'm thinking as well. I've been reading up on control structures for the past 20 minutes to see if there's some other way I can have 3 possible statements from a random variable.

LOL. I'm an idiot. I just got rid of the ELSE statements, and just had 3 different IF statements and it works now. Not sure why I was thinking an ELSE statement was needed, but I guess we can chalk that up to Beginner's Luck :p

Thanks a ton for the help Ka-Oz. You're a true scholar, and gentleman :D

Edited by PhelanKA7

Share this post


Link to post
Share on other sites

Mine is working with 2 else statements, you may find the problem has been that the script is missing a "};" at the end as it's missing in post 10.

Also the getin nearest isn't working.

Share this post


Link to post
Share on other sites
Mine is working with 2 else statements, you may find the problem has been that the script is missing a "};" at the end as it's missing in post 10.

Would you mind posting it? I need the ELSE statements because without them, it's always using the same waypoint set.

Share this post


Link to post
Share on other sites

I changed the waypoint numbers as I was just playing about with it, I noticed yours just uses the same 7 all the time.

_unit = _this select 0;
_group = group leader _unit;
_posnum = round (random 2);

hint format["%1 ",_posnum];

sleep 2;
if (_posnum == 0) then 
{
_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"MOVE";

_wp4 = _group AddWaypoint[GetMarkerPos "StarySoborWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP7", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
}
else { 	

if (_posnum == 1) then {

_wp1 = _group addWaypoint [GetMarkerPos "WP8", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP9", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP10",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "PolanaWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP12", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP13", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP14", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
}

else {

if (_posnum == 2) then {

_wp1 = _group addWaypoint [GetMarkerPos "WP15", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP16", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP17",0];
[_group, 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group AddWaypoint[GetMarkerPos "SolWP", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP19", 0];
[_group, 5] SetWaypointType"GETOUT";

_wp6 = _group AddWaypoint[GetMarkerPos "WP20", 0];
[_group, 6] SetWaypointType"MOVE";

_wp7 = _group AddWaypoint[GetMarkerPos "WP21", 0];
[_group, 7] SetWaypointType"GETIN NEAREST";
_group setCurrentWaypoint [_group, 1]; 
}
}
};

Share this post


Link to post
Share on other sites

Nevermind. I saw that you had your own "WP" #'s in the other IF statements. It works now!

Thanks for the help F2k, and everyone else who offered their advice.

Edited by PhelanKA7

Share this post


Link to post
Share on other sites

One more quick question:

I'm trying to get a group (_group2) to get in a helicopter (_group3) at a waypoint. All of the units move just fine, except the chopper does not come down to load the ground units. I've tried a "synchronizeWaypoint" but it doesn't seem to work.

Here's what I"ve got:

_unit = _this select 0;
_group = group leader _unit;
_posnum = round (random 2);
_unit2 = _this select 1;
_group2 = group leader _unit2;
_unit3 = _this select 2;
_group3 = group leader _unit3;

_wp1 = _group2 AddWaypoint[GetMarkerPos "WP2", 0];
[_group2, 1] setWaypointtype "GETIN";
_group2 SetCurrentWaypoint [_group2, 1];

_wp1 = _group3 AddWaypoint[GetMarkerPos "WP2", 0];
[_group3, 1] SetWaypointtype "LOAD";
_group3 SetCurrentWaypoint [_group3, 1];

[_group2, 1] synchronizeWaypoint [_group3, 1];

hint format["%1 ",_posnum];

sleep 2;
if (_posnum == 0) then 
{
_wp1 = _group addWaypoint[GetMarkerPos "GO", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "StarySoborWP", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 3] SetWaypointType"MOVE";

_group setCurrentWaypoint [_group, 1];

}

else { 	

if (_posnum == 1) then .... 

EDIT: Nevermind! I needed to say "[_group2, 1] synchronizeWaypoint [[_group3, 1]]". Instead of with single brackets like I had it. Sorry for bumping this thread.

Edited by PhelanKA7

Share this post


Link to post
Share on other sites

Ok... Here's something I can't figure out:

_group1 at a point in any of his possible statements "gets in a nearest" vehicle which I have setup as a named/unlocked/Chernarus/civilian car in the editor. He then drives to a location, and gets out of said vehicle. He makes his way to _group2 and successfully joins their group.

Now is where it gets funky. _group2 sends the _group1 guy back to the car he showed up in which causes pathing problems for the pickup performed by _group3 (a chopper). None of this happens if _group1 never got into a car.

Is there something I need to tell the game when _group1 gets out of the car, that will keep _group2 from sending him back to it?

Sorry to keep bringing this topic back up. Just when I think something is buggy and won't work I (or someone else :p) figure out that it was me doing something incorrectly, or not doing something I needed to.

Thanks for any help.

_posnum = round (random 2);

_unit1 = _this select 0;
_group1 = group leader _unit1;
_unit2 = _this select 1;
_group2 = group leader _unit2;
_unit3 = _this select 2;
_group3 = group leader _unit3;

/////////////////////////////////////////////////////////////////
///////////////////ESCORT MOVES//////////////////////////////////
_wp1 = _group2 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group2, 1] setWaypointtype "LEADER";
_group2 SetCurrentWaypoint [_group2, 1];

_wp2 = _group2 AddWaypoint[GetMarkerPos "WP2", 0];
[_group2, 2] setWaypointtype "GETIN";
_group2 SetCurrentWaypoint [_group2, 1];


/////////////////////////////////////////////////////////////////
///////////////////CHOPPER MOVES/////////////////////////////////
_wp1 = _group3 AddWaypoint[GetMarkerPos "WP2", 0];
[_group3, 1] SetWaypointtype "LOAD";
_group3 SetCurrentWaypoint [_group3, 1];
/////////////////////////////////////////////////////////////////

[_group2, 1] synchronizeWaypoint [[_group3, 1]];

hint format["%1 ",_posnum];

sleep 2;
if (_posnum == 0) then 
{
_wp1 = _group1 addWaypoint[GetMarkerPos "GO", 0];
[_group1, 1] setWaypointType "MOVE";	

_wp2 = _group1 addWaypoint[GetMarkerPos "GO", 0];
[_group1, 2] SetWaypointType "GETIN NEAREST";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp3 = _group1 AddWaypoint[GetMarkerPos "StarySoborWP", 0];
[_group1, 3] SetWaypointType"MOVE";

_wp4 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1, 4] SetWaypointType "GETOUT";

_wp5 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1, 5] SetWaypointType"JOIN";

_group1 setCurrentWaypoint [_group1, 1];


}

else { 	

if (_posnum == 1) then {

_wp1 = _group1 addWaypoint[GetMarkerPos "GO", 0];
[_group1, 1] setWaypointType "MOVE";	

_wp2 = _group1 addWaypoint[GetMarkerPos "GO", 0];
[_group1, 2] setWaypointType "GETIN NEAREST";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp3 = _group1 AddWaypoint[GetMarkerPos "PolanaWP", 0];
[_group1, 3] SetWaypointType"MOVE";

_wp4 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1, 4] SetWaypointType "GETOUT";

_wp5 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1, 5] SetWaypointType"JOIN";

_group1 setCurrentWaypoint [_group1, 1];


}

else {

if (_posnum == 2) then {
_wp1 = _group1 addWaypoint[GetMarkerPos "GO", 0];
[_group1, 1] setWaypointType "MOVE";	

_wp2 = _group1 addWaypoint[GetMarkerPos "GO", 0];
[_group1, 2] setWaypointType "GETIN NEAREST";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp3 = _group1 AddWaypoint[GetMarkerPos "SolWP", 0];
[_group1, 3] SetWaypointType"MOVE";

_wp4 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1, 4] SetWaypointType "GETOUT";

_wp5 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1, 5] SetWaypointType"JOIN";

_group1 setCurrentWaypoint [_group1, 1];

}
}
};

[_group1, 5] synchronizeWaypoint [[_group2, 1]];

Share this post


Link to post
Share on other sites

After extensive testing I have finally gotten a script that does exactly what I need. So I give you all (or at least those who are interested :D) my very first script for public consumption.

The purpose of this script is to generate a random whole number, and assign it to a variable. This variable is part of a collection of IF/ELSE statements that contain a list of possible waypoints whose coordinates are given through marker positions. Also I have added a Group2 that awaits Group1 (the one with random WPs) at a destination. At this destination they board a vehicle, Group3, that arrived from another location. Group3 takes Group1 and Group2 away in the transport to another location.

I made this for a "Cat and Mouse" type mission for use with the Little Bird helicopter. Group1 is the target that is trying to escape Chernarus. I will post a link to that mission after I've gotten the Armaholic page updated with a version using this script.

In order to get this script to "work out of the box" you will need:

  1. A passenger who will run this script in their init line. (nul = [this, escort, getaway] execVM "RandomWaypoints.sqf"; )
  2. An escort(s) who will be named "escort" within the editor
  3. A vehicle that will be named "getaway"
  4. A series of waypoints named "WP1", "WP2", "WP3", "WP5", "WP6", "WP8", "RandomWP1", "RandomWP2", "RandomWP3","Joinup", "Pickup", "Moveout1", and "Moveout2"
  5. A trigger that detects the passenger and makes "PassengerArrives" true.

If you have any questions on how to get this working for your particular needs feel free to ask here, PM me, or email me.

Here is the script:

(NOTE: Group2 *cannot* GETIN a vehicle at any point except for the Group3 vehicle with Group1. This is due to a documented bug in Arma2. This is why Group1 MUST be the LEADER at the "Joinup" marker. If you try to put Group2 in a vehicle and have them JOIN Group1 they will board their previous vehicle instead of joining Group1 in Group3. Let's hope it's fixed.)

//////////////"RANDOM" WAYPOINT GROUP SCRIPT w/ ESCORT AND ESCAPE VEHICLE AT DESTINATION/////////////////////
////////////////////////////////////////////By PhelanKA7/////////////////////////////////////////////////////
/////////////////////////////////////email: phelanka7@gmail.com//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////Implementation: In the init field of your Passenger type vvvvv////////////////////////
//////////////////////////nul = [this, escort, getaway] execVM "RandomWaypoints.sqf";////////////////////////
/////////////////////MAKE SURE TO NAME YOUR ESCORT GROUP 'escort' AND THE VEHICLE 'getaway'//////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////Thanks to J-Dog, Ka-Oz, and F2kSel @ the BIS forums for helping me get started/////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

_posnum = round (random 2);

_unit1 = _this select 0; //Unit1/Group1 are the "Passenger" who runs through the random waypoint lists.
_group1  = group leader _unit1;
_unit2 = _this select 1; //Unit2/Group2 are the "Escorts" who meet up with the "Passenger" before boarding Unit3/Group3 (Vehicle).
_group2 = group leader _unit2;  
_unit3 = _this select 2; //Unit2/Group3 is the pickup vehicle.
_group3 = group leader _unit3;

hint format["%1 ",_posnum]; //FOR DEBUG PURPOSES.  REMOVE BEFORE USING A MAP YOU ARE DISTRIBUTING

/////////////////////////////////////////////////////////////////
///////////////////ESCORT JOINS//////////////////////////////////
/////////////////////////////////////////////////////////////////
_wp1 = _group2 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group2, 1] setWaypointtype "JOIN";

_group2 SetCurrentWaypoint [_group2, 1];
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////
///////////////////CHOPPER MOVES/////////////////////////////////
/////////////////////////////////////////////////////////////////
_wp1 = _group3 AddWaypoint[GetMarkerPos "Pickup", 0];
[_group3, 1] SetWaypointType "GETOUT";

_wp2 = _group3 AddWaypoint[GetMarkerPos "Pickup", 0];
[_group3, 2] SetWaypointType "LOAD";
[_group3, 2] SetWaypointStatements ["PassengerArrives",""];  //Keeps transport from leaving before Group1/Group2 board the transport.

_wp3 = _group3 AddWaypoint[GetMarkerPos "Moveout1", 0];
[_group3, 3] SetWaypointType "MOVE";

_wp4 = _group3 Addwaypoint[GetMarkerPos "Moveout2", 0];
[_group3, 4] SetWaypointType "MOVE";

_group3 SetCurrentWaypoint [_group3, 1];
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////


sleep 2;

//Group1 gets escape route from random generation vvvv

if (_posnum == 0) then 
{
_wp1 = _group1 addWaypoint [GetMarkerPos "WP1", 0];
[_group1 , 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group1 AddWaypoint[GetMarkerPos "WP2", 0];
[_group1 , 2] SetWaypointType"MOVE";

_wp3 = _group1 AddWaypoint[GetMarkerPos "WP3",0];
[_group1 , 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group1 AddWaypoint[GetMarkerPos "WP8",0];
[_group1 , 4] SetWaypointType"MOVE";

_wp5 = _group1 AddWaypoint[GetMarkerPos "RandomWP1", 0];
[_group1 , 5] SetWaypointType"MOVE";

_wp6 = _group1 AddWaypoint[GetMarkerPos "WP5", 0];
[_group1 , 6] SetWaypointType"GETOUT";

_wp7 = _group1 AddWaypoint[GetMarkerPos "WP6", 0];
[_group1 , 7] SetWaypointType"MOVE";

_wp8 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1 , 8] SetWaypointType"LEADER";

_wp9 = _group1 AddWaypoint[GetMarkerPos "Pickup", 0];
[_group1 , 9] SetWaypointtype"GETIN";

_group1 setCurrentWaypoint [_group1 , 1]; 

//Synchronizes Group1 to LEAD Group2.  Since Group1 already boarded a vehicle at index 3, they must lead or else Group2 would tell them to reboard original vehicle.
[_group1 , 8] synchronizeWaypoint [[_group2, 1]];  

//Synchronizes Group1 to GET IN Group3 transport.
[_group1 , 9] synchronizeWaypoint [[_group3, 2]];


}

else { 	

if (_posnum == 1) then {

_wp1 = _group1  addWaypoint [GetMarkerPos "WP1", 0];
[_group1 , 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group1  AddWaypoint[GetMarkerPos "WP2", 0];
[_group1 , 2] SetWaypointType"MOVE";

_wp3 = _group1  AddWaypoint[GetMarkerPos "WP3",0];
[_group1 , 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group1  AddWaypoint[GetMarkerPos "RandomWP2", 0];
[_group1 , 4] SetWaypointType"MOVE";

_wp5 = _group1  AddWaypoint[GetMarkerPos "WP5", 0];
[_group1 , 5] SetWaypointType"GETOUT";

_wp6 = _group1 AddWaypoint[GetMarkerPos "WP6", 0];
[_group1 , 6] SetWaypointType"MOVE";

_wp7 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1 , 7] SetWaypointType"LEADER";

_wp8 = _group1 AddWaypoint[GetMarkerPos "Pickup", 0];
[_group1 , 8] SetWaypointtype"GETIN";

_group1 setCurrentWaypoint [_group1 , 1]; 

[_group1 , 7] synchronizeWaypoint [[_group2, 1]];

[_group1 , 8] synchronizeWaypoint [[_group3, 2]];

}

else {

if (_posnum == 2) then {

_wp1 = _group1 addWaypoint [GetMarkerPos "WP1", 0];
[_group1 , 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group1 AddWaypoint[GetMarkerPos "WP2", 0];
[_group1 , 2] SetWaypointType"MOVE";

_wp3 = _group1 AddWaypoint[GetMarkerPos "WP3",0];
[_group1 , 3] SetWaypointType"GETIN NEAREST";

_wp4 = _group1 AddWaypoint[GetMarkerPos "RandomWP3", 0];
[_group1 , 4] SetWaypointType"MOVE";

_wp5 = _group1 AddWaypoint[GetMarkerPos "WP5", 0];
[_group1 , 5] SetWaypointType"GETOUT";

_wp6 = _group1 AddWaypoint[GetMarkerPos "WP6", 0];
[_group1 , 6] SetWaypointType"MOVE";

_wp7 = _group1 AddWaypoint[GetMarkerPos "Joinup", 0];
[_group1 , 7] SetWaypointType"LEADER";

_wp8 = _group1 AddWaypoint[GetMarkerPos "Pickup", 0];
[_group1 , 8] SetWaypointtype"GETIN";

_group1 setCurrentWaypoint [_group1 , 1]; 

[_group1 , 7] synchronizeWaypoint [[_group2, 1]];

[_group1 , 8] synchronizeWaypoint [[_group3, 2]];

}
}
};

Edited by PhelanKA7

Share this post


Link to post
Share on other sites

Glad you got it working the way you want it to. :)

Here is an option for you to consider, though, too, if you don't mind. :D

I've done random movement locations 2 different ways.

1) have an array of either marker names (strings) or positions (position arrays). I can then have a loop set to however many waypoints I want, and within that loop, select a random element of the array. That will get a marker/position that I can then use in an addWaypoint set of commands or setWaypointPosition command if the waypoints have already been generated.

2) more recently, if I don't need to have an entire route planned, I'll just use the current position of the unit, and generate a random direction and distance to get a position (using sin/cos type stuff) - usually the distances I use are 150-300m from the current position, although the A2 AI does reasonably good pathfinding for greater distances than that. Then I use doMove command and waitUntil the unit is ready. Put the position-finding and moving/waiting within a while loop (while the unit is alive or whatever), and it works well.

You can actually mix and match the two systems, also, if you want.

If you haven't already, I suggest registering at OFPEC. Incredible amount of information and help available there.

Again, well done. :)

Share this post


Link to post
Share on other sites
Glad you got it working the way you want it to. :)

Here is an option for you to consider, though, too, if you don't mind. :D

I've done random movement locations 2 different ways.

1) have an array of either marker names (strings) or positions (position arrays). I can then have a loop set to however many waypoints I want, and within that loop, select a random element of the array. That will get a marker/position that I can then use in an addWaypoint set of commands or setWaypointPosition command if the waypoints have already been generated.

2) more recently, if I don't need to have an entire route planned, I'll just use the current position of the unit, and generate a random direction and distance to get a position (using sin/cos type stuff) - usually the distances I use are 150-300m from the current position, although the A2 AI does reasonably good pathfinding for greater distances than that. Then I use doMove command and waitUntil the unit is ready. Put the position-finding and moving/waiting within a while loop (while the unit is alive or whatever), and it works well.

You can actually mix and match the two systems, also, if you want.

If you haven't already, I suggest registering at OFPEC. Incredible amount of information and help available there.

Again, well done. :)

Those are some good ideas. Thank you :)

The reason I did it the way I did it is that the mission is spread out over a very large portion of Chernarus. If it got *too* random for my mission, finding the target could take an absolutely insane amount of time.

That's why I titled it "Random" because while the different paths vary at a couple of specific points, overall the structure of the waypoints are similar and somewhat predictable.

But anyways, thanks again for the feedback!

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  

×