• 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.2] About lua and metamethods

Ovnyx

Member
Joined
Jul 25, 2017
Messages
163
Solutions
2
Reaction score
7
Solution
if you mean to add new metamethods to a metatable, then yes, you could use
Code:
Metatable:methodName(params)

or
Code:
Metatable.methodName(self, params)

in both cases "self" will be the object you will use

i.e.
Code:
function Player:sayHi()
    self:say("Hi", TALKTYPE_MONSTER_SAY)
end

tfs methods are defined in luascript.cpp but you can even overwrite them if you want it. I.E.

Code:
function Player:getOutfit()
    print("xd")
end

player:getOutfit() --it prints "xd"
so could i make use of this interfaces to create a new object similar behavior to a ordinary player?
 
if you mean to add new metamethods to a metatable, then yes, you could use
Code:
Metatable:methodName(params)

or
Code:
Metatable.methodName(self, params)

in both cases "self" will be the object you will use

i.e.
Code:
function Player:sayHi()
    self:say("Hi", TALKTYPE_MONSTER_SAY)
end

tfs methods are defined in luascript.cpp but you can even overwrite them if you want it. I.E.

Code:
function Player:getOutfit()
    print("xd")
end

player:getOutfit() --it prints "xd"
 
Solution
wow thanks for your answer man trully Educational!!!! really thanks!!!

got a question, can i create a lib file in /data/lib/ , and there with help of Object orientated programming define classes, to create new objects in tibia? like creating a a item who can "act" like a creature, and talk, attack, move, and all that creature actions ??

thanks in advice!! bless

EDIT: make me know if im too confusing and i dont make my self understood!
 
you can create new "classes" but you can't create something that will be an item but act like a creature because that's reserved for creatures
most of the methods you see are made in the source, meaning there's things you can't make by just using lua, they're made in c++.
keep in mind methods are different from metamethods. metamethods are things that work directly with the metatable, like __index, __newindex, __add, etc.
 
Back
Top