db.query("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId())
-- Check house auctions
local resultId = db.storeQuery("SELECT `id`, `highest_bidder`, `last_bid`, (SELECT `balance` FROM `players` WHERE `players`.`id` = `highest_bidder`) AS `balance` FROM `houses` WHERE `owner` = 0 AND `bid_end` != 0 AND `bid_end` < " .. os.time())
if resultId ~= false then
repeat
local house = House(result.getDataInt(resultId, "id"))
if house ~= nil then
local highestBidder = result.getDataInt(resultId, "highest_bidder")
local balance = result.getDataLong(resultId, "balance")
local lastBid = result.getDataInt(resultId, "last_bid")
if balance >= lastBid then
db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder)
house:setOwnerGuid(highestBidder)
end
end
until not result.next(resultId)
result.free(resultId)
end
if balance >= lastBid then
db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder)
house:setOwnerGuid(highestBidder)
end
Script that 'deliver' houses can execute every hour, but page set 'end of auction' date to 5 minutes before restart of OTS. To make it 'safe' you must rewrite that part:
because it works fine at server start when all player ARE offline. If you execute it every hour you must check if player is online [new owner]. If he is you must use LUA function to check if he has enough money on account and LUA function to remove that money (not 'query').PHP:if balance >= lastBid then db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder) house:setOwnerGuid(highestBidder) end
If you want 'unlock' money that is on bank account [reserved for house] you must 'save' OTS after you deliver houses [to change 'owner' of house in database].
---------------------------------------------------Hello sir Gesior.pl
I followed every step and left me all ok, but the question I have is how to change the NPC Banker, since all have their own banker NPC script.
You switch to a banker npc script for your recommend, and neither worked, gold always goes 0) :.
If you can help me I would be very grateful
Cheers
My first OTS that uses house auctions:
http://huntia.org/index.php?subtopic=houses&world=0&show=34
Added Bootstrap style, jQuery table sorter (houses list), better town selector (JS, faast) and IMAGES OF ALL HOUSES.
Maybe I will make it TFS 1.x compatible (my ots uses 'otserv' engine) and release new version.
Soon I will release new version (v4) of:
OpenTibia - OTClient that unpack map.otbm to .png files - v2.0
with option to 'generate house images' by 1 click.
if ($houses_town == $id)
if ( ($houses_town == $id) or ($firstTown == false) )

data/globalevents/scripts/startup.lua:9: attempt to call global 'House' (a table value)
elseif msgcontains(msg, 'balance') then
local bid = getPlayerBiddedMoney(cid)
if(bid > 0) then
npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold, ' .. bid .. ' gold is blocked for house auctioned by you.', cid)
else
npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
end
elseif msgcontains(msg, 'balance') then
local bid = getPlayerBiddedMoney(cid)
if(bid > 0) then
npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold, ' .. bid .. ' gold is blocked for house auctioned by you.', cid)
elseif getPlayerBalance(cid) >= 100000000 then
npcHandler:say('I think you must be one of the richest inhabitants in the world! Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
return true
elseif getPlayerBalance(cid) >= 10000000 then
npcHandler:say('You have made ten millions and it still grows! Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
return true
elseif getPlayerBalance(cid) >= 1000000 then
npcHandler:say('Wow, you have reached the magic number of a million gp!!! Your account balance is ' .. getPlayerBalance(cid) .. ' gold!', cid)
return true
elseif getPlayerBalance(cid) >= 100000 then
npcHandler:say('You certainly have made a pretty penny. Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
return true
else
npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
return true
end
transfer[cid] = msg
local arrayDenied = {"accountmanager", "rooksample", "druidsample", "sorcerersample", "knightsample", "paladinsample"}
if isInArray(arrayDenied, string.gsub(transfer[cid]:lower(), " ", "")) then
npcHandler:say('This player does not exist.', cid)
npcHandler.topic[cid] = 0
return true
end
I hope it will work fine on your OTSes. I made it some time ago and it was compatible with TFS 1.0 house auctions system [which is implemented in every TFS 1.0].
Houses list:
![]()
House page:
![]()
Houses are delivered after server restart. You must use auto-restarter [search in google] and configure in config.lua to restart server every day at X hour.
If you don't have this in config.lua of OTS, add it:
You can change hour to any other (0-23). Server will close itself at this hour (show messages about it before close like rl tibia server). You need auto-restarter script to start it again everytime.PHP:-- Server save -- NOTE: serverSaveHour is the hour of the day when the server save will occur, -- if you would rather save the server with intervals, disable server save and -- use autoSaveEachMinutes. serverSaveEnabled = "yes" serverSaveHour = 10 shutdownAtServerSave = "yes"
This is houses.php page with auctions [at top you can config auctions length]:
http://paste.ots.me/560433/text
You MUST use this Banker NPC script. It updates database every time you change balance of your bank account and don't let players buy houses for 0 gold coins (like it could with normal banker).
Banker NPC script:
http://paste.ots.me/560445/text
Check file data/globalevents/scripts/startup.lua , there should be this code (paste if it's not there):
PHP:-- Check house auctions local resultId = db.storeQuery("SELECT `id`, `highest_bidder`, `last_bid`, (SELECT `balance` FROM `players` WHERE `players`.`id` = `highest_bidder`) AS `balance` FROM `houses` WHERE `owner` = 0 AND `bid_end` != 0 AND `bid_end` < " .. os.time()) if resultId ~= false then repeat local house = House(result.getDataInt(resultId, "id")) if house ~= nil then local highestBidder = result.getDataInt(resultId, "highest_bidder") local balance = result.getDataLong(resultId, "balance") local lastBid = result.getDataInt(resultId, "last_bid") if balance >= lastBid then db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder) house:setOwnerGuid(highestBidder) end end until not result.next(resultId) result.free(resultId) end
-- EDIT, REASON: forgot to paste LUA fix (1 line) --
In LUA under:
Add:PHP:if balance >= lastBid then db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder) house:setOwnerGuid(highestBidder) end
After changes it should be:PHP:db.query("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId())
PHP:-- Check house auctions local resultId = db.storeQuery("SELECT `id`, `highest_bidder`, `last_bid`, (SELECT `balance` FROM `players` WHERE `players`.`id` = `highest_bidder`) AS `balance` FROM `houses` WHERE `owner` = 0 AND `bid_end` != 0 AND `bid_end` < " .. os.time()) if resultId ~= false then repeat local house = House(result.getDataInt(resultId, "id")) if house ~= nil then local highestBidder = result.getDataInt(resultId, "highest_bidder")local balance = result.getDataLong(resultId, "balance")local lastBid = result.getDataInt(resultId, "last_bid") if balance >= lastBid then db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder) house:setOwnerGuid(highestBidder) end -- here new code: db.query("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId()) end until not result.next(resultId) result.free(resultId) end
In the house bid in the src, there's already a way to remove money from the player balance db, first check if the money is in the player balance, otherwise, it takes it from the depot of the city the house belongs to.Hi Gesior,
Im trying to get this to work with a Nostalrius server. Im using your script for NPC Banker. Tried to paste the script into an NPC file and named it Banker. Added behavior so I can greet it with hello, because he wasnt responding, which caused it to just not load.
Created a file named gen-banker.ndb but that wouldnt work either, using the gen-bank.ndb file works that came with the server but all that script would do is exchange coins.
Any help or direction would be appreciated. Thank you again for the plugin