• 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!

Lua Upgrading scripts from TFS 0.2.15 to TFS 1.1/1.2+

Fermantor

Active Member
Joined
Dec 16, 2009
Messages
209
Solutions
4
Reaction score
33
Location
Germany
Hello everyone,
it's been a long time since I worked on my server and a lot of progress was done on TFS.
Now that it uses a new scripting system and a reworked engine I really wanna upgrade my old sever to 1.x.

I want to get all my old script to the new state and I know there is not a program where I throw in my old scripts and get perfectly working ones for the new system. I know I have to go over every single script one by one.
But anyway, I don't know where to start. Almost everything I know about scripting I taught myself by reading working scripts, understanding them and changing them.

I'm afraid I have to do all of this steps again from the very beginning. Are there any tips you guys can give me? Maybe even a little guide or tutorial, where the biggest changes are.
All in all the new system looks so much simpler and easier.

I hope you can help me at least a bit :)
 
Most functions are here; forgottenserver/luascript.cpp at master · otland/forgottenserver · GitHub
If you wanna find out what ex getPlayerHealth(cid) is in 1.3 use this; forgottenserver/compat.lua at master · otland/forgottenserver · GitHub

Some functions are also in these files;
forgottenserver/data/lib/core at master · otland/forgottenserver · GitHub
forgottenserver/global.lua at master · otland/forgottenserver · GitHub

The thread @Sajgon linked to can be good, but remember that its outdated, using those links (except the first one, just serach registerMethod in that case) will make sure that you always have the latest info.
 
if you already know how 0.x scripts work and you're fairly confident with them, it's super easy to learn 1.x
you can learn how lua approaches OOP here, which is used in 1.x Programming in Lua : 16
there is no more uids/cids needed unless you're using them to construct an object
to construct an object, there are functions that are called constructors, which (you guessed it) construct an object that's ready for use
an example of this would be
Lua:
local demonType = MonsterType("Demon")
this constructs a monstertype object and stores it in the variable demonType, objects use userdata, which is a special data type in lua (its a block of memory), you can use methods (functions that only work on objects) to access information
such as:
Lua:
print(demonType:getHealth())
this will print out the normal health that a demon would have
you don't have to worry about starting all over and re learning everything, you just gotta learn how OOP works
keep a list of functions around like the people above posted, since it helps a ton for you to figure out what you want to do

a few examples from 0.4 to 1.2
Lua:
doCreatureAddHealth(cid, 100) -> player:addHealth(100)
getTileItemById({x = 1000, y = 1000, z = 7}, 2160) -> Tile(1000, 1000, 7):getItemById(2160)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DECR, "test") -> player:sendTextMessage(MESSAGE_INFO_DESCR, "test")

you don't exactly have to convert every single function, since there's backwards compatibility (compat.lua in data/lib/compat) meaning the camelcase functions (things like doPlayerAddItem) will return player:addItem instead, and convert cid to a player object
good luck
 
Back
Top