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

Lua TFS 1.3 getHouseOwnerNameById

Senzubean

Active Member
Joined
Aug 24, 2017
Messages
23
Reaction score
36
How can I get the name of the owner of a house? I have this script below but ownerName return false and houseOwnerId returns the player id. I'm new at lua so I would appreciate a full example. Later I will try to make it a function.

I'm using this inside a action script when a lever is pulled.

Code:
function onUse(Player, item, fromPosition, itemEx, toPosition, isHotkey)

    if item.itemid == 1945 then

        local tile           = Tile(Position(1185, 1253, 7))
        local houseTile      = tile:getHouse()
        local houseId            = houseTile:getId()
        local houseOwnerId   = getHouseOwner(houseId)
        local ownerName    = getPlayerName(houseOwnerId)
     
        Player:sendTextMessage(MESSAGE_EVENT_ORANGE, string.format("House name is %s", ownerName))
        item:transform(1946)

    elseif item.itemid == 1946 then
        item:transform(1945)
        end
end
 
Last edited:
Solution
you can put this in your lib to get house owner name
Lua:
function House.getOwnerName(self)
    local guid = self:getOwnerGuid()
    local id = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = ".. guid)
    if not id then
        return ""
    end
    local name = result.getString(id, "name")
    result.free(id)
    return name
end

then all you have to do once you get the house from tile:getHouse() you just use house:getOwnerName()
Lua:
function onUse(Player, item, fromPosition, itemEx, toPosition, isHotkey)
    local tile = Tile(1185, 1253, 7)
    local house = tile:getHouse()
    if house then
        player:sendTextMessage(MESSAGE_EVENT_ORANGE, "House owner's name is ".. house:getOwnerName())
    end
    return...
Not sure what you want. You explained very poorly.

If you want a lever that shows the house name from the player:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local house = player:getHouse()
   if not house then
       -- the player doesn't own a house.
       return false
   end

   print(house:getName()) -- print house name

   local itemId = item.itemid
   item:transform(itemId == 1946 and 1945 or 1946)
   return true
end

If is not what you want try explain better.
 
you can put this in your lib to get house owner name
Lua:
function House.getOwnerName(self)
    local guid = self:getOwnerGuid()
    local id = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = ".. guid)
    if not id then
        return ""
    end
    local name = result.getString(id, "name")
    result.free(id)
    return name
end

then all you have to do once you get the house from tile:getHouse() you just use house:getOwnerName()
Lua:
function onUse(Player, item, fromPosition, itemEx, toPosition, isHotkey)
    local tile = Tile(1185, 1253, 7)
    local house = tile:getHouse()
    if house then
        player:sendTextMessage(MESSAGE_EVENT_ORANGE, "House owner's name is ".. house:getOwnerName())
    end
    return item:transform(item:getId() == 1945 and 1946 or 1945)
end
 
Solution
Not sure what you want. You explained very poorly.

Sorry I couldnt edit my post due anti-grief system of otland, to clarify what i wanted. I want to get the owners name of the house not the name of the house. Like the name that is shown when looking on the door "this house is owned by ...".
 
Back
Top