• 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 Lua script (House Scroll)

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
151
Reaction score
9
Hello,

Im looking for house scroll script, basically the script will work like my talkaction (buyhouse), but i need this in action On use item, the player need use the scroll in front of house door without owner.

My Talkaction Script
Lua:
function onSay(player, words, param)
    if player:getPremiumDays() <= 0 then
        player:sendCancelMessage("You need a premium account.")
        return false
    end

    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

    local tile = Tile(position)
    local house = tile and tile:getHouse()
    if house == nil then
        player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
        return false
    end

    if house:getOwnerGuid() > 0 then
        player:sendCancelMessage("This house already has an owner.")
        return false
    end

    if player:getHouse() then
        player:sendCancelMessage("You are already the owner of a house.")
        return false
    end

    local price = house:getRent() * 5
    if not player:removeMoney(price) then
        player:sendCancelMessage("You do not have enough money.")
        return false
    end

    house:setOwnerGuid(player:getGuid())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.")
    return false
end
 
Solution
Just change the return FALSE to return TRUE, then you can see the messages:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPremiumDays() <= 0 then
        player:sendCancelMessage("You need a premium account.")
        return true
    end

    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

    local tile = Tile(position)
    local house = tile and tile:getHouse()
    if house == nil then
        player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
        return true
    end

    if house:getOwnerGuid() > 0 then
        player:sendCancelMessage("This house already has an owner.")
        return true...
what about

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPremiumDays() <= 0 then
        player:sendCancelMessage("You need a premium account.")
        return false
    end

    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

    local tile = Tile(position)
    local house = tile and tile:getHouse()
    if house == nil then
        player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
        return false
    end

    if house:getOwnerGuid() > 0 then
        player:sendCancelMessage("This house already has an owner.")
        return false
    end

    if player:getHouse() then
        player:sendCancelMessage("You are already the owner of a house.")
        return false
    end

    local price = house:getRent() * 5
    if not player:removeMoney(price) then
        player:sendCancelMessage("You do not have enough money.")
        return false
    end

    house:setOwnerGuid(player:getGuid())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.")
    item:remove()
    return true
end

you can use this to add it


XML:
<action itemid="2322" script="houseitem.lua" /> -- voodo doll
 
Just change the return FALSE to return TRUE, then you can see the messages:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPremiumDays() <= 0 then
        player:sendCancelMessage("You need a premium account.")
        return true
    end

    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

    local tile = Tile(position)
    local house = tile and tile:getHouse()
    if house == nil then
        player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
        return true
    end

    if house:getOwnerGuid() > 0 then
        player:sendCancelMessage("This house already has an owner.")
        return true
    end

    if player:getHouse() then
        player:sendCancelMessage("You are already the owner of a house.")
        return true
    end

    local price = house:getRent() * 5
    if not player:removeMoney(price) then
        player:sendCancelMessage("You do not have enough money.")
        return true
    end

    house:setOwnerGuid(player:getGuid())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.")
    item:remove()
    return true
end
 
Solution
perfect ! thanks so much...
a question, is possible the script only work in specifc house id or name?
Sure use this
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPremiumDays() <= 0 then
        player:sendCancelMessage("You need a premium account.")
        return true
    end
    if house:getId() == 100 then -- Change 100 to the house id
    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

    local tile = Tile(position)
    local house = tile and tile:getHouse()
    if house == nil then
        player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
        return true
    end

    if house:getOwnerGuid() > 0 then
        player:sendCancelMessage("This house already has an owner.")
        return true
    end

    if player:getHouse() then
        player:sendCancelMessage("You are already the owner of a house.")
        return true
    end

    local price = house:getRent() * 5
    if not player:removeMoney(price) then
        player:sendCancelMessage("You do not have enough money.")
        return true
    end

    house:setOwnerGuid(player:getGuid())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.")
    item:remove()
    else
    player:sendMagicEffect(CONST_ME_POFF)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot buy this house using this scroll.")
    end
    return true
end
check the note in line 6
 
Back
Top