• 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!

Is this possible?

Margolin

עם ישראל חי
Joined
Dec 20, 2016
Messages
43
Reaction score
12
Hello OTLand. Im wondering if this is possible:

Player can only buy a house if he is a citizen of the city where he pretends to buy.
Example: !buyhouse CANCEL-> You need to be a citizen of Thais to buy this house.


When you look into a player it says which city he's from and if owns a house.
Example: He is a citizen of Thais.

NPC can sell a citizenship for cash or items.
 
Yes this is possible, go to talkactions > scripts > buyhouse.lua and add this code


Lua:
if player:getTown() ~= house:getTown() then
    player:sendCancelMessage("You must be a citizen of this town.")
    return false
end

I suppose you use TFS 1+
 
Last edited:
This symbol is giving me an error "~"

Yes this is possible, go to talkactions > scripts > buyhouse.lua and add this code


Lua:
if player:getTown ~= house:getTown() then
    player:sendCancelMessage("You must be a citizen of this town.")
    return false
end

I suppose you use TFS 1+
 
tfs 1.2+:
Lua:
function onSay(player, words, param)
    local housePrice = configManager.getNumber(configKeys.HOUSE_PRICE)
    if housePrice == -1 then
        return true
    end

    if not player:isPremium() then
        player:sendCancelMessage("You need a premium account.")
        return false
    end
   
    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

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

    local tile = Tile(position)
    local house = tile and tile:getHouse()
    if not house then
        player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
        return false
    end
   
    if player:getTown() ~= house:getTown() then
        player:sendCancelMessage("You must be a citizen of this town.")
        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:getTileCount() * housePrice
    if not player:removeMoney(price) then
        player:sendCancelMessage("You do not have enough money.")
        return false
    end

    house:setOwnerGuid(player:getGuid())
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully bought this house, be sure to have the money for the rent in the bank.")
    return false
end
 
Not working for me

tfs 1.2+:
Lua:
function onSay(player, words, param)
    local housePrice = configManager.getNumber(configKeys.HOUSE_PRICE)
    if housePrice == -1 then
        return true
    end

    if not player:isPremium() then
        player:sendCancelMessage("You need a premium account.")
        return false
    end
  
    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

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

    local tile = Tile(position)
    local house = tile and tile:getHouse()
    if not house then
        player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
        return false
    end
  
    if player:getTown() ~= house:getTown() then
        player:sendCancelMessage("You must be a citizen of this town.")
        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:getTileCount() * housePrice
    if not player:removeMoney(price) then
        player:sendCancelMessage("You do not have enough money.")
        return false
    end

    house:setOwnerGuid(player:getGuid())
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully bought this house, be sure to have the money for the rent in the bank.")
    return false
end
 
Nevermind, It's working fine. I do not know what happened.
Now, is there a way to look at a player and display which city he belongs to and if he owns a house?
 
data/events
onLook.
player:getTown()
player:getGuid()

function getHouseByPlayerGUID(playerGUID)
for _, house in ipairs(Game.getHouses()) do
if house:getOwnerGuid() == playerGUID then
return house:getId()
end
end
return nil
end

good luck
 
Can you tell me exactly how to put this code?

data/events
onLook.
player:getTown()
player:getGuid()

function getHouseByPlayerGUID(playerGUID)
for _, house in ipairs(Game.getHouses()) do
if house:getOwnerGuid() == playerGUID then
return house:getId()
end
end
return nil
end

good luck
 
@Margolin

@Il Knight i would like to know aswell, ... data > events > scripts > player. but where on OnLook should it go? :)

events.xml
Code:
<event class="Player" method="onLook" enabled="1" />

scripts > player.lua
Code:
function Player:onLook(thing, position, distance)
local description = "You see " .. thing:getDescription(distance)

--// view players house if he got one onLook
if thing:getId() and isPlayer(thing:getId()) and thing:getHouse() then
   description = description .. " Owner of the house " ..  player:getHouse():getName() .. "."
end

self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

This should work.
 
Last edited:
lmao, edit the onlook function, you havent read those post anyways, you only want a fully working code and no opinions about it. That is pretty funny.
 
Back
Top