Skip to content

Instantly share code, notes, and snippets.

@Zbizu
Zbizu / poisoncondition.lua
Created December 9, 2021 07:11
poison condition damage formula
function getValue(x)
local flipped = 0
if x % 10 > 5 then
flipped = 1
end
local f
if (x + flipped) % 2 == 1 then
f = math.floor
else
@Zbizu
Zbizu / lagLessSave.lua
Created June 26, 2021 21:24
less laggy player saving (tfs 1.3 or a fork that supports revscriptsys)
local noLagSave = GlobalEvent("noLagSave")
local timeBetweenSaves = 1 * 60 * 60 * 1000 -- in milliseconds
local delayBetweenSaves = 100
function delayedSave(cid)
local p = Player(cid)
if p then
p:save()
end
end
@Zbizu
Zbizu / matrix.lua
Created June 23, 2021 17:48
matrix operations in lua
local matrixFields = {
area = {}
}
local Matrix = setmetatable(matrixFields,
{
__call = function(matrix, ...)
return matrix.new(...)
end
}
@Zbizu
Zbizu / ClassWithAutoMethods.lua
Created June 22, 2021 19:46
automated getter/setter generation example for lua "classes"
local defaults = {
name = "",
words = "",
mana = 0,
manaPercent = 0,
soul = 0,
spellId = 0,
range = -1,
level = 0,
magLevel = 0,
@Zbizu
Zbizu / ClassExample.lua
Created June 22, 2021 19:00
lua "class" example
local Class = setmetatable ({ },
{
__call = function (class, ...)
return class.new (...)
end
}
)
Class.__index = Class
Class.__call = function (self)
@Zbizu
Zbizu / tableClone.lua
Last active January 19, 2022 19:01
[Lua] Clone a table without references
-- creates a full copy of a table
-- changing the value of copied table doesn't touch the original anymore
-- warning: using methods on "copied" userdata will still affect original object
local a = {
["abc"] = {1, 2},
[1] = {4, {2}}
}
function cloneTable(t)
@Zbizu
Zbizu / animatedTextTesting.lua
Created June 24, 2021 19:04
animated text for TFS 1.3 and HP bars bonus
-- who is showing changes and who is watching
spectated = Player("player")
spectator = Player("Administrator")
-- animated text, otclient only (or old clients)
--------------------------------
msg = NetworkMessage()
msg:addByte(0x84)
@Zbizu
Zbizu / fileDir.lua
Created September 19, 2021 16:56
Get current script directory
--[[
dumps file directory to a console
example output:
linedefined 0
lastlinedefined 207
source @F:\ot\data\scripts\filename.lua
what main
short_src ...ot\data\scripts\filename.lua
]]
@Zbizu
Zbizu / launcher.bat
Last active January 19, 2022 19:03
replacer test
project.exe test.txt
pause
@Zbizu
Zbizu / asyncArea.lua
Created July 28, 2021 22:37
non-blocking iteration over large areas
-- async iterate area
-- for when you want to execute a script on a large area, but dont want lags on your server
local defaultChunkSize = 16
local defaultDelay = 200
Area = setmetatable ({ },
{
__call = function (area, ...)
return area.new (...)
end