This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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={} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project.exe test.txt | |
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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 | |
]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
NewerOlder