Return current held toolmode

Solved
[HR][/HR]
I am trying to make a custom HUD that shows the name of the current tool held,
but I am not able to figure out the way to return the name outside the “CanTool” hook.

Anyone might know a way to return a string containing the current held tool in the client?

Image:

Thanks in advance

CanTool is called when the tool is changed, so you can just set a variable once it’s called.

As far as I can see, CanTool is only called when attempting to use the tool, not at the time it is deployed.

I figured out that LocalPlayer():GetTool() returns a table,
where to get out the toolname part, I have no idea.

[lua]] lua_run_cl PrintTable(LocalPlayer():GetTool())
Owner = Player [1][Aperture Science]
Weapon = Weapon [79][gmod_tool]
SWEP = Weapon [79][gmod_tool]
LastMessage = 0
Category = Render
Message = start
ClientConVar:
locked = 0
key = 0
toggle = 1
ServerConVar:
AllowedCVar = 0
Name = #tool.camera.name
RightClick = function: 0x2c0abd08
LeftClick = function: 0x2bf61258
Stage = 0
Mode = camera
Objects:
[/lua]

Thats all that is returned.
Your gonna have to find a new method to getting it.

I see the “Mode” field in there.
As I am a complete idiot when it comes to Tables, how do you return a specific field from it?
(Yes i’ve checked the wiki, and I am still at this level)

Check the ConVar gmod_toolmode, and make sure the tool gun is actually out?

Someone who actually made an answer that helped me out!
Thanks!

Its all working perfect now! :smiley:

My answer would have worked too; just you’d need to check they had permission to use the tool (ie call cantool hook)

[editline]30th January 2013[/editline]

table.index

e.g. LocalPlayer():GetTool().mode

Yea but that table gets the tool mode from the cvar itself, so it would be dumb not to use the cvar. Your way will work, it’s just the ghetto way to do it.

I wasn’t meaning the table - I was meaning hook to CanTool and check if they have permission to use that tool. That way you know what tool they’re using before they actually use it and you don’t need to constantly check the convar.

You could add a callback on the convar tho - probably the best way to do it.

I repeat: OnTool is not executed before you either: Reload it, Left click it or Right click it.
Anyways, the script has been done.
Also: This is as stated, a clientside script that just shows the current tool in the HUD.

Using this:


GetConVarString( "gmod_toolmode" )