replace that with local LocalPos = ply:GetPos()?
[editline]2nd October 2016[/editline]
[CODE]
[ERROR] lua/find_test.lua:7: bad argument #1 to 'FindInSphere' (Vector expected, got string)
[/CODE]
egh
[QUOTE=darpeyface;51142069]replace that with local LocalPos = ply:GetPos()?
[editline]2nd October 2016[/editline]
[CODE]
[ERROR] lua/find_test.lua:7: bad argument #1 to 'FindInSphere' (Vector expected, got string)
[/CODE]
egh[/QUOTE]
Was referring to your last one.
For the first one, just use PrintTable instead of print
[QUOTE=Skere_;51142076]Was referring to your last one.
For the first one, just use PrintTable instead of print[/QUOTE]
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 [CODE]local ply = LocalPlayer()
local LocalPos = tostring( ply:GetPos().x .. ply:GetPos().y .. ply:GetPos().z )
print (ents.FindInSphere(LocalPos,500))[/CODE]
[editline]2nd October 2016[/editline]
[QUOTE=whitestar;51142082]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.[/QUOTE]
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.
[QUOTE=darpeyface;51142083]heres the current code [CODE]local ply = LocalPlayer()
local LocalPos = tostring( ply:GetPos().x .. ply:GetPos().y .. ply:GetPos().z )
print (ents.FindInSphere(LocalPos,500))[/CODE]
[editline]2nd October 2016[/editline]
it returned random numbers and letters, every time i ran it, diffrent numbers and letters came up.[/QUOTE]
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
[QUOTE=Skere_;51142091]Jeez at least read what I said
For your first 'problem', replace print with PrintTable if you want to print everything it contains
local ply = LocalPlayer()local LocalPos = ply:GetPos()PrintTable(ents.FindInSphere(LocalPos,500))
The random numbers/letters is the table id[/QUOTE]
aaah ok i see
same error [CODE][ERROR] lua/find_test.lua:5: bad argument #1 to 'FindInSphere' (Vector expected, got string)
[/CODE]
[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
[QUOTE=darpeyface;51142147]now...onto trying to figure out how to tell whats in the table is a player...
ahem[/QUOTE]
[code]for _, v in ipairs( ents.FindInSphere( args )) do
if ( v:IsPlayer() ) then
-- code
end
end[/code]
Or if you prefer numeric for
[code]local tEnts = ents.FindInSphere( args )
for i = 1, #tEnts do
local pEntity = tEnts[i]
if ( pEntity:IsPlayer() ) then
-- code
end
end[/code]
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
[QUOTE=gonzalolog;51143932]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[/QUOTE]
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!
[QUOTE=mayomanmaster;51146537]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![/QUOTE]
You cant google: "GMOD LUA TABLE PRINT"?
what are you on about?
[QUOTE=mayomanmaster;51146537]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![/QUOTE]
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
[QUOTE=gonzalolog;51146915]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[/QUOTE]
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
[QUOTE=gonzalolog;51147115]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[/QUOTE]
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 [url=https://facepunch.com/showthread.php?t=1508566]thread[/url].
[QUOTE=NeatNit;51147179]You should try a lot harder before asking for help, but when it's time to ask, use the goddamn [url=https://facepunch.com/showthread.php?t=1508566]thread[/url].[/QUOTE]
at least you can reply without being a cock, sure ill use it
[highlight](User was banned for this post ("Threadshitting" - Bradyns))[/highlight]
[QUOTE=darpeyface;51147928]at least you can reply without being a cock, sure ill use it[/QUOTE]
Well if you expect people to not act up as a cock with you you should do the same and not act up as a cock with people that are trying to help. They are trying to help you and they are saying that because we dont want fucking fill up the forum with this little questions that dont need a fucking thread. Thats why that megathread name is: Problems that dont need their OWN thread.
[QUOTE=geferon;51150196]Well if you expect people to not act up as a cock with you you should do the same and not act up as a cock with people that are trying to help. They are trying to help you and they are saying that because we dont want fucking fill up the forum with this little questions that dont need a fucking thread. Thats why that megathread name is: Problems that dont need their OWN thread.[/QUOTE]
when was i a cock first? and im trying the problems that dont need their own thread
I was a bit grumpy but I wasn't "a cock", if you think that post was unfriendly you should stay around this forum for a while.
I know you fixed the error, but it's also important to understand what the error is saying, so in the future you can translate and understand what errors are telling you.
[code][ERROR] lua/find_test.lua:5: bad argument #1 to 'FindInSphere' (Vector expected, got string)[/code]
It's saying that FindInSphere couldn't run because you gave the first argument a string not a vector, as mentioned in GMod wiki:
[code] ents.FindInSphere( Vector origin, number radius ) [/code]
The first argument needs to be a vector and the second is the radius. The error is literally telling you what the problem is, see how it says: (Vector expected, got string). So you see the error is pretty simple, it's not hard to read either especially when it's telling you exactly what is wrong with it.
Also use PrintTable not print when things that are tables. I hope this helped but remember if you want to learn, you need to try it yourself. You need to find solutions and try to read the error yourself, because if you just constantly ask for help and not come up with a solution yourself, how are you going to learn?
[QUOTE=vrej;51153610]I know you fixed the error, but it's also important to understand what the error is saying, so in the future you can translate and understand what errors are telling you.
[code][ERROR] lua/find_test.lua:5: bad argument #1 to 'FindInSphere' (Vector expected, got string)[/code]
It's saying that FindInSphere couldn't run because you gave the first argument a string not a vector, as mentioned in GMod wiki:
[code] ents.FindInSphere( Vector origin, number radius ) [/code]
The first argument needs to be a vector and the second is the radius. The error is literally telling you what the problem is, see how it says: (Vector expected, got string). So you see the error is pretty simple, it's not hard to read either especially when it's telling you exactly what is wrong with it.
Also use PrintTable not print when things that are tables. I hope this helped but remember if you want to learn, you need to try it yourself. You need to find solutions and try to read the error yourself, because if you just constantly ask for help and not come up with a solution yourself, how are you going to learn?[/QUOTE]
the problem was that i didnt know how to turn a string to a vector
[QUOTE=darpeyface;51153658]the problem was that i didnt know how to turn a string to a vector[/QUOTE]
ply:GetPos() Should be a vector though, it's suppose to return the current position that the player is currently at in the map.
[QUOTE=darpeyface;51153658]the problem was that i didnt know how to turn a string to a vector[/QUOTE]
no, the problem was that the first reply to this thread was wrong but you didn't even try to understand what it was doing.
[QUOTE=NeatNit;51154728]no, the problem was that the first reply to this thread was wrong but you didn't even try to understand what it was doing.[/QUOTE]
It was a solution to his 4th edit, and it worked fine.
[lua]
lua_run_cl RunConsoleCommand( "Say", tostring( LocalPlayer():GetPos().x .. " " .. LocalPlayer():GetPos().y .. " " .. LocalPlayer():GetPos().z ) )
[/lua]
[quote]
[Cv] Skere: 913.02709960938 314.71475219727 -143.96875
[/quote]
Oh, I see. That wasn't clear before.
By the way tostring(some_vector) works just fine ;)
[editline]5th October 2016[/editline]
And also you're concatenating strings so you don't need to tostring() them (in your post above)
Sorry, you need to Log In to post a reply to this thread.