Jump to content
Sign in to follow this  
Zombitch

Need advices on how to make an intelligent enemy.

Recommended Posts

Hello mates,

I need some advices about creating an intelligent enemy.

What I call an "intelligent enemy" is an enemy (AI) that can spot you AND look for you if you ran away (until you are far far away from the enemy ( > 200 m).

So here is what I've done :

1) Creating an enemy

2) Set some waypoints to the enemy (waypoints type are "move").

Now the enemy is moving waypoint to waypoint, when he sees me he attacks me, that's OK. But the thing is if I am hinding in a house that is 20m away from the enemy he will continue to go from waypoint to waypoint whereas I would like the enemy look for me (heading to the house and look for me).

Is this possible ? And if so, can you give me some tips to achieve this ?

Again thanks a lot for you appreciate help.

Edit : I have another question about enemy : Is it possible to make enemy live their life ? I mean can I put an enemy in the editor, and without setting waypoints this enemy will walk where ever he wants and will do what he wants ?

Share this post


Link to post
Share on other sites

You could spawn them with BIS_Fnc_TaskPatrol so they have randomly assigned waypoints, and set a loop running to check their knowledge of player positions.

Then if their knowsAbout of the player is over a certain threshold (like 1.5 or similar), you delete their waypoints and add a "seek and destroy" waypoint at the players position.

Edited by Das Attorney

Share this post


Link to post
Share on other sites

@Das Attorney

Looks pretty good and thanks for the links. But instead of making a loop is it possible to add an event handler something like :

enemyUnit addEventHandler [knowsAbout < 1.5 , {_this exec "searchAndDestroyPlayer.sqf"}];

Is this possible (to add a condition in a addEventHandler) ? And if so, it's better than using a loop ?

One other question :p , where to put the loop script ? In a game logic ?

Edit : Since I'm making a simple MP mission, can you tell me if the BIS_Fnc_TaskPatrol should be call by each client or only by the server ?

Edited by Zombitch
Adding questions

Share this post


Link to post
Share on other sites

You can name your enemy in the Editor like: searchDude

If you are familiar with .sqf scripts skip the spoiler.

create inside your mission folder a new .txt file and rename it as search.sqf

But make sure you have file extensions enabled on your system so it won’t be search.sqf.txt which will not work!

.sqf files are files that are readable by the RV engine and can be executed by the mission.

Create your search.sqf and insert this code:

while {alive searchDude} do {
waituntil {(lineIntersects [eyePos searchDude, getPos player, searchDude, player]) && (terrainIntersect [getPosATL searchDude, getPosATL player]) && (40 > player distance searchDude) && (1 == round (random 3))};  //waits until there is no object and no terrain betwen you and the searchDude distance maximum 40 m and a random value with 33% chance to be true
group searchDude setCombatMode "RED"; //will set the group of your searchDude on "engage at will"
sleep 1;
searchDude move getPos player; //if your ai is in a fire fight this needs some time to execute but that’s fine so he won’t run up to you while you are shooting at him
};

then create a init.sqf with the following code inside:

Handle = execVM "search.sqf";

For your "random walking behaviour" you can create 3 "MOVE" waypoints in the editor and the 4th as a "Cycle" and place it near your first waypoint so it will create a endless cycle. In each Waypoint you can change the Radius (0 by default) to, let’s say 80 m so the waypoint is somewhere in a radius of 80 m around your waypoint placed in the editor.

Try to create those 4 waypoints over the whole area that makes sense for your mission. (-80 m to make sure he won't be somewhere he shouldn't)

This is everything NOT TESTED as I’m at work.

So if you have problems send me a PM or ask here

Best Regards, Lappihuan

Edit: wooops there are some ninjas :D

For the Eventhandler, there is not such a Eventhandler: List of all EH

but yes EH's are much less Performance heavy than loops, so use loops with that in mind.

the Sleep command will stop the script for the value given to the sleep so you can use this to make loops less heavy.

my loop uses a waituntil so the loop won't run until the AI sees you.

btw Das Attorney's Solution is very good and simple so i would try that first and see if it fits your thoughts, mine is more complex and more adjustable so you could tweak some behaviour.

Edited by Lappihuan

Share this post


Link to post
Share on other sites

@Lappihuan

Thanks for your answer. I will try Das Attorney solution first, doing something like this :

while(enemyUnit knowsAbout Player1 < 1.5) do
{
   enemyUnit addWayPoint [Player1 getPos, 20];
}

But I'm at work at the moment, so I can't test it right now.

Moreover I would like my mission available for multiplayer, do I have to write something specially to make it available for multiplayer ? I mean should I run the BIS_Fnc_TaskPatrol on the server only or on all clients ?

(I'm not very comfortable on how do things to make a mission available in multiplayer mode)

Thanks.

Share this post


Link to post
Share on other sites

Basically all Units placed in the Editor are Server side.

So the BIS_Fnc_TaskPatrol needs to be Server side too.

(i know locality is confusing in the beginnings but you will get used to by try end error, also there are some nice explanations out there)

btw. you have a syntax error:

while(enemyUnit knowsAbout Player1 < 1.5) do
{
   enemyUnit addWayPoint [getPos Player1, 20];
}

getPos and Player1 was incorrect ;)

And if you try my suggestion, PM me i will overwork it, because its only SP compatible (by using player which is a predefined variable for the player that is executing the script... locality ;) )

Share this post


Link to post
Share on other sites

Just use 1 Waypoint. Super simple. Very very effective. No scripting.

Set it right in front of the Unit and set to DISMISSED, NORMAL, SAFE.

Random Patrols until you are spotted, then they will hunt you as long

as they 'feel' they are the aggressor and know the general area you

went to while fleeing or spotted again. Works great. Very organic. :cool:

Share this post


Link to post
Share on other sites
Just use 1 Waypoint. Super simple. Very very effective. No scripting.

Set it right in front of the Unit and set to DISMISSED, NORMAL, SAFE.

Random Patrols until you are spotted, then they will hunt you as long

as they 'feel' they are the aggressor and know the general area you

went to while fleeing or spotted again. Works great. Very organic. :cool:

Looks like pretty easy :p but I 've done this and when the unit arrives to the waypoint he just stops (still standing, or sit and dont move anymore). Any idea ?

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  

×