Skip to content

Commit 5834195

Browse files
authored
Fix control locking in singleplayer (#1989)
* Fix control locking in singleplayer * cleanup
1 parent 6d49261 commit 5834195

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lua/starfall/libs_sh/input.lua

+18-20
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ end
1010
-- This should manage the player button hooks for singleplayer games.
1111
local PlayerButtonDown, PlayerButtonUp
1212
if game.SinglePlayer() then
13+
PlayerButtonDown, PlayerButtonUp = "SF_PlayerButtonDown", "SF_PlayerButtonUp"
1314
if SERVER then
1415
util.AddNetworkString("sf_relayinput")
1516

@@ -38,6 +39,8 @@ if game.SinglePlayer() then
3839
end
3940
end)
4041
end
42+
else
43+
PlayerButtonDown, PlayerButtonUp = "PlayerButtonDown", "PlayerButtonUp"
4144
end
4245
if SERVER then
4346
util.AddNetworkString("starfall_lock_control")
@@ -54,7 +57,7 @@ local function unlockControls(instance)
5457
instance.data.input.controlsLocked = false
5558
controlsLocked = false
5659
hook.Remove("PlayerBindPress", "sf_keyboard_blockinput")
57-
hook.Remove("PlayerButtonDown", "sf_keyboard_unblockinput")
60+
hook.Remove(PlayerButtonDown, "sf_keyboard_unblockinput")
5861
end
5962

6063
local function lockControls(instance)
@@ -65,7 +68,7 @@ local function lockControls(instance)
6568
hook.Add("PlayerBindPress", "sf_keyboard_blockinput", function(ply, bind, pressed)
6669
if bind ~= "+attack" and bind ~= "+attack2" then return true end
6770
end)
68-
hook.Add("PlayerButtonDown", "sf_keyboard_unblockinput", function(ply, but)
71+
hook.Add(PlayerButtonDown, "sf_keyboard_unblockinput", function(ply, but)
6972
if but == KEY_LALT or but == KEY_RALT then
7073
unlockControls(instance)
7174
end
@@ -103,24 +106,19 @@ local function CheckButtonPerms(instance, ply, button)
103106
return true, { button }
104107
end
105108

106-
if game.SinglePlayer() then
107-
SF.hookAdd("SF_PlayerButtonDown", "inputpressed", CheckButtonPerms)
108-
SF.hookAdd("SF_PlayerButtonUp", "inputreleased", CheckButtonPerms)
109-
else
110-
--- Called when a button is pressed
111-
-- @client
112-
-- @name InputPressed
113-
-- @class hook
114-
-- @param number button Number of the button
115-
SF.hookAdd("PlayerButtonDown", "inputpressed", CheckButtonPerms)
116-
117-
--- Called when a button is released
118-
-- @client
119-
-- @name InputReleased
120-
-- @class hook
121-
-- @param number button Number of the button
122-
SF.hookAdd("PlayerButtonUp", "inputreleased", CheckButtonPerms)
123-
end
109+
--- Called when a button is pressed
110+
-- @client
111+
-- @name InputPressed
112+
-- @class hook
113+
-- @param number button Number of the button
114+
SF.hookAdd(PlayerButtonDown, "inputpressed", CheckButtonPerms)
115+
116+
--- Called when a button is released
117+
-- @client
118+
-- @name InputReleased
119+
-- @class hook
120+
-- @param number button Number of the button
121+
SF.hookAdd(PlayerButtonUp, "inputreleased", CheckButtonPerms)
124122

125123
--- Called when a keybind is pressed
126124
-- @client

0 commit comments

Comments
 (0)