diff --git a/LUA/TFS_10/globalevent shopsystem/znoteshop.lua b/LUA/TFS_10/globalevent shopsystem/znoteshop.lua index 194e293..36c96e4 100644 --- a/LUA/TFS_10/globalevent shopsystem/znoteshop.lua +++ b/LUA/TFS_10/globalevent shopsystem/znoteshop.lua @@ -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 diff --git a/LUA/TFS_10/talkaction shopsystem/znoteshop.lua b/LUA/TFS_10/talkaction shopsystem/znoteshop.lua index dfc496a..44b7d0c 100644 --- a/LUA/TFS_10/talkaction shopsystem/znoteshop.lua +++ b/LUA/TFS_10/talkaction shopsystem/znoteshop.lua @@ -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 diff --git a/config.php b/config.php index ed543b4..c388f68 100644 --- a/config.php +++ b/config.php @@ -391,6 +391,19 @@ 'housesPerPlayer' => 1, 'requirePremium' => false, 'levelToBuyHouse' => 8, + // Instant buy with shop points + 'shopPoints' => array( + 'enabled' => true, + // SQM => points cost + 'cost' => array( + 1 => 10, + 25 => 15, + 60 => 25, + 100 => 30, + 200 => 40, + 300 => 50, + ), + ), ); // Leave on black square in map and player should get teleported to their selected town. @@ -936,7 +949,8 @@ type 5 = Buy outfit (put outfit id as itemid), (put addon id as count [0 = nothing, 1 = first addon, 2 = second addon, 3 = both addons]) type 6 = Buy mount (put mount id as itemid) - type 7+ = custom coded stuff + type 7 = buy house (hardcoded in the house system, type used for data log) + type 8+ = custom coded stuff */ $config['shop_offers'] = array( 1 => array( diff --git a/house.php b/house.php index 189efa9..ee70c9c 100644 --- a/house.php +++ b/house.php @@ -3,14 +3,23 @@ if ($config['log_ip']) { znote_visitor_insert_detailed_data(3); } -$house = (isset($_GET['id']) && (int)$_GET['id'] > 0) ? (int)$_GET['id'] : false; +$house = getValue($_GET['id']); if ($house !== false && $config['ServerEngine'] === 'TFS_10') { - $house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='$house';"); + $house_SQL = "SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='$house';"; + $house = mysql_select_single($house_SQL); $minbid = $config['houseConfig']['minimumBidSQM'] * $house['size']; if ($house['owner'] > 0) $house['ownername'] = user_name($house['owner']); - //data_dump($house, false, "Data"); + if ($config['houseConfig']['shopPoints']['enabled']) { + $house['points'] = $house['size']; + + foreach ($config['houseConfig']['shopPoints']['cost'] AS $cost_sqm => $cost_points) { + if ($cost_sqm < $house['size']) $house['points'] = $cost_points; + } + } + + //data_dump($house, false, "House data"); ////////////////////// // Bid on house logic @@ -85,6 +94,86 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') { } else echo "You may only bid on houses for characters on your account."; } + //////////////////////////////////////// + // Instantly buy house with shop points + if ($config['houseConfig']['shopPoints']['enabled'] + && isset($_POST['instantbuy']) + && $bid_char + && $house['owner'] == 0 + && isset($house['points'])) { + + $account_points = (int)$user_znote_data['points']; + + if ($account_points >= $house['points']) { + + $bid_char = (int)$bid_char; + $player = mysql_select_single("SELECT `id`, `account_id`, `name`, `level` FROM `players` WHERE `id`='$bid_char' LIMIT 1;"); + $pHouseCount = mysql_select_single("SELECT COUNT('id') AS `value` FROM `houses` WHERE ((`highest_bidder`='$bid_char' AND `owner`='$bid_char') OR (`highest_bidder`='$bid_char') OR (`owner`='$bid_char')) AND `id`!='".$house['id']."' LIMIT 1;"); + + if (user_logged_in() === true + && $player['account_id'] == $session_user_id + && $player['level'] >= $config['houseConfig']['levelToBuyHouse'] + && $pHouseCount['value'] < $config['houseConfig']['housesPerPlayer']) { + + $house_points = (int)$house['points']; + $house_id = $house['id']; + + // Remove points from account + mysql_update(" + UPDATE `znote_accounts` + SET `points` = `points`-{$house_points} + WHERE `account_id`={$session_user_id} + LIMIT 1; + "); + + // Give new ownership to house + mysql_update(" + UPDATE `houses` + SET `owner` = {$bid_char} + WHERE `id` = {$house_id} + LIMIT 1; + "); + + // Log purchase in znote_shop_logs and znote_shop_orders + $time = time(); + mysql_insert(" + INSERT INTO `znote_shop_logs` + (`account_id`, `player_id`, `type`, `itemid`, `count`, `points`, `time`) VALUES + ({$session_user_id}, {$bid_char}, 7, {$house_id}, 1, {$house_points}, {$time}) + "); + mysql_insert(" + INSERT INTO `znote_shop_orders` + (`account_id`, `type`, `itemid`, `count`, `time`) VALUES + ({$session_user_id}, 7, {$house_id}, {$bid_char}, {$time}) + "); + + // Reload house data + $house = mysql_select_single($house_SQL); + $minbid = $config['houseConfig']['minimumBidSQM'] * $house['size']; + if ($house['owner'] > 0) $house['ownername'] = user_name($house['owner']); + + // Congratulate user and tell them they still has to pay rent (if rent > 0) + ?> +
Congratulations!
+
You now own this house!
+
Remember to say !shop in-game to process your ownership!
+ 0): ?>
+
Keep in mind you still need to pay rent on this house, make sure you have enough bank balance to cover it!
+
+
Error:
+
Either your level is too low, or your player already have or is bidding on another house.
+
Your level: . Minimum level to buy house:
+
Your house/bid count: . Maximum house per player: .
+
Your account has available shop points.
+
You don't have enough shop points to instantly buy this house.
Go back to the house list and select a house for further details.
+include 'layout/overall/footer.php'; ?> \ No newline at end of file