TFS 1.2 Lua script (House Scroll)

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
109
Best answers
0
Reaction score
6
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
Support Team
Joined
Aug 31, 2007
Messages
3,294
Best answers
29
Reaction score
811
Location
Arica - Chile
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
 
OP
G

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
109
Best answers
0
Reaction score
6
no work :/

0 console errors, in game say you cannot you this object...
 

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,258
Best answers
18
Reaction score
379
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
 
OP
G

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
109
Best answers
0
Reaction score
6
perfect ! thanks so much...
a question, is possible the script only work in specifc house id or name?
 

Shadow_

Active Member
Joined
Jun 2, 2018
Messages
348
Best answers
9
Reaction score
72
Location
Cairo, Egypt
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