Shadow Dan
Sh4dowDan
Script now working, big thanks to Ninja who made this script!
Tested on TFS 1.2 (100% working)
#GLOBALEVENT ======================================
data/globalevents/globalevents.xml
data/globalevents/scripts/cleanhouses.lua
#OLD ======================================
I can't make this script working for TFS 1.2
Any help would be really appreciated.
Tested on TFS 1.2 (100% working)
Code:
local config = {
days = 30, --- days to clean houses ---
log = true,
file = "data/logs/cleanhouses.txt"
}
local function doWriteLogFile(file, text)
local f = io.open(file, "a+")
if not f then
return false
end
f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")
f:close()
return true
end
function onSay(player, words, param)
local logs = "Houses cleaned:\n"
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")
if resultId == false then
logs = string.format("%sThere were no houses to clean.\n", logs)
else
repeat
local house = House(result.getNumber(resultId, "id"))
local playerName = result.getString(resultId, "playerName")
if house ~= nil then
logs = string.format("%sHouse: %s, Owner: %s\n", logs, house:getName(), playerName)
house:setOwnerGuid(0)
end
until not result.next(resultId)
result.free(resultId)
end
if config.log then
doWriteLogFile(config.file, logs)
end
return true
end
Code:
[14/07/2015 17:11:15] Houses cleaned:
There were no houses to clean.
[14/07/2015 17:11:17] Houses cleaned:
There were no houses to clean.
[14/07/2015 17:11:20] Houses cleaned:
There were no houses to clean.
data/globalevents/globalevents.xml
Code:
<globalevent type="startup" name="CleanHouses" script="cleanhouses.lua" />
Code:
local config = {
days = 30, --- days to clean houses ---
log = true,
file = "data/logs/cleanhouses.txt"
}
local function doWriteLogFile(file, text)
local f = io.open(file, "a+")
if not f then
return false
end
f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")
f:close()
return true
end
function onStartup()
local logs = "Houses cleaned:\n"
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")
if resultId == false then
logs = string.format("%sThere were no houses to clean.\n", logs)
else
repeat
local house = House(result.getNumber(resultId, "id"))
local playerName = result.getString(resultId, "playerName")
if house ~= nil then
logs = string.format("%sHouse: %s, Owner: %s\n", logs, house:getName(), playerName)
house:setOwnerGuid(0)
end
until not result.next(resultId)
result.free(resultId)
end
if config.log then
doWriteLogFile(config.file, logs)
end
return true
end
#OLD ======================================
I can't make this script working for TFS 1.2
Any help would be really appreciated.
Code:
local config = {
days = 30, --- days to clean houses ---
log = true,
file = "data/logs/cleanhouses.txt"
}
function onSay(player, words, param)
local house = db.storeQuery("SELECT `owner` ,`id` FROM `houses` WHERE `owner` IN (SELECT `id` FROM `players` WHERE `lastlogin` < UNIX_TIMESTAMP() - "..config.days.. "*24*60*60)")
local logs = " :: Houses cleaned:\n\n"
if house:getID() ~= -1 then
repeat
logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. getPlayerNameByGUID(house:getDataInt('owner')) .. "\n"
setHouseOwner(house:getDataInt('id'), 0)
until not house:next()
else
logs = logs .. "There were no houses to clean."
end
if config.log then
doWriteLogFile(config.file, logs)
end
saveServer()
return true
end
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/houses.lua:onSay
data/talkactions/scripts/houses.lua:10: attempt to index local 'house' (a number value)
stack traceback:
[C]: in function '__index'
data/talkactions/scripts/houses.lua:10: in function <data/talkactions/scripts/houses.lua:7>
Last edited: