Skip to content

Instantly share code, notes, and snippets.

@Codinablack
Codinablack / getOS.lua
Created January 19, 2022 19:04 — forked from Zbizu/getOS.lua
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()
@Codinablack
Codinablack / loopEvent.lua
Created January 19, 2022 19:04 — forked from Zbizu/loopEvent.lua
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
@Codinablack
Codinablack / getVariables.lua
Created January 19, 2022 19:04 — forked from Zbizu/getVariables.lua
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={}
@Codinablack
Codinablack / magic_wall_rune.lua
Created January 19, 2022 19:04 — forked from Zbizu/magic_wall_rune.lua
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
@Codinablack
Codinablack / asyncArea.lua
Created January 19, 2022 19:03 — forked from Zbizu/asyncArea.lua
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
@Codinablack
Codinablack / launcher.bat
Created January 19, 2022 19:03 — forked from Zbizu/launcher.bat
replacer test
project.exe test.txt
pause
@Codinablack
Codinablack / fileDir.lua
Created January 19, 2022 19:03 — forked from Zbizu/fileDir.lua
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
]]
@Codinablack
Codinablack / animatedTextTesting.lua
Created January 19, 2022 19:02 — forked from Zbizu/animatedTextTesting.lua
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)
@Codinablack
Codinablack / dumptable.lua
Created January 19, 2022 19:01 — forked from Zbizu/dumptable.lua
dump lua table contents to string
-- usage: dumpTable(t)
-- to dump to file:
--[[
local str = dumpTable(t)
local f = io.open("dumped_table.txt", "w+")
f:write(str)
f:close()
]]
local function getTabulation(depth)
@Codinablack
Codinablack / tableClone.lua
Created January 19, 2022 19:01 — forked from Zbizu/tableClone.lua
[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)