• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS 1.x] lib folder in "data" like 0.4

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,690
Location
Poland
A simple loader for libs. It brings data\lib folder functionality from 0.4

installation:

create folder: "data\lib\"
add to global.lua:
Code:
for dir in io.popen([[dir "data\lib\" /b /aa]]):lines() do
  dofile('data/lib/'..dir..'')
end
after:
Code:
dofile('data/compat.lua')

it should look like this:
wW4ux3L.jpg


now you may put anything in lib folder and it will be loaded like in 0.4.
example lib:

04_compat.lua
Code:
getThingFromPos = getThingfromPos
getThingPosition = getThingPos
MESSAGE_LOOT = MESSAGE_INFO_DESCR
TALKTYPE_MONSTER = TALKTYPE_MONSTER_SAY
TALKTYPE_ORANGE_1 = TALKTYPE_MONSTER_SAY
TALKTYPE_ORANGE_2 = TALKTYPE_MONSTER_YELL

getCreatureStorage = getPlayerStorageValue
doCreatureSetStorage = setPlayerStorageValue
function getItemNameById(itemId) return ItemType(itemId):getName() end

string.explode = function (str, sep, limit)
if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
   return {}
end


Special thanks to @Limos for showing me how to do it.
 
Last edited:
It's default/not TFS related Lua code so it also works on other (windows) servers btw, incase there are people who want to use it on other servers like 0.2.
 
Yes I seen that post and have been utilizing this method for a couple weeks now I believe. It's great, recommended for everyone for organization purposes, so easy to add libs
 
It uses windows commands so with linux it will be a bit different, unfortunately I can't test it since I only have windows.
 
I've been working on an auto parser aswell for lua files, for your needs you can use this (it's tested and confirmed working)

this function will tell us which operation system we use:
Code:
function getOS()
   -- Unix, Linux varients
   fh,err = assert(io.popen("uname -o 2>/dev/null","r"))
   if fh then
     osname = fh:read()
   end
   if osname then
     return osname
   end
   return "windows"
end
the only problem is, if you use this function at windows it'll write in your console that it didn't found the file it's basicly an error but you can ignore it.

and this method will fetch all lua files in a certain directory (it also checks all subdirectories)
Code:
function loadLibs()
   if getOS() == "windows" then
     for path in io.popen([[cd "data\lib\" && dir *.lua /b/s]]):lines() do
       dofile(path)
     end
   else
     for path in io.popen("cd data/lib && find . -type f | grep .lua"):lines() do
       dofile(path)
     end
   end
end

if someone wants a c function for the getOS() then he can use this:
Code:
int32_t LuaScriptInterface::luaGetOS(lua_State* L)
{
   //getOS()
   std::string os = "unix";
#ifdef _WIN32
   os = "windows";
#endif
   pushString(L, os);
   return 1;
}
 
your function was good too, to make loaders for older versions of tfs without LuaJIT
 
Back
Top