• 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+ Few questions - housing

Raschu

New Member
Joined
Aug 2, 2011
Messages
69
Reaction score
1
Hello All

I using TFS 1.2 and now i have few problems with housing system.

1) How to change premision for sleeping in house, I mean only VIP players can use beds.
2) Unwraping system also i want to have dhat option only for VIP players.
3) When Owner VIP Account is ended, then player leave house.

I be realy gratefull i someone can help me.

Thanks
Mat
 
Solution
I believe a global event would be the most appropiate solution since a player could buy a house and then never login again, so onLogin won't do the deed.
Lua:
    local vip_storage = 1000
    local houses = Game.getHouses()
    for i = 1, #houses do
        local house = houses[i]
        local owner = house:getOwnerGuid()
        if owner > 0 then
            local own = Player(owner)
            if own:getStorageValue(vip_storage) == 0 then
                house:setOwnerGuid(0)
            end
        end
    end
You could create a new global event or just add it to serversave.lua,
Storage. And I See unwraping dont work anyway.
Edit.

1) and 2) sloved if someone have any ideas for no 3. Please help :)
 
Last edited:
I believe a global event would be the most appropiate solution since a player could buy a house and then never login again, so onLogin won't do the deed.
Lua:
    local vip_storage = 1000
    local houses = Game.getHouses()
    for i = 1, #houses do
        local house = houses[i]
        local owner = house:getOwnerGuid()
        if owner > 0 then
            local own = Player(owner)
            if own:getStorageValue(vip_storage) == 0 then
                house:setOwnerGuid(0)
            end
        end
    end
You could create a new global event or just add it to serversave.lua,
 
Solution
Hello

I just check your code but this does not work for me. I will give you my vip system that probaby be helps. To buy the house is no problem i just change comand preference:

vip system lua:

Lua:
--[[
# Vip System for The Forgotten Server 1.0
# https://github.com/otland/forgottenserver/releases (1.0)
# Vip System by Summ
## Version v0.2
## Link: http://otland.net/threads/vip-system-the-forgotten-server-1-0.224910/
# Credits to Printer upon whose script this is based
## Link: http://otland.net/threads/vip-system-tfs-1-1.224758/
# MySQL query
    ALTER TABLE `accounts`
        ADD COLUMN `viplastday` int(10) NOT NULL DEFAULT 0 AFTER `lastday`,
        ADD COLUMN `vipdays` int(11) NOT NULL DEFAULT 0 AFTER `lastday`;
]]
local config = {
    -- true = player will be teleported to this position if Vip runs out
    -- false = player will not be teleported
    useTeleport = true,
    expirationPosition = Position(32681, 31686, 7),
    -- true = player will received the message you set
    -- false = player will not receive a message
    useMessage = true,
    expirationMessage = 'Your vip days ran out.',
    expirationMessageType = MESSAGE_STATUS_WARNING
}
if not VipData then
    VipData = { }
end
function Player.onRemoveVip(self)
    if config.useTeleport then
        self:teleportTo(config.expirationPosition)
        config.expirationPosition:sendMagicEffect(CONST_ME_TELEPORT)
    end
    if config.useMessage then
        self:sendTextMessage(config.expirationMessageType, config.expirationMessage)
    end
end
function Player.getVipDays(self)
    return VipData[self:getId()].days
end
function Player.getLastVipDay(self)
    return VipData[self:getId()].lastDay
end
function Player.isVip(self)
    return self:getVipDays() > 0
end
function Player.addInfiniteVip(self)
    local data = VipData[self:getId()]
    data.days = 0xFFFF
    data.lastDay = 0
    db.query(string.format('UPDATE `accounts` SET `vipdays` = %i, `viplastday` = %i WHERE `id` = %i;', 0xFFFF, 0, self:getAccountId()))
end
function Player.addVipDays(self, amount)
    local data = VipData[self:getId()]
    local amount = math.min(0xFFFE - data.days, amount)
    if amount > 0 then
        if data.days == 0 then
            local time = os.time()
            db.query(string.format('UPDATE `accounts` SET `vipdays` = `vipdays` + %i, `viplastday` = %i WHERE `id` = %i;', amount, time, self:getAccountId()))
            data.lastDay = time
        else
            db.query(string.format('UPDATE `accounts` SET `vipdays` = `vipdays` + %i WHERE `id` = %i;', amount, self:getAccountId()))
        end
        data.days = data.days + amount
    end
    return true
end
function Player.removeVipDays(self, amount)
    local data = VipData[self:getId()]
    if data.days == 0xFFFF then
        return false
    end
    local amount = math.min(data.days, amount)
    if amount > 0 then
        db.query(string.format('UPDATE `accounts` SET `vipdays` = `vipdays` - %i WHERE `id` = %i;', amount, self:getAccountId()))
        data.days = data.days - amount
        if data.days == 0 then
            self:onRemoveVip()
        end
    end
    return true
end
function Player.removeVip(self)
    local data = VipData[self:getId()]
    if data.days == 0 then
        return
    end
    data.days = 0
    data.lastDay = 0
    self:onRemoveVip()
    db.query(string.format('UPDATE `accounts` SET `vipdays` = 0, `viplastday` = 0 WHERE `id` = %i;', self:getAccountId()))
end
function Player.loadVipData(self)
    local resultId = db.storeQuery(string.format('SELECT `vipdays`, `viplastday` FROM `accounts` WHERE `id` = %i;', self:getAccountId()))
    if resultId then
        VipData[self:getId()] = {
            days = result.getDataInt(resultId, 'vipdays'),
            lastDay = result.getDataInt(resultId, 'viplastday')
        }
        result.free(resultId)
        return true
    end
    VipData[self:getId()] = { days = 0, lastDay = 0 }
    return false
end
function Player.updateVipTime(self)
    local save = false
    local data = VipData[self:getId()]
    local days, lastDay = data.days, data.lastDay
    local daysBefore = days
    if days == 0 or days == 0xFFFF then
        if lastDay ~= 0 then
            lastDay = 0
            save = true
        end
    elseif lastDay == 0 then
        lastDay = os.time()
        save = true
    else
        local time = os.time()
        local elapsedDays = math.floor((time - lastDay) / 86400)
        if elapsedDays > 0 then
            if elapsedDays >= days then
                days = 0
                lastDay = 0
            else
                days = days - elapsedDays
                lastDay = time - ((time - lastDay) % 86400)
            end
            save = true
        end
    end
    if save then
        if daysBefore > 0 and days == 0 then
            self:onRemoveVip()
        end
        db.query(string.format('UPDATE `accounts` SET `vipdays` = %i, `viplastday` = %i WHERE `id` = %i;', days, lastDay, self:getAccountId()))
        data.days = days
        data.lastDay = lastDay
    end
end
 
You said it was through storages lol
Lua:
    local houses = Game.getHouses()
    for i = 1, #houses do
        local house = houses[i]
        local owner = house:getOwnerGuid()
        if owner > 0 then
            local own = Player(owner)
            if not Player.isVip(owner) then
                house:setOwnerGuid(0)
            end
        end
    end
 
You said it was through storages lol
Lua:
    local houses = Game.getHouses()
    for i = 1, #houses do
        local house = houses[i]
        local owner = house:getOwnerGuid()
        if owner > 0 then
            local own = Player(owner)
            if not Player.isVip(owner) then
                house:setOwnerGuid(0)
            end
        end
    end
i think you mean:
Lua:
    local houses = Game.getHouses()
    for i = 1, #houses do
        local house = houses[i]
        local owner = house:getOwnerGuid()
        if owner > 0 then
            local own = Player(owner)
            if own and not own:isVip() then
                house:setOwnerGuid(0)
            end
        end
    end
 
i think you mean:
Lua:
    local houses = Game.getHouses()
    for i = 1, #houses do
        local house = houses[i]
        local owner = house:getOwnerGuid()
        if owner > 0 then
            local own = Player(owner)
            if own and not own:isVip() then
                house:setOwnerGuid(0)
            end
        end
    end
Lol yes, should work if we remove "if owner > 0 then " I guess
 
i think you mean:
Lua:
    local houses = Game.getHouses()
    for i = 1, #houses do
        local house = houses[i]
        local owner = house:getOwnerGuid()
        if owner > 0 then
            local own = Player(owner)
            if own and not own:isVip() then
                house:setOwnerGuid(0)
            end
        end
    end
i think you mean:
Lua:
for _, house in pairs(Game.getHouses()) do
    local ownerGUID = house:getOwnerGuid()
    if ownerGUID > 0 then
        local owner = Player(ownerGUID)
        if owner and not owner:isVip() then
            house:setOwnerGuid(0)
        end
    end
end
 
i think you mean:
Lua:
for _, house in pairs(Game.getHouses()) do
    local ownerGUID = house:getOwnerGuid()
    if ownerGUID > 0 then
        local owner = Player(ownerGUID)
        if owner and not owner:isVip() then
            house:setOwnerGuid(0)
        end
    end
end
no, i didn't mean a slower performing chunk of code
i corrected bogart because his would have errored + a minor fix to use the method instead of indexing the player table to use isVip
 
Last edited:
Hi

If I add this like that, then does not work:

Lua:
ocal shutdownAtServerSave = true
local cleanMapAtServerSave = false

local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    else
        Game.setGameState(GAME_STATE_CLOSED)

        if cleanMapAtServerSave then
            cleanMap()
        end

        Game.setGameState(GAME_STATE_CLOSED)
    end
end

local function secondServerSaveWarning()
    Game.broadcastMessage("Server is saving game in one minute. Please logout.", MESSAGE_EVENT_ADVANCE)
    addEvent(serverSave, 60000)
end
local function firstServerSaveWarning()
    Game.broadcastMessage("Server is saving game in 3 minutes. Please logout.", MESSAGE_EVENT_ADVANCE)
    addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
    Game.broadcastMessage("Server is saving game in 5 minutes. Please logout.", MESSAGE_EVENT_ADVANCE)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end

for _, house in pairs(Game.getHouses()) do
    local ownerGUID = house:getOwnerGuid()
    if ownerGUID > 0 then
        local owner = Player(ownerGUID)
        if owner and not owner:isVip() then
            house:setOwnerGuid(0)
        end
    end
end
 
Back
Top