TFS 1.2 Lua script (House Scroll)

Joined
Aug 21, 2017
Messages
49
Best answers
0
Likes
1
#1
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
 

StreamSide

Joseluis Gonzalez
Joined
Aug 31, 2007
Messages
3,065
Best answers
18
Likes
676
Location
Arica - Chile
#2
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
 

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,247
Best answers
17
Likes
376
#4
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
 
Joined
Aug 21, 2017
Messages
49
Best answers
0
Likes
1
#5
perfect ! thanks so much...
a question, is possible the script only work in specifc house id or name?
 

Shadow_

asgard-ot.com
Premium User
Joined
Jun 2, 2018
Messages
270
Best answers
6
Likes
43
Location
Cairo, Egypt
#6
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
 
Top