Hey guys!
Yesterday I started working on an addon for Garry’s Mod that would allow players to spawn small props that they can track and teleport to (e.g. to find creations on a large map when some weird guy killed them!).
This is what I came up with:
addons\prop finder\lua\autorun\client.lua
DropFinder = {}
DropFinder.debugger = false
DropFinder.props = {}
local rehook = nil
local function DrawPropHints()
draw.SimpleText(#DropFinder.props, "ScoreboardText", 25, 25, Color(86, 104, 86, 255), 0, 0)
for i = 1, #DropFinder.props do
local pos = DropFinder.props*:getPos():ToScreen()
surface.DrawRect( pos.x - 16, pos.y - 16, 16, 16 )
end
end
-- HUD
local function dropfinderHUD()
DrawPropHints()
end
rehook = function()
hook.Add("HUDPaint", "DropFinder.HUD", dropfinderHUD)
end
rehook()
addons\prop finder\lua\weapons\gmod_tool\stools\dropfinder.lua
TOOL.Category = "Prop Finder"
TOOL.Name = "Drop Finder prop"
TOOL.Command = nil
TOOL.ConfigName = ""
-- tool functions
function TOOL:LeftClick( trace )
prop = ents.Create("prop_physics")
prop:SetModel("models/hunter/blocks/cube025x025x025.mdl")
prop:SetPos(trace.HitPos + (trace.HitNormal*16) )
prop:SetAngles(trace.HitNormal:Angle())
prop:Spawn()
table.insert(DropFinder.props, prop)
return true
end
function TOOL:RightClick( trace )
end
-- tool control panel
function TOOL.BuildCPanel(panel)
panel:AddControl("Header", { Text = "Example TOOL", Description = "Just an little example" })
end
The idea was to create a table that would store a list of all props that were spawned. For debugging, I displayed the number of table items in the HUD, but I get errors all over the time.
When I started experimenting, the script added items to the table (and they were printed; but not in the HUD but when I called DrawPropHints via TOOL:RightClick.
Can you help me set up how I can get the table in the HUD?
And if you see some weird errors I made I would be glad if you could explain me what I’ve done wrong. I want to understand what is going on here; not just copy&paste.
I hope you can help me.
So long,
…eiszfuchs