About Store Forum Documentation Contact



Post Reply 
ai attack again
Author Message
1991mirec Offline
Member

Post: #1
ai attack again
Hi

I am trying here for a while now it would be like 3 days or so and i can t seem to find solution even though i know it probably is something very easy.
So i want to do something like when NPC is so and so far away from player then attack him. i got the part
if(DIST(npc.pos,players.pos)<something)attack
that is easy but what if i want npc to attack anything that come so and so close to him. what if i want him to attack everything , every npc every player every moving living thing in the game that comes to him in certain distance. I probably have to change players.pos for something but i have no idea that for what or how.

thank you in advance.
mirec wink
09-01-2013 11:29 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #2
RE: ai attack again
Quote:what if i want npc to attack anything that come so and so close to him. what if i want him to attack everything , every npc every player every moving living thing in the game that comes to him in certain distance.

I'm not at my dev PC at the moment so I can't give you specifics in terms of actual EE functions but essentially you need to identify and maintain a list of entities you are interested within a given distance of your NPC.

Here are a few suggestions:

Typically many engines tend to offer a means to get this inherently by having a function that returns all objects within a given volume, you can then filter out the object types you are interested in. I don't know off the top of my head if Esenthel has this, or something similar, but I'd have thought so.

Failing that you could manually loop through your object containers and fail or pass objects based on their distance from the NPC, again constructing a list.

If you sort the list based on distance then you can attack the nearest one first.

For more realism you might want to use a line of sight restriction too so it doesn't look like you have eyes in the back of your head grin
09-02-2013 09:59 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #3
RE: ai attack again
(09-02-2013 09:59 AM)Pixel Perfect Wrote:  Typically many engines tend to offer a means to get this inherently by having a function that returns all objects within a given volume, you can then filter out the object types you are interested in. I don't know off the top of my head if Esenthel has this, or something similar, but I'd have thought so.

Yes, Esenthel has this. I did it like this:

Code:
// Get all the enemies around this turret
Memc<Obj*> chrsInRange;
Game.World.objGet(chrsInRange, Ball(m_FiringRange + m_AimingRange, pos()), OBJ_CHR);

// Trying not to use dynamic casting through-out the entire file, so creating an Enemy* container, and adding all the Obj* (cast to Enemy*) to it  
Memc<Enemy*> enemies;
REPA(chrsInRange)  enemies.add((Enemy*)chrsInRange[i]);

Do keep in mind that I can get away with dynamically casting (and preferably, I wouldn't do this C-style..) to Enemy*, because enemies are the only CHR's I have in my scene.
09-02-2013 01:31 PM
Find all posts by this user Quote this message in a reply
1991mirec Offline
Member

Post: #4
RE: ai attack again
thank you for your reply but still having some problems. probably didn t get it correctly.
ok i tryed something like this. please sorry for me being stupid but i am new here and at least i thought it works like this. but apparetly it doesnt->
Memc<Obj*> chrsInRange;
Game.World.objGet(chrsInRange, Ball(24, pos()), OBJ_CHR);
REPA(chrsInRange)WindowMsgBox("dd", "dd");
so shouldn t this give me one message box if i got close to npc??? i was just testing if it works.. but i am doing something wrong.
09-02-2013 10:42 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #5
RE: ai attack again
Yeah, it should work. Unless your NPC's are not of type OBJ_CHR? Check if you're using exactly that type.
09-03-2013 10:38 AM
Find all posts by this user Quote this message in a reply
1991mirec Offline
Member

Post: #6
RE: ai attack again
i am ... hmm weird.. have to do something wrong.. thank you anyway... i ll be messing with it... i ll let you know how it went.. thank u very much
09-03-2013 02:25 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #7
RE: ai attack again
If this is server side i doubt you will get away with the Game.World.objGet(); However if it is client sided the solution is correct and should work, if you are applying it to your type ofcourse. Also what about your first example? is it in a loop or just for one player elm?

Example on loop and player elm ->

for(Int i = 0; i < Players.elms(); ++i)if(Dist(Players[i].pos(), npc.pos()) < 1) Attack();


if(Dist(Players[0].pos(),npc.pos()) Attack();
(This post was last modified: 09-03-2013 03:34 PM by TBJokers.)
09-03-2013 03:33 PM
Visit this user's website Find all posts by this user Quote this message in a reply
1991mirec Offline
Member

Post: #8
RE: ai attack again
it is server sided... why it wouldn t work?? do you have other idea for me please??

and i have it second way,.. if(Dist(Players[0].pos(),npc.pos()) Attack();

well right now i have it like this. in server it check in loop for every player if he is closer then i want it and if yes then it send to client to attack player[0] but then it will attack in each client diferent player.. well player[0] as i wrote it.. before i had it to attack position which worked better for moving to same player in every client but i had some other problem not sure exactly what right now..
(This post was last modified: 09-05-2013 06:12 PM by 1991mirec.)
09-05-2013 06:06 PM
Find all posts by this user Quote this message in a reply
1991mirec Offline
Member

Post: #9
RE: ai attack again
anybody please??
09-07-2013 08:47 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #10
RE: ai attack again
It is really hard to tell how you should do it. The reason it is attacking all different is because Players[0] is usually the main Player. Whilst you have a neighbor array. smile
09-07-2013 09:13 PM
Visit this user's website Find all posts by this user Quote this message in a reply
1991mirec Offline
Member

Post: #11
RE: ai attack again
hey TBjokers ..nice to hear from you.. and thank you for respond.. that s what i figured players0 is main player for each client and i know that i have neighbor array but not sure how to use it.. should i use some if with for statement for example to check for all neigbor if they are in the needed distance and if they are then attack neighbor?? well ok but then how they are going to attack main player. player[0]. player[0] is not in neighbor array.. or is it? i don t think so but i might be wrong. I am kinda confused in this as you can see.. can you please put me straight?? i would appriciate if somebody can push me a little more so I will be able to do it..
thank you in advance
mirec wink
09-07-2013 10:10 PM
Find all posts by this user Quote this message in a reply
1991mirec Offline
Member

Post: #12
RE: ai attack again
please anybody could give me some hint??
09-11-2013 06:27 PM
Find all posts by this user Quote this message in a reply
Post Reply