Guest User

Untitled

a guest
Oct 15th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. local function getLastLoginDiff(name)
  2. local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
  3.     if res:getID() ~= -1 then
  4.         return os.time()-res:getDataInt('lastlogin')
  5.     end
  6. end
  7.  
  8.  
  9. local config = {
  10. timeInDays = 14,
  11. buyHouseCommand = "!buyhouse",
  12. delay = 10,
  13. delayStorage = 49676
  14. }
  15.  
  16. function onSay(cid, words, param, channel)
  17.     local pos,s,dir = getPlayerPosition(cid),getPlayerPosition(cid),getCreatureLookDirection(cid)
  18.     if config.delay ~= 0 and getPlayerStorageValue(cid,config.delayStorage) >= os.time() then
  19.         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.")
  20.     end
  21.     pos.x = dir == 1 and pos.x+1 or dir == 3 and pos.x-1 or pos.x
  22.     pos.y = dir == 0 and pos.y-1 or dir == 2 and pos.y+1 or pos.y
  23.     local abuse = config.delay ~= 0 and setPlayerStorageValue(cid,config.delayStorage,os.time()+config.delay)
  24.      
  25.     local house = getHouseFromPos(pos)
  26.     if house == false then
  27.         return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This ain't a house tile.")
  28.     end
  29.      
  30.     if getHouseOwner(house) == 0 then
  31.         return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This house has no owner. You can buy it on the normal way using " .. config.buyHouseCommand .. ".")
  32.     end
  33.      
  34.     local owner = getPlayerNameByGUID(getHouseOwner(house))
  35.     if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
  36.         return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
  37.     end
  38.      
  39.     if doPlayerRemoveMoney(cid,getHousePrice(house)) then
  40.         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) .. ".")
  41.     else
  42.         return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"You need "..getHousePrice(house).." gold coins to buy " .. getHouseName(house) .. ".")
  43.     end
  44. end
Add Comment
Please, Sign In to add comment