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

Lua A Globalevent that delivery house to player OTX 2.15 (TFS 0.3.7)

mano368

Senior Support Team Member
Staff member
Support Team
Joined
Sep 2, 2011
Messages
648
Solutions
46
Reaction score
296
Location
Brazil
Hello,

I need a script that delivers houses purchased via website(znote).

SQL:
local query = db.storeQuery("SELECT `id`, `owner`, `bid`, `bid_end`, `highest_bidder` FROM `houses` WHERE `bid_end` <= " .. os.time() .. " AND `highest_bidder` != 0 LIMIT 1;")

the script checks 2 conditions before delivering the house(remembering that there may be more than one house to be delivered, for example 10 houses):
1. if the player has the money in the bank.
2. if the auction time is less than the current time.
Then the house is delivered (setHouseOwner) and the money in the bank is deducted, and if the player does not have the money, the purchase is undone, resetting values such as:

SQL:
db.executeQuery("UPDATE `houses` SET `bid` = 0, `bid_end` = 0, `last_bid` = 0, `highest_bidder` = 0 WHERE `id` = " .. houseNumber .. ";")

Preferably this script will be onStartup type, which will deliver the house as soon as the SS, being even a way to prevent the player from being online and not find a way to bug the gold in the bank (withdraw) before receiving the house.
(system similar to the global, where you buy the house, wait for the bid time, and in the next ss you receive the house).

Obs.:
Lua:
bid = current offer(money)
bid_end = auction end time
last_bid = previous offer(money)
highest_bidder = id player current offer


- Can someone help me? even giving tips on how to write this script!
 
Last edited:
Solution
Why don’t you look how TFS got it? It’s almost exactly to what you have explained. Probably some lua adjusting needed but the core should stay the same.

Thank you Danger II! Works so beaultiful!!

If someone needs:

Lua:
function onStartup()

    -- 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 then
        repeat
            local house = getHouseInfo(result.getDataInt(resultId, "id"))
            if house then
                local highestBidder = result.getDataInt(resultId, "highest_bidder")
                local balance = result.getDataInt(resultId, "balance")
                local lastBid = result.getDataInt(resultId, "last_bid")
                if balance >= lastBid then
                    db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder)
                    setHouseOwner(house.id, highestBidder)
                    print("> House: Player ".. getPlayerNameByGUID(highestBidder) .." received the ".. getHouseName(house.id) ..".")
                end
                db.query("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house.id)
            end
        until not result.next(resultId)
        result.free(resultId)
    end
end

Added print() in the code to see if everything goes ok!

works.jpg
 
Last edited:
Back
Top