function onUse(cid, item, fromPosition, itemEx, toPosition)
if not getConfigInfo('buyableAndSellableHouses') then
return false
end
local house = getHouseFromPos(getCreatureLookPosition(cid))
if not house or getTileThingByType(getCreatureLookPosition(cid), ITEM_TYPE_DOOR).uid < 1 then
doPlayerSendCancel(cid, "You have to be looking at door of flat you would like to purchase.")
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
if not getHouseInfo(house).guildHall then
if getHouseByPlayerGUID(getPlayerGUID(cid)) then
doPlayerSendCancel(cid, "You already rent another house.")
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
--[[ FIXME: Houses/account limit
local accountHouses = getConfigInfo('housesPerAccount')
if accountHouses > 0 and getHousesCount(getPlayerAccountId(cid)) >= accountHouses
doPlayerSendCancel(cid, "You may own only " .. accountHouses .. " house" .. (accountHouses ~= 1 and "s" or "") .. " per account.")
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end]]
if getConfigInfo('houseNeedPremium') and not isPremium(cid) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUNEEDPREMIUMACCOUNT)
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
local levelToBuyHouse = getConfigInfo('levelToBuyHouse')
if getPlayerLevel(cid) < levelToBuyHouse then
doPlayerSendCancel(cid, "You have to be at least Level " .. levelToBuyHouse .. " to purchase a house.")
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
else
if getPlayerGuildId(cid) == 0 or getPlayerGuildLevel(cid) ~= GUILDLEVEL_LEADER then
doPlayerSendCancel(cid, "You have to be at least a guild leader to purchase a hall.")
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
-- FIXME: Only 1 GH per guild
end
if getHouseOwner(house) > 0 then
doPlayerSendCancel(cid, "This flat is already owned by someone else.")
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
setHouseOwner(house, getPlayerGUID(cid))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have successfully bought this " .. (getHouseInfo(house).guildHall and "hall" or "house") .. ", remember to leave money at " .. (getHouseInfo(house).guildHall and "guild owner " or "") .. (getConfigInfo('buyableAndSellableHouses') and "bank or " or "") .. "depot of this town for rent.")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
return true
end