HUD may not access table of spawned props?

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 )

-- HUD
local function dropfinderHUD()

rehook = function()
	hook.Add("HUDPaint", "DropFinder.HUD", dropfinderHUD)


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:SetPos(trace.HitPos + (trace.HitNormal*16) )

	table.insert(DropFinder.props, prop)

	return true

function TOOL:RightClick( trace )

-- tool control panel
function TOOL.BuildCPanel(panel)
	panel:AddControl("Header", { Text = "Example TOOL", Description = "Just an little example" })

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. :wink:

I hope you can help me.

So long,

Ooookay … would you be so kind then to help me getting at least a list of spawned props to work that I can work with in my HUD? It would really help me.

I’m not sure whether I mix up server-side and client-side … basically, this tool should work on client’s side. A client should be able to spawn small props and relocate them via HUD. (Later, you could propably teleport to them, making it easy to find your stuff on huge maps when some weird guy killed you or you died by accident.)

Pretty please? :slight_smile:

Guys, this problem drives me mad!
I can’t even declare a global integer (that later has to be a table!) that I could display in my HUD and is increased by clicking with the left mouse button.

Could you please help me setting up a storage where I can push my variables into?

Use usermessages. You’re trying to read data from a clientside table serverside.

Use something like this in the tool and HUD.

SendUserMessage(“ToolEntSend”, self.Owner, prop)

function ToolEntSend( um )
local prop = um:ReadEntity()
table.insert(DropFinder.props, prop)
usermessage.Hook(“ToolEntSend”, ToolEntSend)

Thanks, jonney934 & GranPC. I’ll try it next time I’m able to play gmod. :3
Will keep you updated.


It works! Well… I can store prop entities in my table, but I cannot work with them. Console says:

Hook 'PropFinder.HUD' Failed: addons\prop finder\lua\autorun\client.lua:21: attempt to call method 'getPos' (a nil value)

Then I try to debug it:

] lua_run_cl print(PropFinder.props[1])
Entity [33][prop_physics]
] lua_run_cl print(PropFinder.props[1]:getPos())
:1: attempt to call method 'getPos' (a nil value)

Why can’t I call methods? :confused:



Lua is case sensitive:wink:

Damn it. Thanks. :smiley: Now it works fine.
Meh, now I can start with some real scripts…