AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   find_ent_in_sphere problem (https://forums.alliedmods.net/showthread.php?t=47244)

SSJ2GOKU 11-13-2006 03:49

find_ent_in_sphere problem
 
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?

dutchmeat 11-13-2006 05:19

Re: find_ent_in_sphere problem
 
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()
}


SSJ2GOKU 11-13-2006 05:30

Re: find_ent_in_sphere problem
 
Quote:

Originally Posted by dutchmeat (Post 402852)
Something like this?:

Code:

  while((ent = find_ent_in_sphere(ent, pOrigin, Radius)) != 0)

ent should be ID i guess

dutchmeat 11-13-2006 05:37

Re: find_ent_in_sphere problem
 
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])
    }
  }


VEN 11-13-2006 07:22

Re: find_ent_in_sphere problem
 
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.

schnitzelmaker 11-13-2006 09:04

Re: find_ent_in_sphere problem
 
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.

SSJ2GOKU 11-14-2006 15:09

Re: find_ent_in_sphere problem
 
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

schnitzelmaker 11-14-2006 15:23

Re: find_ent_in_sphere problem
 
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     } }

dutchmeat 11-15-2006 04:49

Re: find_ent_in_sphere problem
 
I don't think that'll work, since the origin[0] always changes.

schnitzelmaker 11-15-2006 08:07

Re: find_ent_in_sphere problem
 
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.


All times are GMT -4. The time now is 06:57.

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