Skip to content

Commit 412f504

Browse files
authored
Fix lua errors (#2225)
* Fix lua errors * Also fix getQuotaAverage for e2
1 parent ca2fa6c commit 412f504

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

lua/starfall/editor/tabhandlers/tab_wire.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,12 +3070,13 @@ end
30703070

30713071
function PANEL:AutocompleteApply()
30723072
local selection = self.acPanel:GetSelected()
3073-
self:SetCaret(self:SetArea({{self.Caret[1], math.max(1, self.Caret[2]-selection.replacelength)}, self.Caret }, selection.replace ))
3074-
if selection.reopen then
3075-
self:AutocompleteOpen()
3076-
else
3077-
self:AutocompleteClose()
3073+
if selection then
3074+
self:SetCaret(self:SetArea({{self.Caret[1], math.max(1, self.Caret[2]-selection.replacelength)}, self.Caret }, selection.replace ))
3075+
if selection.reopen then
3076+
return self:AutocompleteOpen()
3077+
end
30783078
end
3079+
self:AutocompleteClose()
30793080
end
30803081

30813082
function PANEL:AutocompleteClose()

lua/starfall/libs_sh/entities.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ function ents_methods:getQuotaAverage()
10871087
if ent_tbl.Starfall then
10881088
return ent_tbl.instance and ent_tbl.instance:movingCPUAverage() or 0
10891089
elseif Ent_GetClass(ent)=="gmod_wire_expression2" then
1090-
return SERVER and ent_tbl.context.timebench or ent_tbl.GetOverlayData(ent).timebench
1090+
return SERVER and (ent_tbl.context and ent_tbl.context.timebench or 0) or (ent_tbl.GetOverlayData(ent).timebench or 0)
10911091
else
10921092
SF.Throw("The entity isn't a starfall or expression2 chip", 2)
10931093
end

lua/starfall/libs_sh/input.lua

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ hook.Add("FinishChat","SF_StartChat",function() isChatOpen=false end)
9898

9999
local function CheckButtonPerms(instance, ply, button)
100100
if not IsFirstTimePredicted() and not game.SinglePlayer() then return false end
101-
if not haspermission(instance, nil, "input") then return false end
102-
if isChatOpen and not haspermission(instance, nil, "input.chat") then
103-
local notMouseButton = button < MOUSE_FIRST and button > MOUSE_LAST
104-
local notJoystick = button < JOYSTICK_FIRST and button > JOYSTICK_LAST
105-
if notMouseButton and notJoystick then return false end -- Mouse and joystick are allowed, they don't put text into the chat
101+
if instance.player ~= SF.Superuser then
102+
if not haspermission(instance, nil, "input") then return false end
103+
if isChatOpen and not haspermission(instance, nil, "input.chat") then
104+
local notMouseButton = button < MOUSE_FIRST and button > MOUSE_LAST
105+
local notJoystick = button < JOYSTICK_FIRST and button > JOYSTICK_LAST
106+
if notMouseButton and notJoystick then return false end -- Mouse and joystick are allowed, they don't put text into the chat
107+
end
106108
end
107109

108110
return true, { button }
@@ -129,7 +131,7 @@ SF.hookAdd(PlayerButtonUp, "inputreleased", CheckButtonPerms)
129131
-- @param string bind Name of keybind pressed
130132
-- @return boolean Returning true will block the binding from being pressed for the chip owner
131133
SF.hookAdd("PlayerBindPress", "inputbindpressed", function(instance, ply, bind)
132-
if haspermission(instance, nil, "input") then
134+
if instance.player == SF.Superuser or haspermission(instance, nil, "input") then
133135
return true, {bind}
134136
end
135137
return false
@@ -145,7 +147,7 @@ end)
145147
-- @param number x X coordinate moved
146148
-- @param number y Y coordinate moved
147149
SF.hookAdd("InputMouseApply", "mousemoved", function(instance, _, x, y)
148-
if haspermission(instance, nil, "input") then
150+
if instance.player == SF.Superuser or haspermission(instance, nil, "input") then
149151
if x~=0 or y~=0 then
150152
return true, { x, y }
151153
end
@@ -160,7 +162,7 @@ end)
160162
-- @class hook
161163
-- @param number delta Rotate delta
162164
SF.hookAdd("StartCommand", "mousewheeled", function(instance, ply, cmd)
163-
if haspermission(instance, nil, "input") then
165+
if instance.player == SF.Superuser or haspermission(instance, nil, "input") then
164166
local delta = cmd:GetMouseWheel()
165167
if delta ~= 0 then
166168
return true, {delta}
@@ -175,7 +177,7 @@ local oldOnMouseWheeled = wpanel.OnMouseWheeled or function() end
175177
function wpanel:OnMouseWheeled(delta)
176178
oldOnMouseWheeled(self, delta)
177179
for inst, _ in pairs(SF.allInstances) do
178-
if haspermission(inst, nil, "input") then
180+
if inst.player == SF.Superuser or haspermission(inst, nil, "input") then
179181
inst:runScriptHook("mousewheeled", delta)
180182
end
181183
end
@@ -257,7 +259,7 @@ function input_library.isKeyDown(key)
257259
checkluatype(key, TYPE_NUMBER)
258260

259261
checkpermission(instance, nil, "input")
260-
if isChatOpen and not haspermission(instance, nil, "input.chat") then return false end
262+
if isChatOpen and not (instance.player == SF.Superuser or haspermission(instance, nil, "input.chat")) then return false end
261263

262264
return input.IsKeyDown(key)
263265
end
@@ -385,7 +387,7 @@ end
385387
-- @client
386388
-- @return boolean Whether the player's control can be locked
387389
function input_library.canLockControls()
388-
return haspermission(instance, nil, "input.lockcontrols") and lockedControlCooldown + inputLockCooldown:GetFloat() <= CurTime()
390+
return instance.player == SF.Superuser or (haspermission(instance, nil, "input.lockcontrols") and lockedControlCooldown + inputLockCooldown:GetFloat() <= CurTime())
389391
end
390392

391393
--- Returns whether the game menu overlay ( main menu ) is open or not.

0 commit comments

Comments
 (0)