Jump to content
Sign in to follow this  
avibird 1

How to prevent non playable units from moving to close to a player unit!

Recommended Posts

I am using this code to spawn in support units from FOB's in a mission that I am working on.

_pos = [(getPosATL Player select 0) + (70 * sin(90)), (getPosATL Player select 1) + (70 * cos(90)), 0];

HQ2MechanizedBAFunits = CreateGroup WEST;

All works great the Mechanized group spawns on the east side of the FOB 70 meters away.

The group has a series of waypoints that allows the group to move to the current location of the SL that called in the group for an Assault of that position. Here is the waypoints

sleep 10;
hint "Squad Leader advance to the sector Position that you want Mechanized Platoon to Assault, deployment time ETA 2 minutes from Outpost Sparrow 2"; 

[color="#B22222"] //staging sector
wp1 = HQ2Mechanized addwaypoint [position Player, 100];   
wp1 waypointAttachVehicle vehicle player; 
wp1 setwaypointtype "MOVE"; 
wp1 setWaypointCombatMode "YELLOW"; 
wp1 setWaypointFormation "DIAMOND"; 
wp1 setWaypointSpeed "FULL"; 
wp1 setWaypointBehaviour "AWARE"; 
wp1 setWaypointCompletionRadius 10; 
wp1 setWaypointStatements ["true", "hint 'British Mechanized Platoon Heron Attempting to move to Assault Position Alpha';"];
wp1 setWaypointTimeout [120,120,120]; [/color]


[color="#0000CD"] //Alpha waypoint
wp2 = HQ2Mechanized addwaypoint [position Player, 50]; 
wp2 waypointAttachVehicle vehicle player;  
wp2 setwaypointtype "SAD"; 
wp2 setWaypointCombatMode "Yellow"; 
wp2 setWaypointFormation "WEDGE"; 
wp2 setWaypointSpeed "FULL"; 
wp2 setWaypointBehaviour "AWARE"; 
wp2 setWaypointCompletionRadius 10;
wp2 setWaypointStatements ["true", "hint 'British Mechanized Platoon Heron Attempting to move to Assault Position Bravo';"];
wp2 setWaypointTimeout [30,30,30]; 


//Bravo waypoint
wp3 = HQ2Mechanized addwaypoint [position Player, 50]; 
wp3 waypointAttachVehicle vehicle player;  
wp3 setwaypointtype "SAD"; 
wp3 setWaypointCombatMode "YELLOW"; 
wp3 setWaypointFormation "VEE"; 
wp3 setWaypointSpeed "FULL"; 
wp3 setWaypointBehaviour "AWARE"; 
wp3 setWaypointCompletionRadius 10;
wp3 setWaypointStatements ["true", "hint 'British Mechanized Platoon Heron Attempting to move to Assault Position Charlie';"];
wp3 setWaypointTimeout [30,30,30]; 


//Charlie waypoint
wp4 = HQ2Mechanized addwaypoint [position Player, 50]; 
wp4 waypointAttachVehicle vehicle player; 
wp4 setwaypointtype "SAD"; 
wp4 setWaypointCombatMode "YELLOW"; 
wp4 setWaypointFormation "WEDGE"; 
wp4 setWaypointSpeed "FULL"; 
wp4 setWaypointBehaviour "AWARE"; 
wp4 setWaypointCompletionRadius 10;
wp4 setWaypointStatements ["true", "hint 'British Mechanized Platoon Heron Attempting to move to Assault Position Delta';"]; 
wp4 setWaypointTimeout [30,30,30]; 


//Delta waypoint
wp5 = HQ2Mechanized addwaypoint [position Player, 50]; 
wp5 waypointAttachVehicle vehicle player; 
wp5 setwaypointtype "SAD"; 
wp5 setWaypointCombatMode "YELLOW"; 
wp5 setWaypointFormation "WEDGE"; 
wp5 setWaypointSpeed "FULL"; 
wp5 setWaypointBehaviour "AWARE"; 
wp5 setWaypointCompletionRadius 10;
wp5 setWaypointStatements ["true", "hint 'British Mechanized Platoon Heron will Establish a New staging sector to regroup for Orders to Assault New Alpha,Bravo,Charlie and Delta Positions';"];
wp5 setWaypointTimeout [30,30,30]; 


//cycle waypoint
wp6 = HQ2Mechanized addwaypoint [position Player, 50];
wp6 waypointAttachVehicle vehicle player;  
wp6 setwaypointtype "Cycle";[/color]  

The waypoints work great But the issue is with the first waypoint in red the staging sector. The group will move to the players location wp1 = HQ2Mechanized addwaypoint [position Player, 100]; but WILL move closer then the 100 meters. In fact the lead Mechanized vechicle will drive into the FOB MOST OF THE TIME and gets trapped making the whole Mechanized group combat insufficient for the mission):

The script allows the SL to call in other units from a combat menu and not from inside the FOB. The script works great then. I think the codeline of waypointAttachVehicle vehicle player may cause the issue but I need the code to allow the units to follow the SL to new location throughout the map.

Any input how I CAN stop the units from moving that close to the player unit when using the above codes. AVIBIRD.

Ice baby Ice (vanilla ice that is) lol No big to add the tags. If you have any suggestions that would be great. Like your sig below I can't move on to new problems when my Mechanized group is killing my FOB. Avibird

Edited by AVIBIRD 1

Share this post


Link to post
Share on other sites

AV. Please use code tags. As cliché as it may sound, you've been around long enough. Please use the code tags. In the mean while I'll try to sort the problem out.

Share this post


Link to post
Share on other sites

After testing The waypointAttachVehicle vehicle player; Is the issue But it is a must for the script to work the way is was designed to work.

Is there a way to combine to commands into one codeline.

In the script I also use these

1. [(player ModelToWorld [0,-500,0]), 0];

2. [position Player, 75];

I tryed to add

wp1 waypointAttachVehicle; [vehicle player, position Player, 75];

wp1 waypointAttachVehicle ; [(player ModelToWorld [0,-500,0]), 0];

I am just stabbing in the dark. Is there a way to add to command/codes into.

Share this post


Link to post
Share on other sites

I haven't read the whole post, but I found a problem with waypointAttachVehicle vehicle player in that it attaches only some of the waypoint.

the setWaypointCompletionRadius gets left at the original position.

Share this post


Link to post
Share on other sites

Hey the F2k the setWaypointCompletionRadius is no big deal and it should not be in the codeline/script as well as the addwaypoint [position Player, 50]; because the waypointAttachVehicle vehicle player overrides them both. The units will move right next to the player position < 5 meters away.

The script that I am working on is for a mission that uses a lot of different AI support units for a group of human players and only the SL can call in the support for the mission. The way I have the waypoints working the support units will follow the group all over the map.

Each support group has a different function to stop the support and delete the group during the mission.

1. All units of the group gets killed

2. a set time amount for that group on the map is reached

3 no enemy units are in a set radius on the map

The SL can call for support units from a combat support menu. I have no issues with the units/group from this menu all works great. In the Combat support menu there are two options to call in and build two different FOB's. Once the FOB is constructed the SL and other lower rank human players has the options to use a different base resource menu to call in other support units and items. The problem is the Mechanized units from the FOB menu will move right into the base before the first real combat waypoint is used. The Mechanized units at times will get trapped inside the FOB and kill some of the base defense units inside the FOB.

I know the issue is with the waypointAttachVehicle vehicle player command but I was hoping there was a way to limited the distance the command makes the units move next to the player. This may be a hard code thing that can't be altered. I don' t know that's above my paygrade with scripting lol.

I can change the the Mechanized units from the FOB's menu to a different waypoint setup but I really like the fucntionally of the setup that I have for the mission. If there is a way I would love to know. I don't give up that easy but lack the knowledge to help myself lol. AVIBIRD.

Share this post


Link to post
Share on other sites

It doesn't do what you think it does....

You are creating a waypoint 500m away from the player

waypoint waypointAttachVehicle vehicle player;

Then moves that waypoint to the player and attaches it to the player - there is no way of setting it 500m away using this command - it's the wrong command to use.

Share this post


Link to post
Share on other sites

Tried placing a trigger on the unit to check the distance to the caller and then issue a stop until called again or distance > than whatever.

That should work even if waypoint waypointAttachVehicle vehicle player is placed directly over the unit.

I guess you could also try updating setwaypointposition to the player which should allow waypointcomprad to work, but that may not work as route planning my override it.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Was just looking for something I posted earlier to solve this for someone:

http://forums.bistudio.com/showthread.php?145606-Can-I-make-an-AFV-follow-a-group

You need to use a loop to continually move the waypoint to a position x metres away from the player.

Changed it to make it easier to use:

syntax: nul = [vehicle,groupNameToFollow,distance,bearingInDegrees] execVM "follow.sqf";

eg vehicle init field: nul = [this,group player,500,180] execVM "follow.sqf";

vehicle/unit will follow a position 500m south of player


private ["_pos","_cntrPos","_vcl","_grp","_wPArray","_wp1","_dist"];

_vcl = _this select 0;
_grp = _this select 1;
_dist = _this select 2;
_degs = _this select 3;

//remove all previous waypoints
_wPArray = waypoints (group _vcl);
      for "_i" from 0 to (count _wPArray -1) do 
{
      deleteWaypoint [(group _vcl), _i]
};

//add 1 WP it's all you need
_wp1 = (group _vcl) addWaypoint [getPosATL _vcl, 100];
   _wp1 setWaypointType "MOVE";

//movement loop
while {alive _vcl} do {
_cntrPos = getPosATL (leader _grp);

if (format ["%1", _cntrPos] != "[0,0,0]") then {

   _pos = [(_cntrPos select 0) + (_dist * sin(_degs)), (_cntrPos select 1) + (_dist * cos(_degs)), 0];
     _wp1 setWaypointPosition [_pos, 0];
       (group _vcl) setCurrentWaypoint _wp1;};
sleep 30;
};

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Hey mattar and F2K thank you for your support and input on my my scripting dilemmas.

@ mattar I don't think you fully understand what I am working on. This is a very large support script and I am using many different commands for different support groups within the whole script.

the [(player ModelToWorld [0,-500,0]), 0]; works great. I am using it for specific groups that partol the FOB's. I am using a series of waypoints using the this format [(player ModelToWorld [0,0,0]), 0]; to patrol north, south, east and west of the FOB's 500 meters away with a cycle waypoint that loops the partol around the FOB's. That's not the issue.

I am using the The waypointAttachVehicle vehicle player command to make specific support groups to follow a Human SL who called the group in during the mission all over the map. I am using a series of waypoints with ( move , SAD, SAD, SAD, SAD and a cycle waypoint. This allows a group to Assault a Position using the SAD waypoint. The group will not move to the next waypoint if enemy units are still in the general area. This Works great. The key here is when the new waypoint gets triggered the group will move to the current position of the human SL within 5 meters when the waypoint got triggered and then the SAD kicks in. The SL then can move to a new location. The group is now on the SAD waypoint and will not follow the SL until all the enemy units are killed in that location.

My issue was when using the waypointAttachVehicle vehicle player command with one of the groups that the human SL called in using the FOB menu (inside the FOB's) The group would move inside the the FOB and if the group had a vechicle most of the time it would get trapped inside the FOB. If the human SL used the Combat support menu in the open enviroment that is attached to the SL and not inside the FOB's the script works great.

I hope you understand what I am talking about and how the script works now. I found an easy fix to the issue. I just had to remove the waypointAttachVehicle vehicle player command from the first staging sector waypoint and the last cycle waypoint. Now the addwaypoint [position Player, 50]; command works at the start and end of the waypoint cycle.

Thanks for the input without help form others to look in different directions one would go crazy gettting things to work the way you want them to (: AVIBIRD.

Edited by AVIBIRD 1

Share this post


Link to post
Share on other sites

I use repeating triggers to do this in missions where I want to keep the ai units, that are under my command, from getting too close to me or standing up when they should keep low. If they are more than 50 meters from me, they will stand, run and regroup, if they are less than 50 meters from me and more than 25 meters, they will crouch and regroup. If they are less than 25 meters from me, they will stop and stay crouched. If I then move to another position farther than 100 meters from them, they will once again continue to follow and the triggers will continue to make them behave as I wish. At any time I can "manually" command then to regroup or move to a position next to me and they will. They will also go prone if I command them to. Since the triggers are set to repeat, the triggers will re-activate and continue to function as they should, which keeps the ai behaving exactly the way I want them to throughout the course of the mission.

Lets say I am leader/player "s1". this would be an example of a 3 trigger system for player "s2".

The 1st trigger tells the player "s2" to stand and regroup if he is more than 50 from my position. This keeps the ai moving fast when I need him to keep up with me.

Radius: 0

Activation: None, Repeatedly

Condition: s2 distance s1>50

OnAct: s2 doFollow s1; s2 setUnitPos "UP";

The 2nd trigger tells the AI to crouch if he is less than 50 meters from my position. Now the ai is more stealth and I don't have to manually give him an order to keep low.

Trigger 2:

Radius: 0

Activation: None, Repeatedly

Condition: s2 distance s1>25 && s2 distance s1<50

OnAct: s2 setUnitPos "MIDDLE"

The 3rd trigger tells the ai to stop if he is within 25 meters of my position and he will remain crouched.

Trigger 3:

Radius: 0

Activation: None, Repeatedly

Condition: s2 distance s1<25

OnAct: doStop [s2];

I could also use "doFollow" in trigger 2 as well, but I like how I am able to move forward alone and the ai will once again continue to follow once I am 100 meters away. This gives me the opportunity to go Rambo a little without the ai getting in my way or drawing the enemy's attention to me. Again, at any time I can manually give the command to regroup or move to a position near me.

Once I create the 3 triggers for "s2" I then copy and paste the 3 triggers to be used for another ai unit and I simply change the corresponding name used in the trigger to work with the other ai in the mission. It sounds like a lot of triggers, but they are extremely useful and it is a very simple method and requires very few commands. You can use "commandFollow" instead of "doFollow", but "doFollow" will issue the command silently, which is much better because you will otherwise get a nasty headache from listening to yourself issuing individual "Regroup" commands non-stop throughout the entire mission.

Here's a sample mission:

http://www.odaly.com/files/a2_all_version/smart_ai.zip

Obviously the trigger distance settings can be adjusted to your needs. You can even force the ai to go prone when they are close to you with "DOWN", or you can use "AUTO" and the ai will choose the stance that they think suites the situation.

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  

×