Skip to content

Commit

Permalink
Properly fix the tool switch insanity
Browse files Browse the repository at this point in the history
How did I not think of this in the first place
  • Loading branch information
robotboy655 committed Mar 16, 2015
1 parent 7406f7f commit 63ed131
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
local gmod_drawhelp = CreateClientConVar( "gmod_drawhelp", "1", true, false )
local gmod_toolmode = CreateClientConVar( "gmod_toolmode", "rope", true, true )

// HACK: We need a better way to do this
local LastSwitchTime = 0
cvars.AddChangeCallback( "gmod_toolmode", function( name, old, new )
if ( old == new || LastSwitchTime + .1 > CurTime() ) then return end
LastSwitchTime = CurTime()
spawnmenu.ActivateTool( new )
if ( old == new ) then return end
spawnmenu.ActivateTool( new, true )
end, "gmod_toolmode_panel" )

include( "shared.lua" )
Expand Down
4 changes: 2 additions & 2 deletions garrysmod/lua/includes/modules/spawnmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function ActivateToolPanel( id, cp )
end

-- While technically tool class names CAN be duplicate, it normally should never happen.
function ActivateTool( strName )
function ActivateTool( strName, noCommand )

-- I really don't like this triple loop
for tab, v in ipairs( g_ToolMenu ) do
Expand All @@ -282,7 +282,7 @@ function ActivateTool( strName )

if ( istable( item ) && item.ItemName && item.ItemName == strName ) then

if ( item.Command ) then
if ( !noCommand && item.Command ) then
RunConsoleCommand( unpack( string.Explode( " ", item.Command ) ) )
end

Expand Down

0 comments on commit 63ed131

Please sign in to comment.