Skip to content

Commit

Permalink
Fix control locking in singleplayer (#1989)
Browse files Browse the repository at this point in the history
* Fix control locking in singleplayer

* cleanup
  • Loading branch information
thegrb93 authored Jan 20, 2025
1 parent 6d49261 commit 5834195
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions lua/starfall/libs_sh/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ end
-- This should manage the player button hooks for singleplayer games.
local PlayerButtonDown, PlayerButtonUp
if game.SinglePlayer() then
PlayerButtonDown, PlayerButtonUp = "SF_PlayerButtonDown", "SF_PlayerButtonUp"
if SERVER then
util.AddNetworkString("sf_relayinput")

Expand Down Expand Up @@ -38,6 +39,8 @@ if game.SinglePlayer() then
end
end)
end
else
PlayerButtonDown, PlayerButtonUp = "PlayerButtonDown", "PlayerButtonUp"
end
if SERVER then
util.AddNetworkString("starfall_lock_control")
Expand All @@ -54,7 +57,7 @@ local function unlockControls(instance)
instance.data.input.controlsLocked = false
controlsLocked = false
hook.Remove("PlayerBindPress", "sf_keyboard_blockinput")
hook.Remove("PlayerButtonDown", "sf_keyboard_unblockinput")
hook.Remove(PlayerButtonDown, "sf_keyboard_unblockinput")
end

local function lockControls(instance)
Expand All @@ -65,7 +68,7 @@ local function lockControls(instance)
hook.Add("PlayerBindPress", "sf_keyboard_blockinput", function(ply, bind, pressed)
if bind ~= "+attack" and bind ~= "+attack2" then return true end
end)
hook.Add("PlayerButtonDown", "sf_keyboard_unblockinput", function(ply, but)
hook.Add(PlayerButtonDown, "sf_keyboard_unblockinput", function(ply, but)
if but == KEY_LALT or but == KEY_RALT then
unlockControls(instance)
end
Expand Down Expand Up @@ -103,24 +106,19 @@ local function CheckButtonPerms(instance, ply, button)
return true, { button }
end

if game.SinglePlayer() then
SF.hookAdd("SF_PlayerButtonDown", "inputpressed", CheckButtonPerms)
SF.hookAdd("SF_PlayerButtonUp", "inputreleased", CheckButtonPerms)
else
--- Called when a button is pressed
-- @client
-- @name InputPressed
-- @class hook
-- @param number button Number of the button
SF.hookAdd("PlayerButtonDown", "inputpressed", CheckButtonPerms)

--- Called when a button is released
-- @client
-- @name InputReleased
-- @class hook
-- @param number button Number of the button
SF.hookAdd("PlayerButtonUp", "inputreleased", CheckButtonPerms)
end
--- Called when a button is pressed
-- @client
-- @name InputPressed
-- @class hook
-- @param number button Number of the button
SF.hookAdd(PlayerButtonDown, "inputpressed", CheckButtonPerms)

--- Called when a button is released
-- @client
-- @name InputReleased
-- @class hook
-- @param number button Number of the button
SF.hookAdd(PlayerButtonUp, "inputreleased", CheckButtonPerms)

--- Called when a keybind is pressed
-- @client
Expand Down

0 comments on commit 5834195

Please sign in to comment.