FindInSphere, GetPos. why.


local ply = LocalPlayer()

local LocalPos = ply:GetPos()


print (ents.FindInSphere(LocalPos,500))

returns a random table, something like this:


] lua_openscript_cl find_test.luaRunning script find_test.lua...
table: 0x362f0ad0
] lua_openscript_cl find_test.lua
Running script find_test.lua...
table: 0x36113548




yeah, no errors either.

[editline]2nd October 2016[/editline]


local ply = LocalPlayer()

local LocalPos = ply:GetPos()

print (LocalPos)

this works 385.750458 375.982758 335.741608

[editline]2nd October 2016[/editline]


local ply = LocalPlayer()

local LocalPos = ply:GetPos()

RunConsoleCommand("say",(LocalPos))

but this doesnt…nothing is said…

Try this:
[lua]
local LocalPos = tostring( ply:GetPos().x … " " … ply:GetPos().y … " " … ply:GetPos().z )
[/lua]

replace that with local LocalPos = ply:GetPos()?

[editline]2nd October 2016[/editline]



[ERROR] lua/find_test.lua:7: bad argument #1 to 'FindInSphere' (Vector expected, got string)


egh

Was referring to your last one.

For the first one, just use PrintTable instead of print

wait wot, last one, first one? last, first line?

So you simply want to find entities wich are around a player within a 500 units radius? Then the first code you showed us was right already, the returned table contains ‘all’ (or none) entitys.

heres the current code


local ply = LocalPlayer()

local LocalPos = tostring( ply:GetPos().x .. ply:GetPos().y .. ply:GetPos().z  )

print (ents.FindInSphere(LocalPos,500))

[editline]2nd October 2016[/editline]

it returned random numbers and letters, every time i ran it, diffrent numbers and letters came up, even if no entities had been created. i didnt even move.

Jeez at least read what I said

For your first ‘problem’, replace print with PrintTable if you want to print everything it contains
[lua]
local ply = LocalPlayer()

local LocalPos = ply:GetPos()

PrintTable(ents.FindInSphere(LocalPos,500))
[/lua]

The random numbers/letters is the table id

aaah ok i see

same error


[ERROR] lua/find_test.lua:5: bad argument #1 to 'FindInSphere' (Vector expected, got string)



[editline]2nd October 2016[/editline]

er not, it just fixed itself. thanks!

Just to note; printing a table or metatable/userdata with no __tostring will print the memory location of the table. It’s just the default printing behaviour; PrintTable will loop through a table to print all of the elements.

now…onto trying to figure out how to tell whats in the table is a player…

ahem


for _, v in ipairs( ents.FindInSphere( args )) do
   if ( v:IsPlayer() ) then
      -- code
   end
end

Or if you prefer numeric for


local tEnts = ents.FindInSphere( args )

for i = 1, #tEnts do
   local pEntity  = tEnts*
   
   if ( pEntity:IsPlayer() ) then
      -- code
   end
end

Oh my god, this guy is trying to get spoonfeed everytime he doesn’t understand something, why are you guys still spooning feed him, he will never learn

in any other programming language it’s pretty easy to google any problem for a solution. Lua is an exception and this board is the one place people are willing to help people who want to learn more. Don’t be a hindrance to the progression of coders in this world. We need as many of them as we can get!

You cant google: “GMOD LUA TABLE PRINT”?
what are you on about?

Lua it’s easier as fuck, if there’s a problem…It basically tells you how to fix it in the same error, this guy it’s not even trying
I know it, i’ve learned lua and tried to learn by myself, but this guy keep asking and keep asking without even saying thanks or showing a sign he’s still alive and reading it, that’s why i’m rekt

you dont even know if i tried, did you ask if i tried, did you ever think that maybe im new and i dont know how to do it, maybe its better to ask than just sit there for an hour and try random things

and why are you so concerned if i am getting spoon fed, thats how im starting out, if you dont like that, well, that fuckin sucks. i mean, i try to do it for 10-20 minutes, if nothing comes of it i ask for help. i know, its a little odd for you, but i ask for help when i need it

like in his code, he put it in a loop. i never thought it would need a loop, now that i have an example of it i can see i need one. you know why i never would have thought that? because im new. im sorry i didnt start doing glua and i was a fucking coding god such as yourself, but thats how i started, not knowing anything. atleast im trying to learn, and if i cant learn it, i ask for help. isnt that why developer discussion is here? for random, dumb questions to be answered? yeah some people ask questions that arent like that but i will, not against the rules.

I’m not a good, i’ve been learning lua from 2011 where you had to restart map to load files
Learn lua from start, you are printing a table, and if you have this error:

[lua][ERROR] lua/find_test.lua:5: bad argument #1 to ‘FindInSphere’ (Vector expected, got string)[/lua]

And you still don’t understand what’s going on, learn lua

thats exactly what im doing here, why do you think im trying to get help so i can learn

You should try a lot harder before asking for help, but when it’s time to ask, use the goddamn thread.