• 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 TFS 1.2 Scripting

Ovnyx

Member
Joined
Jul 25, 2017
Messages
163
Solutions
2
Reaction score
7
hi people, im trying to use lua metatables to create a script by using classes, what i wanted to know is if i can save some info to work with it anytime the player log in?

basically what i wanted to do its to create a object and associate it to a player, so i can use a lib file, to create some functions like getPlayerObject().... and if created, make use of this object with the associated player, but i dont want this info to lose so i can use this "object " any time no matter if i log off and then log in again

i hope i made my self understand and can be helped.

thanks in advice.
Ovnyx.
 
Yeah you can just store it in a table with the players id, so you can get the item whenever you want. Untested and maybe some errors, but it should help you understand.

Lua:
playerItems = {}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local id = player:getId()
    playerItems[id] = item
    return true
end

function getPlayerObject(player)
    local id = player:getId()
    if playerItems[id] then
        player:addItem(playerItems[id], 1)
    end
end
 
wow!!, so just by storing the data in a lua table, will be avaliable anytime i log in if player had an associated object? even if server get closed and opened again??
 
wow!!, so just by storing the data in a lua table, will be avaliable anytime i log in if player had an associated object? even if server get closed and opened again??
No.
Server memory is freed after restart.
 
Well actually I didnt think about that, it would reset on login. I guess best way then is to player:setStorageValue(RANDOMNUMBER, item ID).

So like:
Lua:
STORAGE_PLAYEROBJECT = 48921 --In global.lua

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:setStorageValue(STORAGE_PLAYEROBJECT, item:getId())
    return true
end

function getPlayerObject(player)
    local id = player:getStorageValue(STORAGE_PLAYEROBJECT)
    if id > 0 then
        player:addItem(id, 1)
    end
end
 
hmmm so, i should modify the server sql squema and try to store there the object info to store it permanetly?

EDIT: what if my class object isnt an item and its for example a summon? and i wante anytime i log that summon is still there with me?
 
Last edited:
Its possible but not easily done because you would have to have the monsters name. I created a script a while back for a pet egg that works with the tfs 1.2 pet system if it's helpful, this one works because there is a table that has the monster names that it refers to: [TFS 1.2] Pet system

Also this may be a dumb solution but if there's possibly a way to convert the name to string.char and convert back. Just an idea.
 
thanks for your answer, i was already reading that code trying to understand but sincerely i understand all the code and what it does but, i cant understand how that values are still there in PETS table, when i turn off server and run it again or player log of and log in :/
 
Back
Top