Raised This Month: $51 Target: $400
 12% 

find_ent_in_sphere problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SSJ2GOKU
Senior Member
Join Date: Oct 2005
Location: Belgium
Old 11-13-2006 , 03:49   find_ent_in_sphere problem
Reply With Quote #1

hello,

i'm searching a piece of code that returns an array of player indexes in a certain radius around a player

i know find_ent_in_sphere should be capable of doing that, but can anyone give me an example ?

the player "id" is the start entity, so the search should start around him and it would have to return an array of players in a radius of 100


or should i use a traceline around the player's body to find the closest player-entity?

Last edited by SSJ2GOKU; 11-13-2006 at 04:01.
SSJ2GOKU is offline
Send a message via MSN to SSJ2GOKU
dutchmeat
Senior Member
Join Date: Sep 2006
Old 11-13-2006 , 05:19   Re: find_ent_in_sphere problem
Reply With Quote #2

Something like this?:

Code:
public test(id){
   new Float:vOrigin[3]; //get my origin
   entity_get_vector( id, EV_VEC_origin, vOrigin ); 
   new Radius = 100.0
  while((ent = find_ent_in_sphere(id, vOrigin, Radius)) != 0)
    {
        if(!is_user_alive(ent) || ent == id)
        {
            return 0
        }
        else
        {
 
            //Do the stuff if a player was found
            explosion(ent)     // create an explosion on each found entity.
        }
    }
}
public explosion (id){ 
   new startloc[3] 
   get_user_origin(id,startloc)
   message_begin( MSG_ALL, get_user_msgid("Explosion"), {0,0,0} ,id); 
   write_coord(startloc[0])
   write_coord(startloc[1])
   write_coord(startloc[2]) 
   write_long(500) 
   write_byte(5) 
   message_end() 
}

Last edited by dutchmeat; 11-13-2006 at 05:30.
dutchmeat is offline
SSJ2GOKU
Senior Member
Join Date: Oct 2005
Location: Belgium
Old 11-13-2006 , 05:30   Re: find_ent_in_sphere problem
Reply With Quote #3

Quote:
Originally Posted by dutchmeat View Post
Something like this?:

Code:
  while((ent = find_ent_in_sphere(ent, pOrigin, Radius)) != 0)
ent should be ID i guess
SSJ2GOKU is offline
Send a message via MSN to SSJ2GOKU
dutchmeat
Senior Member
Join Date: Sep 2006
Old 11-13-2006 , 05:37   Re: find_ent_in_sphere problem
Reply With Quote #4

hehe right, too quick with posting

You can also use this:

Code:
 
  new OriginA[3]
  new OriginB[3]
  new players[32], inum
  new Radius = 100.0
  for(new i = 0 ;i < inum; ++i)
  {
    get_user_origin(players[i],OriginB)
    if(get_distance(OriginA,OriginB) < Radius && players[i]!=id)
    {
     explosion(players[i])
    }
  }

Last edited by dutchmeat; 11-13-2006 at 05:57.
dutchmeat is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 11-13-2006 , 07:22   Re: find_ent_in_sphere problem
Reply With Quote #5

Quote:
or should i use a traceline around the player's body to find the closest player-entity?
You would need a traceline only if you want to detect a "visible" players. If visiblity doesn't matter you can just check the players' distance or just use find_ent_in_sphere.

Last edited by VEN; 11-13-2006 at 07:25.
VEN is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 11-13-2006 , 09:04   Re: find_ent_in_sphere problem
Reply With Quote #6

Here without origin,but it need engine module
This set every player who is in radius in the array to 1,and the rest to 0
Code:
new maxplayers = get_maxplayers() new players[32] new Float:Radius = 100.0 for(new i = 1 ;i < maxplayers ; ++i) {        if(entity_range(id,i) < Radius && players[i]!=id && is_user_connected(i))           players[i] = 1        else players[i] = 0 }

or with "get_entity_distance(ent1, ent2)" that return a non float value,but is the same.
__________________

Last edited by schnitzelmaker; 11-13-2006 at 09:15.
schnitzelmaker is offline
SSJ2GOKU
Senior Member
Join Date: Oct 2005
Location: Belgium
Old 11-14-2006 , 15:09   Re: find_ent_in_sphere problem
Reply With Quote #7

and what i have to change if they have to be on the left or right side from me ?

so practically close to the same x axis
SSJ2GOKU is offline
Send a message via MSN to SSJ2GOKU
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 11-14-2006 , 15:23   Re: find_ent_in_sphere problem
Reply With Quote #8

for this you need the player origin
Code:
new OriginA[3] // [0]=x,[1]=y,[2]=z new OriginB[3] new players[33] new maxplayers = get_maxplayers() new Float:Radius = 100.0 new FLoat:MaxXdifference = 10.0 //this is how big can be the difference in "x" // as example your origin is 350.0,so the playerorigin can be 350.0 +/-10.0 get_user_origin(id,OriginA) for(new i = 1 ;i < maxplayers ; ++i) {     get_user_origin(i,OriginB)     if(get_distance(OriginA,OriginB) < Radius && i != id && is_user_connected(i))     {       //i use a second if to explain,but it can also used both in 1 if       if (OriginB[0] <= (OriginA[0]+MaxXdifference) && OriginB[0] >= (OriginA[0]-MaxXdifference))           players[i] = 1       else players[i] = 0     } }
__________________

Last edited by schnitzelmaker; 11-14-2006 at 15:31.
schnitzelmaker is offline
dutchmeat
Senior Member
Join Date: Sep 2006
Old 11-15-2006 , 04:49   Re: find_ent_in_sphere problem
Reply With Quote #9

I don't think that'll work, since the origin[0] always changes.
dutchmeat is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 11-15-2006 , 08:07   Re: find_ent_in_sphere problem
Reply With Quote #10

Quote:
I don't think that'll work, since the origin[0] always changes.
??? origin is not an fix number,its dynamic.

with get_user_origin(id,OriginA) it get own origin.
with get_user_origin(i,OriginB) it get the playerorigin

And the example was only for 1 time for 1 second,its not the fully plugin.
__________________
schnitzelmaker is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode