TFS 1.0: Direct house purchase with shop points

Allow players to directly purchase houses using shop points.
https://otland.net/threads/znote-aac-shop-house-offers.266507/
This commit is contained in:
Znote
2019-09-28 09:25:47 +02:00
parent 8a8baba9fc
commit 56050fcb29
4 changed files with 176 additions and 9 deletions

View File

@@ -11,7 +11,7 @@ function onThink(interval, lastExecution)
ON `po`.`player_id` = `p`.`id`
INNER JOIN `znote_shop_orders` AS `shop`
ON `p`.`account_id` = `shop`.`account_id`
WHERE `shop`.`type` IN(1,5,6)
WHERE `shop`.`type` IN(1,5,6,7)
GROUP BY `shop`.`id`
]])
-- Detect if we got any results
@@ -22,7 +22,8 @@ function onThink(interval, lastExecution)
"pending gender change (skip)",
"pending character name change (skip)",
"Outfit and addons",
"Mounts"
"Mounts",
"Instant house purchase"
}
repeat
local player_id = result.getDataInt(orderQuery, 'player_id')
@@ -92,6 +93,28 @@ function onThink(interval, lastExecution)
end
end
-- ORDER TYPE 7 (Direct house purchase)
if orderType == 7 then
served = true
local house = House(orderItemId)
-- Logged in player is not neccesarily the player that bough the house. So we need to load player from db.
local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
if buyerQuery ~= false then
local buyerName = result.getDataString(buyerQuery, "name")
result.free(buyerQuery)
if house then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
house:setOwnerGuid(orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
print("Process complete. [".. buyerName .."] has recieved house: ["..house:getName().."]")
else
print("Process canceled. Failed to load house with ID: "..orderItemId)
end
else
print("Process canceled. Failed to load player with ID: "..orderCount)
end
end
if not served then -- If this order hasn't been processed yet (missing type handling?)
print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
end

View File

@@ -12,7 +12,8 @@ function onSay(player, words, param)
"pending gender change (skip)",
"pending character name change (skip)",
"Outfit and addons",
"Mounts"
"Mounts",
"Instant house purchase"
}
print("Player: " .. player:getName() .. " triggered !shop talkaction.")
-- Create the query
@@ -69,6 +70,24 @@ function onSay(player, words, param)
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!")
end
end
-- ORDER TYPE 7 (Direct house purchase)
if orderType == 7 then
served = true
local house = House(orderItemId)
-- Logged in player is not neccesarily the player that bough the house. So we need to load player from db.
local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
if buyerQuery ~= false then
local buyerName = result.getDataString(buyerQuery, "name")
result.free(buyerQuery)
if house then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
house:setOwnerGuid(orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
print("Process complete. [".. buyerName .."] has recieved house: ["..house:getName().."]")
end
end
end
-- Add custom order types here