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

TalkAction Buy inactive houses

Summ

(\/)(;,,;)(\/) Y not?
Staff member
Global Moderator
Joined
Oct 15, 2008
Messages
4,152
Solutions
12
Reaction score
1,107
Location
Germany :O
Hi

Request: http://otland.net/f132/getting-house-83042/ by Sherlok

Script by me. ;d
Just stay infront of a house like with !buyhouse and if the owner is inactive for more than x days you will be able to buy the house.


Features:
•Anti abuse (you can set waiting period between uses of the command)
•if house owner is inactive for more than x days you can buy the house for real price.
•Feel free to remove the messages like: ^^
doPlayerSendCancel(cid,"This ain't a house tile.")

Script:
PHP:
local function getLastLoginDiff(name)
local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
	if res:getID() ~= -1 then
		return os.time()-res:getDataInt('lastlogin')
	end
end

local config = {
timeInDays = 14,
buyHouseCommand = "!buyhouse",
delay = 10,
delayStorage = 49676
}

function onSay(cid, words, param, channel)
	local pos,s,dir = getPlayerPosition(cid),getPlayerPosition(cid),getCreatureLookDirection(cid)
	if config.delay ~= 0 and getPlayerStorageValue(cid,config.delayStorage) >= os.time() then
		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.")
	end
	pos.x = dir == 1 and pos.x+1 or dir == 3 and pos.x-1 or pos.x
	pos.y = dir == 0 and pos.y-1 or dir == 2 and pos.y+1 or pos.y
	local abuse = config.delay ~= 0 and setPlayerStorageValue(cid,config.delayStorage,os.time()+config.delay)
	
	local house = getHouseFromPos(pos)
	if house == false then
		return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This ain't a house tile.")
	end
	
	if getHouseOwner(house) == 0 then
		return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"This house has no owner. You can buy it on the normal way using " .. config.buyHouseCommand .. ".")
	end
	
	local owner = getPlayerNameByGUID(getHouseOwner(house))
	if not(getLastLoginDiff(owner) >= config.timeInDays*24*60*60) then
		return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,owner.." is not inactive.")
	end
	
	if doPlayerRemoveMoney(cid,getHousePrice(house)) then
		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) .. ".")
	else
		return doSendMagicEffect(s,2) and doPlayerSendCancel(cid,"You need "..getHousePrice(house).." gold coins to buy " .. getHouseName(house) .. ".")
	end
end

Talkactions.xml:
HTML:
	<talkaction words="/inactive" event="script" value="inactivehouses.lua"/>

Config:
timeInDays => Time in days the owner needs to be inactive
buyHouseCommand => the command which is used for buying house, because it is used in the script's messages
delay => anti abuse. the time the player needs to wait between using this command (can be turned of by setting it to 0)
delayStorage => unused storage value for anti abuse, isn't needed if delay is = 0

Have fun with the script.
Feel free to
Rep+

~Rhux
 
You just stand in front of a house door and say !inactive and then the script checks if the house owner is inactive for more than 14 day and if yes you buy the house for the real house price.

I wanted to make a screenshot but my computer crashed everytime i opened paint o_O
 
Nice, but maybe first check if player is inactive, next, if new owner have money needed to buy house and later other options? :D

Thanks, rep++ :D
 
Why not do a automatic house cleaner or something?
Would be much better.
 
Well
1; It was requested to be a talkaction.
2; Thats already released.

3; I will try to combine this script with normal !buyhouse command if I have more time, cuz there are many tests at school now..
 
can you make a script that works like this, you say !inactive and a list comes with inactive players and how many sqm there house is and in witch city the house is and how much the house cost example "Blackish, 155sqm, Thais, 579570"
 
Yes I can.
Thanks for idea I will do for my server ;d
 
Ok did your requested script.
Just add as talkaction.

PHP:
function getLastLoginDiff(name)
	if type(name) ~= "string" then
		return name
	end
	
	local res = db.getResult("SELECT `lastlogin` FROM `players` WHERE `name` = '"..name.."';")
	if res:getID() ~= -1 then
		return os.time()-res:getDataInt('lastlogin')
	end
end

function onSay(cid, words, param, channel)
	local towns,houses = {1},{}
	local text = "House - Size - Town - Price\n\n"
	for town = 1, #towns do
		for _, house in pairs(getTownHouses(town)) do
			table.insert(houses,house)
		end
	end
	for i = 1, #houses do
		local house = houses[i]
		local owner = getHouseOwner(house) ~= 0 and getPlayerNameByGUID(getHouseOwner(house)) or 1
		
		if getLastLoginDiff(owner) >= 14*24*60*60 then
			text = text .. getHouseName(house) .. " - " .. getHouseTilesCount(house) .. " - " .. getTownName(getHouseTown(house)) .. " - " .. getHousePrice(house) .. "\n"
		end
	end
	if text == "House - Size - Town - Price\n\n" then
		text = text .. "No owner of a house is inactive."
	end
	
	doPlayerPopupFYI(cid,text)
	return true
end
 
kk great script but cant u fix it like this :p

urs have on my server (Unnamed House #127-50-Lighning City- 44000) witch is good but can u fix it like this


"Blackish
Unnamed House #127-50-Lighning City- 44000" also




1953 is the itemid
 
Bump, seems like players can buy many houses with this script, you should fix that.
 
@Summ Could you add to config max houses per account and message cancel "You can't buy more than x houses."
 
This could easily be configured to run as a global event, like once a day, I tried writing one of these once but I guess my sql is a bit rusty hehe
 
Last edited:
This was written like this on purpose, so you do not lose your house if you are inactive instantly, but only if someone is interested in buying the house.
 
Back
Top