Jump to content
Sign in to follow this  
scottdog62

How to make AI break combat, and how to force a player stay in the vicinity of a unit

Recommended Posts

I'm making a mission where you play as a squad member and you spot a large enemy force, and now you need to retreat. The problem is how to make the AI break combat mode, and follow there way point(they just stay in combat mode and don't move). I'v tried careless mode, but they just walk.

And the other thing i need is to make it so the player must stay in the vicinity of the squad leader, So i want to give the player a warning, then if you don't get back within range of squad leader you fail mission.

Share this post


Link to post
Share on other sites

And the other thing i need is to make it so the player must stay in the vicinity of the squad leader, So i want to give the player a warning, then if you don't get back within range of squad leader you fail mission.

For this you could do it a couple ways, you could either run a while/do loop in a script to check the distance of the player to whatever unit every couple of seconds, or use two repeatable triggers, the first having the distance for a warning, the second failing the mission.

 

Using the distance command is fairly simple, just add a check for whether or not the number is greater than whatever distance you desire the player to remain within.

 

As for the retreating, I don't know the command by heart, but I think it's like enableFleeing or allowFleeing or something like that.

Share this post


Link to post
Share on other sites

Thanks, tried getting it to work. But must have done something incorrect.

 

this was the example

 

 

_meters = player distance _object;

 

This is what i used

 

 

20 = unit2 distance unit1;

 

unit 2 is player

 

it didn't work

Share this post


Link to post
Share on other sites
Guest
if(unit1 distance unit2 < 20) then {
    diag_log "Unit1 is under 20 meters away of unit2";
}

Share this post


Link to post
Share on other sites

I put that in the condition of trigger, but it's still not working. I am missing anything?

Share this post


Link to post
Share on other sites

My bad, I didn't know you were looking for a pre-packaged solution, I thought you were just asking about how it might be done.

 

For a script, you can either use the if/then statement harmdhast posted, or use it in a while/do loop, so something like:

_unit1 = player
_unit2 = myUnitName

while {_unit2 distance _unit1 > 100 && alive _unit1 && alive _unit2} do {
hintSilent "You are moving too far away! Return to formation!";
sleep 5;
};
So what that does is every 5 seconds or so it checks the player's distance to whoever myUnitName is; if it's over 100m, it will display the hint, if it is less than or equal to 100m, it will not display the hint (keep in mind hints stay on the screen from ~20-30sec, so the hint won't instantly disappear once the player is back within the required distance with this simple example). But because both units must be alive, the hint shouldn't be created if either the player or the myUnitName guy die.

The other option is with a trigger set to be repeatable. In the condition field place something like

player distance myUnitName > 100;
and in the On Activation field put

hintSilent "You are moving too far away! Return to formation!";
Now the trigger should fire each time the distance between the player and whoever he/she should be following is greater than 100m. The only potential issue with this is if the unit the player is supposed to stay near can die (not invincible), the trigger will probably fire if he dies and then the player continues on with the mission, but again you can add the check for whether or not the unit is alive just like the script if you want.

As a disclaimer I'll add I can't put this stuff into a mission to check it right now, so if it doesn't work exactly as I typed it you will still be close and on the right track, I might have missed a parenthesis or something. And I should also add I don't do scripting for co-op or dedicated server stuff, so I have no idea if this will work in any sort of multiplayer environment, I only work with single player stuff.

Share this post


Link to post
Share on other sites

Thanks heeps Mynock. I'm not very good when it comes to the scripting side of things, thanks for your time.
The second one with the trigger i was the one I was looking for, works great.

Share this post


Link to post
Share on other sites

For the first problem i did allowfleeing 1, they break combat, but they just run around like headless chooks, they don't follow the waypoint I set.
 

So is there another way to do that?

Share this post


Link to post
Share on other sites

Can't give you a scripting solution. But turning them to careless mode will make them ignore all combat and move to the next waypoint.

Share this post


Link to post
Share on other sites

Yes, you can set them to careless mode instead to make them flee, but if they are walking still like you said then that is a problem I'm assuming. Dig through this thread I googled up: https://forums.bistudio.com/topic/151693-make-ai-sprint/Might be as simple as setting the speed mode for the unit, although some people are reporting bugs when trying to script it, but there look to be some workarounds in there if it hasn't been fixed yet in the game (most of that thread info is a couple years old, it might not be an issue anymore). They're talking about sprinting toward a target, but obviously it's the same for running away, just a different destination.

Share this post


Link to post
Share on other sites

Here's a function I'm using to but AI in "rout" mode:

// rout.sqf
// input: group of AI to set in rout mode, marker to flee toward to
// return: nothing
// effect: for all units of a group: disable all combat behabiour, delete all waypoints, add a WP to a place to flee to
// dans l'init.sqf, faire:  wz_rout = compile preprocessFile "func\rout.sqf";
// exemple d'appel de la fonction:  [groupe_att_7_1, "att7_1"] call wz_rout

private ["_grp", "_mkr_flee", "_wp"];
_grp = _this select 0;
_mkr_flee = _this select 1;

{
    _x commandWatch objNull;
    _x disableAI "AUTOTARGET";
    _x disableAI "TARGET";
    _x disableAI "SUPPRESSION";
    _x disableAI "AUTOCOMBAT";
} forEach units _grp;



while {(count (waypoints _grp)) > 0} do
    {
    deleteWaypoint ((waypoints _grp) select 0);
    };


_wp = _grp addWaypoint [getMarkerPos _mkr_flee, 20] ;
_wp setWaypointSpeed "FULL";
_wp setWaypointBehaviour "AWARE";
_wp setWaypointType "MOVE";

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  

×