• 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.

[LUA FUNCTION] cleanHousesByIdleTime(idletime)

norrow

Member
Joined
Dec 16, 2012
Messages
129
Reaction score
7
Location
Poland
This function can make a throw to functions.lua in lib
Lua:
function cleanHousesByIdleTime(idletime)
	local days = tonumber(idleTime)
	if(not days or days <= 0) then 
		return 0
	end
	local checkTime = os.time() - days*3600*24
	local result, i = db.getResult('SELECT `owner`, `world_id`, (SELECT `lastlogin` FROM `players` AS `b` WHERE `b`.`id`=`a`.`owner` AND `b`.`world_id`=`a`.`world_id`) AS `loggedLast` FROM `houses` AS `a` WHERE `loggedLast`<='..checkTime), 0
	if(result:getID() == -1) then
		return 0
	end
	repeat
		if(setHouseOwner(result:getDataInt('id')), 0, true) then
			i = i + 1
		end
	until not(result:next())
	result:free()
	return i
end
Talkactions
Lua:
 function onSay(cid, words, param, channel)
	if(param:len() <= 0) then
		doPlayerSendCancel(cid, 'This command requires a numeric parameter - number of days. If any player has not logged on since the amount of days, his house will be cleared.')
		return true
	end
	local days = tonumber(param)
	if(not days or days <= 0) then
		doPlayerSendCancel(cid, 'Written parameter is not a sufficient number of.')
		return true
	end
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'has been cleared ' .. cleanHousesByIdleTime(param) .. ' the houeses of the players who hasnt log in since' .. days .. ' days.')
	return true
end
 
Last edited:
Back
Top