Jump to content
  • 0

Seek/Hunt script?


Nemaconz

Question

So I have a script that works, just not the way I want it to. Here it is, it will probably look familiar to some people have been around a while.

 

  _theHunt = (position _aiunit) nearEntities ["Bandit2_DZ", _wpradius];
  _target = _theHunt call BIS_fnc_selectRandom;

 

 while {alive _unit && (_unit distance _target > 10)} do {
    _unit doMove getPos _target;
    sleep 3;
  };

 

//generate waypoints
for [{ x=1 },{ x < _wpnum },{ x = x + 1; }] do {
_wppos = [_xpos+(x*20),_ypos+(x*20),_wpradius];
_wp = _aiGroup addWaypoint [_wppos, _wpradius];
_wp setWaypointType "MOVE";
};
_wp = _aiGroup addWaypoint [[_xpos,_ypos,0], _wpradius];
_wp setWaypointType "CYCLE";

 

Now this obviously is not the whole script, it is just the parts that are important. I changed the name of the entity that he seeks for testing purposes, if I wear that skin he will then come after me.

 

Now here is the problem I am having, If I am in line of sight and within the parameters of _wpradius when the server restarts, then as soon as he spawns he will come right at me, however if I let him spawn and I'm outside of the _wpradius he will just proceed to the waypoints and that's it. If I get near him he will not come after me. Now I know this is happening because the script is only designed to run once, so basically he spawns, runs the code once, finds nothing and goes about his business and for the LIFE of me I cannot get a loop script to work.

 

So does anyone have a an old script laying around that makes AI search for a target and makes the AI run right up to the target once it is found?

 

I want this guy to be running to his way point, discover a target along the way, run up to the target, do his thing, and then proceed back on course to his way point while still actively checking for valid targets. Now keep in mind that when he does his thing, the target (which is the player) will have been moved outside of the parameters of _wpradius, so he could simply sleep 1; clear the target array, and then loop the script.

 

Anyone out there have anything like that or something close to that? Thanks!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

You have a loop:

 while {alive _unit && (_unit distance _target > 10)} do {
    _unit doMove getPos _target;
    sleep 3;
  };

 

This is running and running until the condition is true (and this unit is near the targer place).

 

Above the loop you check 1 time:

_theHunt = (position _aiunit) nearEntities ["Bandit2_DZ", _wpradius];

 

I guess you want to check if someone is in the radius so the unit follows him.

 

But you do not check this in the loop anymore. So when the unit is in the loop you can go nearer and nearer and you are not recognized.

 

I cannot explain it better, sorry ;)

Link to comment
Share on other sites

  • 0

You have a loop:

 while {alive _unit && (_unit distance _target > 10)} do {

    _unit doMove getPos _target;

    sleep 3;

  };

 

This is running and running until the condition is true (and this unit is near the targer place).

 

Above the loop you check 1 time:

_theHunt = (position _aiunit) nearEntities ["Bandit2_DZ", _wpradius];

 

I guess you want to check if someone is in the radius so the unit follows him.

 

But you do not check this in the loop anymore. So when the unit is in the loop you can go nearer and nearer and you are not recognized.

 

I cannot explain it better, sorry ;)

 

 

So you're suggesting that I loop the variable? 

 

Here is the script:

target = objNull;

if (true) then {

  // Init the target array.

  if (isNil "TargetArray") then {TargetArray = [];};

  // Start Hunting

  _theHunt = (position _aiunit) nearEntities ["Bandit2_DZ", _wpradius];

  _target = _theHunt call BIS_fnc_selectRandom;

  // make entity chase unit till its dead

  while {alive _aiunit && (_aiunit distance _target > 10)} do {

    _aiunit doMove getPos _target;

    sleep 1;

  };

 

So do you mean I should loop the check with something like this? Like: while (alive _aiunit) do { _aiunit call _theHunt };

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...