Skip to content

Commit

Permalink
Add setClipboardText cooldown
Browse files Browse the repository at this point in the history
Added a cooldown convar and fixed limit test
  • Loading branch information
Sandalot committed Dec 4, 2023
1 parent 110ff31 commit d119666
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lua/entities/gmod_wire_expression2/core/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,23 @@ end

util.AddNetworkString( "wire_expression2_set_clipboard_text" )
local clipboard_character_limit = CreateConVar("wire_expression2_clipboard_character_limit", 512, FCVAR_ARCHIVE, "Maximum character that can be copied into a players clipboard", 0, 65532)
local clipboard_cooldown = CreateConVar("wire_expression2_clipboard_cooldown", 1, FCVAR_ARCHIVE, "Cooldown for setClipboardText in seconds", 0, nil)

__e2setcost(100)
e2function void setClipboardText(string text)
if #text > clipboard_character_limit:GetInt() then return nil end
print(self.entity:EntIndex())
local timerid = "wire_expression2_clipboard_cooldown_" .. self.entity:EntIndex()
if not timer.Exists(timerid) then
if #text > clipboard_character_limit:GetInt() then

Check warning on line 429 in lua/entities/gmod_wire_expression2/core/debug.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
return self:throw("setClipboardText exceeding string limit of " .. clipboard_character_limit:GetInt() .. " characters", nil)

Check warning on line 430 in lua/entities/gmod_wire_expression2/core/debug.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
end

net.Start("wire_expression2_set_clipboard_text")
net.WriteString(text)
net.Send(self.player)
timer.Create( timerid, clipboard_cooldown:GetInt(), 1, function() timer.Remove(timerid) end)

Check warning on line 434 in lua/entities/gmod_wire_expression2/core/debug.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
net.Start("wire_expression2_set_clipboard_text")
net.WriteString(text)
net.Send(self.player)
else
return self:throw("setClipboardText cooldown!", nil)
end
end

0 comments on commit d119666

Please sign in to comment.