• 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 buy house

Status
Not open for further replies.

WSouls

New Member
Joined
Aug 5, 2010
Messages
51
Reaction score
1
when u use it at an active house it works correctly --not letting you buy the house (works)
when you use it at an inactive house w/ enough gold to buy it, it always says --sends cancel msg you do not have enough gp & it removes your gp
when you use it at an inactive house w/o enough gold it says -- it doesnt remove any gold and it also sends the cancel message
the check if you own a house doesn't work(red code) it doesnt matter if you own a house are not you still get the above messages if you test the same scenarios

Code:
local function getLastLoginDiff(name)
local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
    if res:getID() ~= -1 then
        return os.time()-res:getDataInt('lastlogin')
    end
end

local config = {
timeInDays = 30,
delay = 10,
delayStorage = 1210
}

function onSay(cid, words, param, channel)
    local pos,s,dir = getPlayerPosition(cid),getPlayerPosition(cid),getCreatureLookDirection(cid)
    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() .. " more 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 = getHouseFromPos(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 the normal way using alana res.")
    end
    
    local owner = getPlayerNameByGUID(getHouseOwner(house))
    if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
        return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
    end
    
    if doPlayerRemoveMoney(cid,getHousePrice(house)) and [COLOR="red"]not getHouseByPlayerGUID(getPlayerGUID(cid))[/COLOR] 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 " .. getHousePrice(house) .. ".")
    else
        return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"You need "..getHousePrice(house).." gold coins to buy " .. getHouseName(house) .. ".")
    end
end
 
Status
Not open for further replies.
Back
Top