• 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.1] How to save a single house?

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,317
Solutions
35
Reaction score
434
Hello,

Is it possible to save houses one at a time? The goal is to save the house every time a player moves an item in that house.

Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    -- save house
    local houseTile = Tile(toPosition)
    if houseTile then
        local house = tile:getHouse()
        if house then
            house:save() <-- I just made that up but it's what I'm looking for, like player:save()
        end
    end
return true
end

Thanks for your help! :)
 
Hello,

Is it possible to save houses one at a time? The goal is to save the house every time a player moves an item in that house.

Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    -- save house
    local houseTile = Tile(toPosition)
    if houseTile then
        local house = tile:getHouse()
        if house then
            house:save() <-- I just made that up but it's what I'm looking for, like player:save()
        end
    end
return true
end

Thanks for your help! :)
This is not a good idea.
 
This is not a good idea.
Without an explanation that's not a very helpful response. :(

Could you please explain to myself and others who may read this thread why it is not a good idea so that we can all gain a better understanding.

Thanks!
 
Without an explanation that's not a very helpful response. :(

Could you please explain to myself and others who may read this thread why it is not a good idea so that we can all gain a better understanding.

Thanks!
TFS save each tile of a house in the database by deleting the old information and replacing with the new information about them.
If you have a house with 30 tiles every time you save that house it will remove 30 rows from the database and add 30 rows to the database.
(In fact TFS saves all house tiles at the same time, so it deletes all information from the stored tiles. there is no function to save a single house but that's how it would be done.)
From there its easy to see why saving a house every time an item is moved is not a good idea.

Another problem would be duplicating items, the player is only saved on logout or when the server is saved, so if he moves an item from his inventory to the house, this item would be saved in the database inside the house and in the player. To avoid this you would need to save the player every time he moved an item, again more database stuff to be deleted and added again.

Edit: Source https://github.com/otland/forgottenserver/blob/master/src/iomapserialize.cpp#L67-L114
 
Well you could store it in memory temporarily while the server is online and then save it to a separate table in the event of a crash, kind of like hibernation mode on windows.

Idk this might be something interesting to look into.
 
Back
Top