• Find in sphere
    6 replies, posted
How do i check if a player entity is in a radius using the [url]https://wiki.garrysmod.com/page/ents/FindInSphere[/url] and then i run a function if there is a player in that radius
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/HasValue]table.HasValue[/url]
[QUOTE=LUModder;50095983][IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/table/HasValue"]table.HasValue[/URL][/QUOTE] I think he just wants to find out if there is a player in general, not a particular player. For loop through the ents in sphere, check each class to see if they are a player. If you're running a function on a player, call it directly. Otherwise call your function and break from the for loop Example: [code] for _,ent in pairs( ents.FindInSphere( ... ) ) do if ent:IsPlayer() then RUN FUNCTION break end end [/code]
[QUOTE=solid_jake;50096102]I think he just wants to find out if there is a player in general, not a particular player. For loop through the ents in sphere, check each class to see if they are a player. If you're running a function on a player, call it directly. Otherwise call your function and break from the for loop Example: [code] for _,ent in pairs( ents.FindInSphere( ... ) ) do if ent:IsPlayer() then RUN FUNCTION break end end [/code][/QUOTE] That's a horrible example. What you should do is use player.GetAll() and do distance checks against each player, it is way more efficient than looping through every entity on the server and doing shit afterwards.
[QUOTE=Robotboy655;50096176]That's a horrible example. What you should do is use player.GetAll() and do distance checks against each player, it is way more efficient than looping through every entity on the server and doing shit afterwards.[/QUOTE] He wants to use FindInSphere though :cry:
[QUOTE=solid_jake;50096322]He wants to use FindInSphere though :cry:[/QUOTE] And how does this prevent you from suggesting a better way of doing things?
[QUOTE=solid_jake;50096102]I think he just wants to find out if there is a player in general, not a particular player. For loop through the ents in sphere, check each class to see if they are a player. If you're running a function on a player, call it directly. Otherwise call your function and break from the for loop Example: [code] for _,ent in pairs( ents.FindInSphere( ... ) ) do if ent:IsPlayer() then RUN FUNCTION break end end [/code][/QUOTE] Thank you! [editline]9th April 2016[/editline] [QUOTE=Robotboy655;50096176]That's a horrible example. What you should do is use player.GetAll() and do distance checks against each player, it is way more efficient than looping through every entity on the server and doing shit afterwards.[/QUOTE] Hey man if it does anything to the performance of server, / fps / ping i would love if you could give me an example using player.GetAll()? Thanks!
Sorry, you need to Log In to post a reply to this thread.