JoseluisGGR

Untitled

Feb 10th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. this to the xml
  2. -------------
  3. <talkaction words="!cleanhouses" script="cleanhouse.lua" />
  4. -------------
  5.  
  6.  
  7.  
  8. and this on scripts folder called "cleanhouse.lua"
  9. -------------
  10. local config = {
  11. days = 1, --- days to clean houses ---
  12. log = true,
  13. file = "data/logs/cleanhouses.txt"
  14. }
  15.  
  16. local function doWriteLogFile(file, text)
  17. local f = io.open(file, "a+")
  18. if not f then
  19. return false
  20. end
  21.  
  22. f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")
  23. f:close()
  24. return true
  25. end
  26.  
  27. function onSay(player, words, param)
  28. local logs = "Houses cleaned:\n\n"
  29. local resultId = db.storeQuery("SELECT `h`.`id` AS `id`, `p`.`name` AS `playerName` FROM `houses` AS `h` LEFT JOIN `players` AS `p` ON `p`.`id` = `h`.`owner` WHERE `p`.`lastlogin` < UNIX_TIMESTAMP() - " .. config.days .. " * 24 * 60 * 60")
  30. if resultId == false then
  31. logs = string.format("%sThere were no houses to clean.", logs)
  32. else
  33.  
  34. repeat
  35. local house = House(result.getNumber(resultId, "id"))
  36. local playerName = result.getString(resultId, "playerName")
  37. if house ~= nil then
  38. logs = string.format("%sHouse: %s, Owner: %s\n", logs, house:getName(), playerName)
  39. house:setOwnerGuid(0)
  40. end
  41.  
  42. until not result.next(resultId)
  43. result.free(resultId)
  44. end
  45.  
  46. if config.log then
  47. doWriteLogFile(config.file, logs)
  48. end
  49.  
  50. player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "House were cleaned.")
  51. return true
  52. end
  53. -------------
Advertisement
Add Comment
Please, Sign In to add comment