I don't know much about lua but im trying to make a custom ulx command that toggles on and off an autohop function.
Heres the current code
------------------------------ autohop ------------------------------
function ulx.autohop( calling_ply, target_plys, should_revoke )
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]
if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
else
if not should_revoke then
hook.Add( 'SetupMove', 'AutoHop', function( ply, move )
if( !ply:IsOnGround() ) then
move:SetButtons( bit.band( move:GetButtons(), bit.bnot( IN_JUMP ) ) )
end
end )
else
hook.Add( 'SetupMove', 'Walk', function( ply, move )
if( ply:IsOnGround() ) then
move:SetButtons( bit.band( move:GetButtons(), bit.bnot() ) )
end
end )
end
table.insert( affected_plys, v )
end
end
if not should_revoke then
ulx.fancyLogAdmin( calling_ply, "#A gave autohop to #T", affected_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A removed autohop from #T", affected_plys )
end
end
local autohop = ulx.command( CATEGORY_NAME, "ulx autohop", ulx.autohop, "!autohop" )
autohop:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
autohop:addParam{ type=ULib.cmds.BoolArg, invisible=true }
autohop:defaultAccess( ULib.ACCESS_ADMIN )
autohop:help( "Grants autohop to target(s)." )
autohop:setOpposite( "ulx unautohop", {_, _, true}, "!unautohop" )
Surprisingly everything works up until when I grant myself autohop but I can't disable it and return the affected player back to normal.
hook.Add( 'SetupMove', 'Walk', function( ply, move )
if( ply:IsOnGround() ) then
move:SetButtons( bit.band( move:GetButtons(), bit.bnot() ) )
end
end )
disconnect and reconnecting doesn't disable it either, the only way to currently disable autohop is via server restart.
Just wondering if anyone has any ideas how to fix this. Thanks in advance.
One solution could be that you set it up so that:
1 - Create the 'AutoHop' hook when autohop is enabled
2 - Remove the 'AutoHop' hook when autohop is disabled
-Use hook.Remove to remove the 'AutoHop' hook.
-Give the hook a unique identifier so that you can remove it per player affected ( you could add v:UniqueId() to the id string )
Result: You would have one hook for every player affected, thus removing the hook would remove the bunnyhop effect
Sorry, you need to Log In to post a reply to this thread.