]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Improved AutoSneak
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 24 Nov 2020 08:48:16 +0000 (09:48 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 24 Nov 2020 08:48:16 +0000 (09:48 +0100)
builtin/client/cheats/movement.lua

index 9737662b2076d6583fea9f742e248139bedc32db..907990cceabfd8b0dbaed0ee46b4b18c11a77705 100644 (file)
@@ -1,15 +1,18 @@
-local function register_keypress_cheat(cheat, keyname)
+local function register_keypress_cheat(cheat, keyname, condition)
        local was_enabled = false
        core.register_globalstep(function()
-               if core.settings:get_bool(cheat) then
-                       was_enabled = true
+               local is_active = core.settings:get_bool(cheat)
+               local condition_true = (not condition or condition())
+               if is_active and condition_true then
                        core.set_keypress(keyname, true)
                elseif was_enabled then
-                       was_enabled = false
                        core.set_keypress(keyname, false)
                end
+               was_enabled = is_active and condition_true
        end)
 end
 
-register_keypress_cheat("autosneak", "sneak")
+register_keypress_cheat("autosneak", "sneak", function()
+       return core.localplayer:is_touching_ground()
+end)
 register_keypress_cheat("autosprint", "special1")