• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Clean Non-Active Houses for 0.2+

BeniS

Advanced OT User
Senator
Joined
Aug 8, 2009
Messages
1,850
Reaction score
189
Location
New Zealand
I edited Adams code for (Goosio OT) 0.3+ to work in 0.2+ distros (a lot of editing).

It will clear the house and reset the owner of the house to nobody if the player has been inactive for a certain amount of time (10 days is the default set). Sorry for the messy code haha

safelist values are the id of certain houses you don't want to check.

days number of days a player has to be inactive to clear the house (10 days).

Lua:
--Adam 2008 Edited by Teh Maverick to work in 0.2+

--Config
local safelist = {1,2}
local days = 10*3600*24

--Leave these
local ownerr = 0
local hid = 0
local pid = 0
local lastlogin = 0
local cleared = 0
local name = ""
local house = nil
local player = nil
local playerID = nil
local cur = nil
local cur2 = nil

function onSay(cid, words, param)
if getPlayerGroupId(cid) > 2 then
    pdelete = "Inactive Players With Houses:\n\n"
    t=os.date('*t')
	dofile("./config.lua")
	env = assert(luasql.mysql())
	con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	local houseID = assert(con:execute("SELECT `owner` FROM `houses`  WHERE `owner` > 0"))
	local houseCount = numRows(houseID)
	cur = assert(con:execute("SELECT `owner`, `id` FROM `houses` WHERE `owner` > 0"))
	house  = cur:fetch({}, "a")
	cur:close()
	
  if(houseCount >= 1) then
	for owner, id in rows(con, "SELECT `owner`, `id` FROM `houses` WHERE `owner` > 0 ORDER BY `id` DESC;") do
        ownerr = tonumber(owner)
        hid = tonumber(id)
		playerID = assert(con:execute("SELECT `id` FROM `players` WHERE `id` = '"..ownerr.."'  "))
		cur2 = assert(con:execute("SELECT `id`,`name`,`lastlogin` FROM `players` WHERE `id` = '"..ownerr.."'  "))
		player = cur2:fetch({}, "a")
		cur2:close()
			
            if(numRows(playerID) >= 1) then
                lastlogin = player.lastlogin
                pid = player.id
                name = player.name
                time=os.time(t) - lastlogin
                offline = time - days
				
                if offline >= 0 then
                    pdelete = pdelete.."House #"..hid.." owned by "..name.."\n"
                    if isInArray(safelist,hid) == FALSE then                    
                        setHouseOwner(hid, 0)
						cleared=cleared+1
                    end
                end
				player = nil
            end
    end
	  if cleared < 1 then
		pdelete = "No players have been inactive.\n"
	  end
     doShowTextDialog(cid, 5958, pdelete.."\n"..cleared.." Houses cleared.")
  else
     doPlayerSendCancel(cid, "No one owns any houses")
	 print('No one owns any houses')
  end
  house = nil
  con:close()
  env:close()
end
return TRUE
end

Add this to your talkactions.xml:
Lua:
<talkaction words="/cleanhouses" script="houseclean.lua"/>

Make sure you have this code in your global.lua file:

Lua:
function numRows(cursor)
	local row = cursor:fetch()
	local rows = 0
	while row do
		rows = rows + 1
		row = cursor:fetch()
	end
	cursor:close()
	return rows
end

Example:
23uoqiq.jpg


2yopgsp.jpg


Should work fine, though I haven't done a lot of testing. post any bugs you find any.

Change Log:
  • Fixed a minor bug.
  • Added a counter, that counts how many houses were cleared and displays it in the window.

EDIT: Here is the 0.3+ script written by Adam for Goosio OT credits to him for this:
Lua:
--Adam 2008

--Goosio OT

local safelist = {1,2}

function onSay(cid, words, param)
if getPlayerGroupId(cid) > 2 then
    pdelete = "Inactive Players With Houses:\n\n"
    days = 10*3600*24
    t=os.date('*t')
    local house = db.getResult("SELECT `owner`,`id` FROM `houses`")
    if(house:getID() ~= -1) then
        while (true) do
        local owner = house:getDataInt("owner")
        local hid = house:getDataInt("id")
            local player = db.getResult("SELECT `id`,`name`,`lastlogin` FROM `players` WHERE `id` = '"..owner.."'  ")
            if(player:getID() ~= -1) then
                local lastlogin = player:getDataInt("lastlogin")
                local pid = player:getDataInt("id")
                local name = player:getDataString("name")
                time=os.time(t) - lastlogin
                offline = time - days
                if offline >= 0 then
                    pdelete = pdelete.."House #"..hid.." owned by "..name.."\n"
                    if isInArray(safelist,hid) == FALSE then                    
                        setHouseOwner(hid, 0)
                    end
                end
            player:free()
            end
            if not(house:next()) then
                break
            end
        end
            
        house:free()    
        doShowTextDialog(cid, 5958, pdelete)
    else
        doPlayerSendCancel(cid, "Error.")
    end
end
return TRUE
end
 
Last edited:
That's nice, thanks for the release.
 
Thanks :p hope its useful to the few people still using 0.2+

0.2+ rox forever!! :D
 
Good script :)

You can add the creation of the log - here you have a command doWriteLogFile (file, text)

I could do that for 0.3+ but I actually wrote this one for 0.2+ distros so doWriteLogFile (file, text) won't work ;D its a good idea tho I may add it sometime using:
Lua:
Log = io.open("data/logs/houses.txt", "a+")
Log:write("Text")
Log:close()
for 0.2+ :p
 
Back
Top