therrax
Member
- Joined
- Jul 12, 2012
- Messages
- 262
- Solutions
- 1
- Reaction score
- 11
Hi.
I am looking for buyhouse command, which allow one account to have one house. And so that the player did not create a new account for new house. (IP Block)
Can somebody help me to edit that 2 scripts?
buyhouse command:
buyinactivehouse
I am looking for buyhouse command, which allow one account to have one house. And so that the player did not create a new account for new house. (IP Block)
Can somebody help me to edit that 2 scripts?
buyhouse command:
Code:
function onSay(cid, words, param)
local housePrice = configManager.getNumber(configKeys.HOUSE_PRICE)
if housePrice == -1 then
return true
end
local player = Player(cid)
if player:getPremiumDays() <= 0 then
player:sendCancelMessage("You need a premium account.")
return false
end
local position = player:getPosition()
position:getNextPosition(player:getDirection())
local house = House(getTileHouseInfo(position))
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 getHouseByPlayerGUID(player:getGuid()) 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_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.")
return false
end
Code:
local function getLastLoginDiff(name)
local res = db.storeQuery("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
if res then
xres = result.getDataString(res, 'lastlogin')
result.free(res)
return os.time()-xres
end
return false
end
local config = {
timeInDays = 21,
buyHouseCommand = "!buyhouse",
delay = 10,
delayStorage = 49676
}
function onSay(cid, words, param, channel)
local pos,s,dir = getPlayerPosition(cid),getPlayerPosition(cid),Creature(cid):getDirection()
if config.delay ~= 0 and getPlayerStorageValue(cid,config.delayStorage) >= os.time() then
return doSendMagicEffect(pos,2) and doPlayerSendCancel(cid,"You can only use this command every " .. config.delay .. " seconds. You have to wait " .. getPlayerStorageValue(cid,config.delayStorage)-os.time() .. " seconds.")
end
pos.x = dir == 1 and pos.x+1 or dir == 3 and pos.x-1 or pos.x
pos.y = dir == 0 and pos.y-1 or dir == 2 and pos.y+1 or pos.y
local abuse = config.delay ~= 0 and setPlayerStorageValue(cid,config.delayStorage,os.time()+config.delay)
local house = getTileHouseInfo(pos)
if house == false then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This ain't a house tile.")
end
if getHouseOwner(house) == 0 then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This house has no owner. You can buy it on the normal way using " .. config.buyHouseCommand .. ".")
end
local owner = getPlayerNameByGUID(getHouseOwner(house))
if owner then -- checks if there is an owner in the first place
if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
end
end
if doPlayerRemoveMoney(cid,(configManager.getNumber(configKeys.HOUSE_PRICE) * Tile(pos):getHouse():getTileCount())) then
return doSendMagicEffect(s,13) and setHouseOwner(house, getPlayerGUID(cid)) and doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,owner .. " has been inactive for more than " .. config.timeInDays .. " days.\nYou bought " .. getHouseName(house) .. " for " .. (configManager.getNumber(configKeys.HOUSE_PRICE) * Tile(pos):getHouse():getTileCount()) .. ".")
else
return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"You need "..(configManager.getNumber(configKeys.HOUSE_PRICE) * Tile(pos):getHouse():getTileCount()).." gold coins to buy " .. getHouseName(house) .. ".")
end
end