• Halp?
    9 replies, posted
[lua] point = {} function pointseta(ply) local b = ply:GetPos() point[x][y][z] = b.x, b.y, b.z end concommand.Add("setpoint_a", pointseta) [/lua] Right now I'm wanting to set point A to the point table, and further on my idea is to draw a line between point a and b, I just need a little jump to get started, I have no idea what im doing here.
[QUOTE=Raven-Rave;22834344][lua] point = {} function pointseta(ply) local b = ply:GetPos() point[x][y][z] = b.x, b.y, b.z end concommand.Add("setpoint_a", pointseta) [/lua] Right now I'm wanting to set point A to the point table, and further on my idea is to draw a line between point a and b, I just need a little jump to get started, I have no idea what im doing here.[/QUOTE] You're looking for this [url]http://wiki.garrysmod.com/?title=Surface.DrawLine[/url].
Your error is that you are trying to make the field z of the non-existant index y of th non-existant index x of the table point to be able to all 3 of these values. So 2 different kinds of errors coming from a mittle misunderstanding. :smile: If I were you I would store the position vector as itself. So : [lua]local point = {} local function pointseta(ply) table.insert(point, ply:GetPos()) end concommand.Add("setpoint_a", pointseta) [/lua] [b][url=wiki.garrysmod.com/?title=table.insert]table.insert [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] And since you saved a vector you can use [b][url=wiki.garrysmod.com/?title=Vector.ToScreen]Vector.ToScreen [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] to get screen positions for drawing.
Another question, how would I retrieve the X and Y values from the table?
point[1].x point[1].y [editline]10:20AM[/editline] Assuming you went with Quebec's method
[QUOTE=Crazy Quebec;22836370]Your error is that you are trying to make the field z of the non-existant index y of th non-existant index x of the table point to be able to all 3 of these values. So 2 different kinds of errors coming from a mittle misunderstanding. :smile: If I were you I would store the position vector as itself. So : [lua]local point = {} local function pointseta(ply) table.insert(point, ply:GetPos()) end concommand.Add("setpoint_a", pointseta) [/lua] [b][url=wiki.garrysmod.com/?title=table.insert]table.insert [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] And since you saved a vector you can use [b][url=wiki.garrysmod.com/?title=Vector.ToScreen]Vector.ToScreen [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] to get screen positions for drawing.[/QUOTE] Mittle? :downs:
I see, thank you all for helping. Very helpful to me you guys are Also I am wondering how this is to be fixed, I guessing I have to make a clientside file for this function? [code]] setpoint_drawline lua\autorun\server\point.lua:35: attempt to index global 'surface' (a nil value)[/code]
Okay I am not sure if I am doing this right but nothing is happening, heres my code atm. serverside point.lua [lua] AddCSLuaFile("autorun/client/cl_point.lua") local on = false point = {} local debug = 1 local function setpoint_a(ply) table.insert(point, 1, ply:GetPos()) if debug != 0 then for k, v in pairs(point) do print(k, v) end end end local function setpoint_b(ply) table.insert(point, 2, ply:GetPos()) if debug != 0 then for k, v in pairs(point) do print(k, v) end end end local function setpoint_cleartable() table.Empty(point) end local function setpoint_draw() timer.Simple(1, function(ply) umsg.Start("DrawLine", ply) umsg.Bool(true) umsg.End() end, ply) end concommand.Add("setpoint_a", setpoint_a) concommand.Add("setpoint_b", setpoint_b) concommand.Add("setpoint_draw", setpoint_draw) concommand.Add("setpoint_clear", setpoint_cleartable) [/lua] clientside cl_point.lua [lua] include("autorun/server/point.lua") hook.Add("HUDPaint", "line", function() if on then surface.DrawLine(point[1].x, point[1].y, point[2].x, point[2].y) else //print("its not on") end end) usermessage.Hook("DrawLine", function(um) on = um:ReadBool() end) [/lua] No errors, just nothing shows up.
Sorry, you need to Log In to post a reply to this thread.