Skip to content

Instantly share code, notes, and snippets.

@Zbizu
Zbizu / animatedText.lua
Last active July 30, 2021 21:23
[TFS 1.3][8.6 downgrade only] doSendAnimatedText
-- just place this in libs
function doSendAnimatedText(pos, text, color, player)
local p = Player(player)
if not p then
return false
end
local msg = NetworkMessage()
msg:addByte(0x84)
msg:addPosition(pos)
@Zbizu
Zbizu / wild_growth_rune.lua
Created July 22, 2021 21:32
timer, wild growth version
local combat = Combat()
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat:setParameter(COMBAT_PARAM_CREATEITEM, ITEM_WILDGROWTH)
local function tile_timer(id, pos, delay, color)
if not Tile(pos):getItemById(id) then
return true
end
if delay ~= 1 then
@Zbizu
Zbizu / magic_wall_rune.lua
Created July 22, 2021 21:31
Timer on magic wall rune (server side)
-- replace your mw script with this
local combat = Combat()
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat:setParameter(COMBAT_PARAM_CREATEITEM, ITEM_MAGICWALL)
local function tile_timer(id, pos, delay, color)
if not Tile(pos):getItemById(id) then
return true
end
@Zbizu
Zbizu / getVariables.lua
Last active December 24, 2023 13:38
get all Lua functions (and globals)
-- usage: just call it in a Lua environment and look for a file called out.txt
-- lists all global variables in a file
function writeAllGlobals()
local file = io.open("out.txt", "w+")
local seen={}
local function dump(t,i)
seen[t]=true
local s={}
@Zbizu
Zbizu / loopEvent.lua
Created July 2, 2021 17:18
reload safe addEvent loop example
-- configuration
LOOP_EVENT_DELAY = 5 * 1000 -- (in milliseconds)
-- register list of affected creatures and protect them from reload
if not LOOP_EVENT_REGISTERED_CREATURES then
LOOP_EVENT_REGISTERED_CREATURES = {}
end
-- store session id to reload the loop without duplicating it
if LOOP_EVENT_SESSION_ID then
@Zbizu
Zbizu / getOS.lua
Last active April 2, 2024 07:55
operating system (OS) detection in Lua
function getOS()
-- ask LuaJIT first
if jit then
return jit.os
end
-- Unix, Linux variants
local fh,err = assert(io.popen("uname -o 2>/dev/null","r"))
if fh then
osname = fh:read()
@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 / 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 / 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,