Skip to content

Instantly share code, notes, and snippets.

@Zbizu
Zbizu / getVector.cpp
Last active March 24, 2023 17:04
Lua get a vector of integers for C++
void LuaScriptInterface::getIntVector(lua_State* L, int32_t arg, std::vector<uint32_t>& vec)
{
lua_pushnil(L);
while (lua_next(L, arg) != 0) {
if (lua_isnumber(L, -1)) {
vec.push_back(lua_tointeger(L, -1));
}
lua_pop(L, 1);
}
local files = {"door_locked.png",
"door_locked_small.png",
"door_normal.png",
"door_normal_small.png",
"door_magic.png",
"door_magic_small.png",
"door_quest.png",
"door_quest_small.png"}
function c()
@Zbizu
Zbizu / loader.lua
Created April 11, 2022 09:40
Lua folder iterator example
------------------------------
-- Loader config
------------------------------
local mapGeneratorDir = "data/map_generator/"
------------------------------
-- loader
------------------------------
dofile(mapGeneratorDir .. 'config.lua')
local prefix = ">> "
@Zbizu
Zbizu / how_to_run_1098_version12.md
Last active June 2, 2022 13:56
How to run 10.98 with version 12
@Zbizu
Zbizu / relocate.lua
Created April 2, 2022 02:56
move all creatures and items from one position to another
-- no need to redefine this in every script, just paste it to your libs
function Position:moveAll(newPos)
local tile = Tile(self)
if tile then
local tileStack = tile:getItems()
for _, tileItem in pairs(tileStack) do
local itemType = tileItem:getType()
if itemType:isMovable() then
@Zbizu
Zbizu / fmt_test.cpp
Created March 30, 2022 14:24
fmt lib color dump
//requires fmt/color.h
std::vector<fmt::color> vect{
fmt::color::alice_blue, fmt::color::antique_white, fmt::color::aqua, fmt::color::aquamarine, fmt::color::azure, fmt::color::beige, fmt::color::bisque, fmt::color::black, fmt::color::blanched_almond, fmt::color::blue, fmt::color::blue_violet, fmt::color::brown, fmt::color::burly_wood, fmt::color::cadet_blue, fmt::color::chartreuse, fmt::color::chocolate, fmt::color::coral, fmt::color::cornflower_blue, fmt::color::cornsilk, fmt::color::crimson, fmt::color::cyan, fmt::color::dark_blue, fmt::color::dark_cyan, fmt::color::dark_golden_rod, fmt::color::dark_gray, fmt::color::dark_green, fmt::color::dark_khaki, fmt::color::dark_magenta, fmt::color::dark_olive_green, fmt::color::dark_orange, fmt::color::dark_orchid, fmt::color::dark_red, fmt::color::dark_salmon, fmt::color::dark_sea_green, fmt::color::dark_slate_blue, fmt::color::dark_slate_gray, fmt::color::dark_turquoise, fmt::color::dark_violet, fmt::color::deep_pink, fmt::color::deep_sky_blue, fmt::color:
@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 / moduleManager.lua
Last active November 30, 2021 04:21
Lua module system concept
-- module system
if not Game.modules then
-- load
Game.modules = {
moduleList = {},
unLoadedModuleList = {}
}
else
-- reload
local newModuleList = {}
@Zbizu
Zbizu / chatchannels.xml
Last active November 27, 2021 15:17
Lua interpreter in chat channel
<channel id="32" name="Lua" script="luachannel.lua" />
@Zbizu
Zbizu / secretMenu.lua
Last active November 25, 2021 18:56
Special outfit window
-- works without adding anything to outfits.xml
local outfits = {
{12, "Archdemon"},
{75, "Gamemaster"},
{159, "Elf"},
{160, "Dwarf"},
{194, "Cultist"},
{226, "Frog"},
{253, "Headsplitter"},
{254, "Skullhunter"},