Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,397 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How can I find the nearest enemy?! #270826
06/10/09 07:52
06/10/09 07:52
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
Hi there,

How can I find the nearest enemy to player...?!

I have several enemies around my player and I don't know how to find two of them which are nearest to player.

Can someone please tell me an example...?!


I don't care!
Re: How can I find the nearest enemy?! [Re: Mahdi] #270829
06/10/09 08:21
06/10/09 08:21
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
c_scan check the manual


3333333333
Re: How can I find the nearest enemy?! [Re: Quad] #270834
06/10/09 09:00
06/10/09 09:00
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
Yes I know what does c_scan and how it works, I just wanted to see an example of finding the two nearest enemies.


I don't care!
Re: How can I find the nearest enemy?! [Re: Quad] #270835
06/10/09 09:06
06/10/09 09:06
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
Well, this is what I'll do, most likely
Code:
ENTITY* target;

action enemy()
{
   my.skill80=1;//or set to anything you like
   ...
}

action detect_nearest_enemy()
{
   you=ent_next(NULL);
   target=you;
   while(you!=NULL)
   {
      if(your.skill==80)
      {
         if(vec_dist(you.x,my.x)<vec_dist(target.x,my.x))
         {
            target=you;
         }
      }
      you=ent_next(you);
   }
   ...
}


Careful, though, it's not tested yet...

Last edited by bart_the_13th; 06/10/09 09:08. Reason: those bloody indetation
Re: How can I find the nearest enemy?! [Re: bart_the_13th] #271103
06/11/09 09:57
06/11/09 09:57
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
Yes Thank you, That worked.

You did a great job... I didn't know there is something called (ent_next(NULL);).

At first it didn't work but then I discovered why (because I had another TARGET entity)...

Thanks.


I don't care!
Re: How can I find the nearest enemies?! [Re: bart_the_13th] #271991
06/15/09 23:45
06/15/09 23:45
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
this forum is pure gold, hehe
thanks for that code!


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1