• Return current held toolmode
    11 replies, posted
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: [URL]http://i.imgur.com/0aKAkek.jpg[/URL] Thanks in advance
CanTool is called when the tool is changed, so you can just set a variable once it's called.
[QUOTE=-Flapadar;39412446]CanTool is called when the tool is changed, so you can just set a variable once it's called.[/QUOTE] 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.
[QUOTE=Science;39414929][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.[/QUOTE] 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?
[QUOTE=TheDivinity;39415092]Check the ConVar gmod_toolmode, and make sure the tool gun is actually out?[/QUOTE] Someone who actually made an answer that helped me out! Thanks! Its all working perfect now! :D
[QUOTE=glitchdetect;39415130]Someone who actually made an answer that helped me out![/QUOTE] 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] [QUOTE=glitchdetect;39415027]how do you return a specific field from it?[/QUOTE] table.index e.g. LocalPlayer():GetTool().mode
[QUOTE=-Flapadar;39417995]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[/QUOTE] 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.
[QUOTE=find me;39418090]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.[/QUOTE] 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.
[QUOTE=-Flapadar;39418820]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. [/QUOTE] 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: [CODE]GetConVarString( "gmod_toolmode" )[/CODE]
Sorry, you need to Log In to post a reply to this thread.