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

[GESIOR2012] Houses auctions on WWW for TFS 1.0

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,967
Solutions
99
Reaction score
3,383
Location
Poland
GitHub
gesior
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:
houseauction2.PNG


House page:
houseauction1.PNG

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:
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"
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.
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:
PHP:
                if balance >= lastBid then
db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder)
house:setOwnerGuid(highestBidder)
end
Add:
PHP:
db.query("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId())
After changes it should be:
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
 
Last edited:
Really cool, but when i was uploading the pictures into the house File my server got really laggy. So I'm unable to use the system. How can i put the images in another location like the same way you did it with the ShopItems/Outfit Images:

Code:
$config['site']['item_images_url'] = 'http://item-images.ots.me/960/';
 
If you write !leavehouse and restart server with save house is again you after restart. So you have to update when player leavehouse bid tables in database are update to 0. So if someone or Gesior can make !leavehouse script with this update ;p
 
Anyway who have /\ this problem:
db.query("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId())

And you have to add required lvl to this script cause 8 lvl can buy house...
 
I've got an issue where after the auction is over..
Players get there houses and all, but there banker still tells them that there money is being held for auction.
 
Last edited:
In LUA under:
PHP:
                if balance >= lastBid then
                   db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder)
                   house:setOwnerGuid(highestBidder)
end
Add:
PHP:
db.query("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId())
After changes it should be:
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
 
Last edited:
Lua fix, house:setOwnerGuid(highestBidder)
 
Problem.

Player bids, It says "The house is currently being auctioned. The highest bid so far is 11111 gold and has been submitted by Torek. Auction will end at Mar 28 2014, 18:31:39"

Someone else bids it still says Torek is bidding



I have 600k on my bank balance and max bid is 11k I bid 15k and get this:


Your offer of 15000 gold is too low.



It is using last_bid to get the bids and it always stand at 1 gold? so I changed it from getlast_bid to getbid.


It now shows the correct bids but will it work?
 
Last edited:
Even if the Bid of Torek is 11k right now, it's still possible that he entered let's say 1kk for bidding. So even if the current highest bid is 11k and you put 15k, it will automatically change Torek's to 15001 gp since he set aside 1kk for bidding. And it will tell you that your offer of 15k is too low.
 
Problem.

Player bids, It says "The house is currently being auctioned. The highest bid so far is 11111 gold and has been submitted by Torek. Auction will end at Mar 28 2014, 18:31:39"

Someone else bids it still says Torek is bidding



I have 600k on my bank balance and max bid is 11k I bid 15k and get this:


Your offer of 15000 gold is too low.



It is using last_bid to get the bids and it always stand at 1 gold? so I changed it from getlast_bid to getbid.


It now shows the correct bids but will it work?
Don't change anything. I got no idea if it will work after changes. Tibia houses auction system works like e-bay, not like real world auctions. It hides real highest bid.
Why? Because in real world auctions take few minutes - in internet few days. When someone offers 1.000$ for car and you are ready to pay 10.000$ you don't say '10000'. You say 1.100$ (or 1.001$ :) ).
That's why in internet you offer highest amount you can pay and 'system' will hide it and overbid other offers.
 
But, lets say I want it to show the real highest bid directly?
 
Then you must rewrite part of code that set 'bid' and 'last_bid' when player make a bid.
It must set both values to same amount. Then it will show highest bid on every page of auctions system.
 
Back
Top