• How to split GetPos()?
    7 replies, posted
Hey guys, I'm wondering how to split the vector that you get with GetPos(). Example: [lua] pos = ply:GetPos() print( pos ) [/lua] Output: 2435435.55 2666 864444.1112 So I want to have the first value (It's the coordinate 'x', right?). I think it's an easy question for you because you are totaly awesome :D Thanks in advance! ^^
GetPos returns a vector object. You can get the components using its members: [lua]local pos = ply:GetPos(); local x = pos.x; local y = pos.y; local z = pos.z;[/lua] [url]http://wiki.garrysmod.com/?title=Vector[/url]
I didn't expect that an article for vectors exists. But thanks dude! :)
[QUOTE=pennerlord;29839662]I didn't expect that an article for vectors exists. But thanks dude! :)[/QUOTE] That's because you didn't search
[QUOTE=Nevec;29834747]GetPos returns a vector object. You can get the components using its members: [lua]local pos = ply:GetPos(); local x = pos.x; local y = pos.y; local z = pos.z;[/lua] [url]http://wiki.garrysmod.com/?title=Vector[/url][/QUOTE] [lua] local x, y, z = v:GetPos() [/lua]
[QUOTE=c-unitV2;29843816][lua] local x, y, z = v:GetPos() [/lua][/QUOTE] I'm pretty sure that assigns x, y, and z to the position. And King, no need to post that. He knows he didn't search, no need to point it out.
[QUOTE=thejjokerr;29850481]I'm pretty sure that will only assign the x with the vector of the position. And wakboarder, no need to post that. You don't know lua, so don't even try to point out someone else's mistakes.[/QUOTE] You're right, I thought that it would return each value sort of like getcolor [code] ] lua_run_cl local x, y, z = LocalPlayer():GetPos() print(x, y, z) 823.8480 -32.000 -143.0096 [highlight]nil nil[/highlight] ] lua_run_cl local r, g, b, a = LocalPlayer():GetColor() print(r, g, b, a) [highlight]255 255 255 255[/highlight][/code]
Sorry, you need to Log In to post a reply to this thread.