• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua buy house

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,209
Solutions
2
Reaction score
154
LUA:
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

This script does not check if player is facing a door, how to fix it?

tfs 1.2
 
Solution
You are calling the method getNextPosition(player:getDirection()) from position but not storing it. Should not be:
position = position:getNextPosition(player:getDirection())

and why repeat the tile verification?


Try this:
LUA:
local position = player:getPosition():getNextPosition(player:getDirection())

local tile = Tile(position)
local house = tile:getHouse()
if tile and house then
    for k, door in ipairs(house:getDoors()) do
        if door:getPosition() == position then
            -- Do the logic buy part here
            return true
        end
    end
end

player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
return false


You are calling the method getNextPosition(player:getDirection()) from position but not storing it. Should not be:
position = position:getNextPosition(player:getDirection())

and why repeat the tile verification?


Try this:
LUA:
local position = player:getPosition():getNextPosition(player:getDirection())

local tile = Tile(position)
local house = tile:getHouse()
if tile and house then
    for k, door in ipairs(house:getDoors()) do
        if door:getPosition() == position then
            -- Do the logic buy part here
            return true
        end
    end
end

player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.")
return false


 
Solution
Back
Top