From b65c860b665ae136206f69efa550440d3f28db99 Mon Sep 17 00:00:00 2001 From: Znote Date: Sat, 9 Nov 2019 22:04:16 +0100 Subject: [PATCH] Fix #369 - Outfit offer type (5) supports 2 outfit ids. --- .../talkaction shopsystem/znoteshop.lua | 41 ++++++++++++------- .../Alternatives/znoteshop.lua | 29 +++++++++---- .../talkaction shopsystem/znoteshop.lua | 27 ++++++++---- .../globalevent shopsystem/znoteshop.lua | 33 ++++++++++----- .../talkaction shopsystem/znoteshop.lua | 29 +++++++++---- config.php | 13 ++---- shop.php | 23 ++++++++++- 7 files changed, 136 insertions(+), 59 deletions(-) diff --git a/LUA/TFS_02/talkaction shopsystem/znoteshop.lua b/LUA/TFS_02/talkaction shopsystem/znoteshop.lua index ada5e53..bd233e5 100644 --- a/LUA/TFS_02/talkaction shopsystem/znoteshop.lua +++ b/LUA/TFS_02/talkaction shopsystem/znoteshop.lua @@ -35,24 +35,37 @@ function onSay(cid, words, param) -- Get wheight local playerCap = getPlayerFreeCap(cid) local itemweight = getItemWeight(q_itemid, q_count) - if playerCap >= itemweight then - db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") - doPlayerAddItem(cid, q_itemid, q_count) - doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have recieved ".. q_count .." "..getItemName(q_itemid).."(s)!") - else - doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Need more CAP!") - end + if playerCap >= itemweight then + db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") + doPlayerAddItem(cid, q_itemid, q_count) + doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have recieved ".. q_count .." "..getItemName(q_itemid).."(s)!") + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Need more CAP!") + end end -- ORDER TYPE 5 (Outfit and addon) if q_type == 5 then served = true - -- Make sure player don't already have this outfit and addon - if not canPlayerWearOutfit(cid, q_itemid, q_count) then - db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") - doPlayerAddOutfit(cid,q_itemid,q_count) - doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") - else - doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + + local itemid = q_itemid + local outfits = {} + + if itemid > 1000 then + local first = math.floor(itemid/1000) + table.insert(outfits, first) + itemid = itemid - (first * 1000) + end + table.insert(outfits, itemid) + + for _, outfitId in pairs(outfits) do + -- Make sure player don't already have this outfit and addon + if not canPlayerWearOutfit(cid, outfitId, q_count) then + db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") + doPlayerAddOutfit(cid,outfitId,q_count) + doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + end end end diff --git a/LUA/TFS_03/talkaction shopsystem/Alternatives/znoteshop.lua b/LUA/TFS_03/talkaction shopsystem/Alternatives/znoteshop.lua index 18a19c5..a55833b 100644 --- a/LUA/TFS_03/talkaction shopsystem/Alternatives/znoteshop.lua +++ b/LUA/TFS_03/talkaction shopsystem/Alternatives/znoteshop.lua @@ -48,14 +48,27 @@ function onSay(cid, words, param) -- ORDER TYPE 5 (Outfit and addon) if q_type == 5 then served = true - -- Make sure player don't already have this outfit and addon - if not canPlayerWearOutfit(cid, q_itemid, q_count) then - local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") - result.free(delete) - doPlayerAddOutfit(cid,q_itemid,q_count) - doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") - else - doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + + local itemid = q_itemid + local outfits = {} + + if itemid > 1000 then + local first = math.floor(itemid/1000) + table.insert(outfits, first) + itemid = itemid - (first * 1000) + end + table.insert(outfits, itemid) + + for _, outfitId in pairs(outfits) do + -- Make sure player don't already have this outfit and addon + if not canPlayerWearOutfit(cid, outfitId, q_count) then + local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") + result.free(delete) + doPlayerAddOutfit(cid,outfitId,q_count) + doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + end end end diff --git a/LUA/TFS_03/talkaction shopsystem/znoteshop.lua b/LUA/TFS_03/talkaction shopsystem/znoteshop.lua index de54e9a..d71d3e0 100644 --- a/LUA/TFS_03/talkaction shopsystem/znoteshop.lua +++ b/LUA/TFS_03/talkaction shopsystem/znoteshop.lua @@ -58,13 +58,26 @@ function onSay(cid, words, param) -- ORDER TYPE 5 (Outfit and addon) if q_type == 5 then served = true - -- Make sure player don't already have this outfit and addon - if not canPlayerWearOutfit(cid, q_itemid, q_count) then - db.executeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") - doPlayerAddOutfit(cid,q_itemid,q_count) - doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") - else - doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + + local itemid = q_itemid + local outfits = {} + + if itemid > 1000 then + local first = math.floor(itemid/1000) + table.insert(outfits, first) + itemid = itemid - (first * 1000) + end + table.insert(outfits, itemid) + + for _, outfitId in pairs(outfits) do + -- Make sure player don't already have this outfit and addon + if not canPlayerWearOutfit(cid, outfitId, q_count) then + db.executeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") + doPlayerAddOutfit(cid,outfitId,q_count) + doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + end end end diff --git a/LUA/TFS_10/globalevent shopsystem/znoteshop.lua b/LUA/TFS_10/globalevent shopsystem/znoteshop.lua index 36c96e4..b00b231 100644 --- a/LUA/TFS_10/globalevent shopsystem/znoteshop.lua +++ b/LUA/TFS_10/globalevent shopsystem/znoteshop.lua @@ -65,16 +65,29 @@ function onThink(interval, lastExecution) -- ORDER TYPE 5 (Outfit and addon) if orderType == 5 then served = true - -- Make sure player don't already have this outfit and addon - if not player:hasOutfit(orderItemId, orderCount) then - db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";") - player:addOutfit(orderItemId) - player:addOutfitAddon(orderItemId, orderCount) - player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") - print("Process complete. [".. player:getName() .."] has recieved outfit: ["..orderItemId.."] with addon: ["..orderCount.."]") - else -- Already has outfit - player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") - print("Process canceled. [".. player:getName() .."] already have outfit: ["..orderItemId.."] with addon: ["..orderCount.."].") + + local itemid = orderItemId + local outfits = {} + + if itemid > 1000 then + local first = math.floor(itemid/1000) + table.insert(outfits, first) + itemid = itemid - (first * 1000) + end + table.insert(outfits, itemid) + + for _, outfitId in pairs(outfits) do + -- Make sure player don't already have this outfit and addon + if not player:hasOutfit(outfitId, orderCount) then + db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";") + player:addOutfit(outfitId) + player:addOutfitAddon(outfitId, orderCount) + player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") + print("Process complete. [".. player:getName() .."] has recieved outfit: ["..outfitId.."] with addon: ["..orderCount.."]") + else -- Already has outfit + player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + print("Process canceled. [".. player:getName() .."] already have outfit: ["..outfitId.."] with addon: ["..orderCount.."].") + end end end diff --git a/LUA/TFS_10/talkaction shopsystem/znoteshop.lua b/LUA/TFS_10/talkaction shopsystem/znoteshop.lua index 44b7d0c..9fbcfe0 100644 --- a/LUA/TFS_10/talkaction shopsystem/znoteshop.lua +++ b/LUA/TFS_10/talkaction shopsystem/znoteshop.lua @@ -47,14 +47,27 @@ function onSay(player, words, param) -- ORDER TYPE 5 (Outfit and addon) if q_type == 5 then served = true - -- Make sure player don't already have this outfit and addon - if not player:hasOutfit(q_itemid, q_count) then - db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") - player:addOutfit(q_itemid) - player:addOutfitAddon(q_itemid, q_count) - player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") - else - player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + + local itemid = q_itemid + local outfits = {} + + if itemid > 1000 then + local first = math.floor(itemid/1000) + table.insert(outfits, first) + itemid = itemid - (first * 1000) + end + table.insert(outfits, itemid) + + for _, outfitId in pairs(outfits) do + -- Make sure player don't already have this outfit and addon + if not player:hasOutfit(outfitId, q_count) then + db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") + player:addOutfit(outfitId) + player:addOutfitAddon(outfitId, q_count) + player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") + else + player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") + end end end diff --git a/config.php b/config.php index 2f3c5d1..a7232ad 100644 --- a/config.php +++ b/config.php @@ -999,26 +999,19 @@ ), 7 => array( 'type' => 5, - 'itemid' => 132, // Outfit ID + 'itemid' => [132, 140], // Outfit ID 'count' => 3, // Addon 0 = none, 1 = first, 2 = second, 3 = both - 'description' => "Nobleman with both addons", + 'description' => "Noble outfit with both addons", 'points' => 20, ), 8 => array( - 'type' => 5, - 'itemid' => 140, - 'count' => 3, - 'description' => "Noblewoman with both addons", - 'points' => 20, - ), - 9 => array( 'type' => 6, 'itemid' => 32, // Mount ID 'count' => 1, 'description' => "Gnarlhound mount", 'points' => 20, ), - 10 => array( + 9 => array( 'type' => 6, 'itemid' => 17, 'count' => 1, diff --git a/shop.php b/shop.php index 7b0e35a..a0fe9cc 100644 --- a/shop.php +++ b/shop.php @@ -44,6 +44,14 @@ if ($loggedin === true) { $verify = $data['points']; if ((int)$old_points == (int)$verify) die("2: Failed to equalize your points.". var_dump((int)$old_points, (int)$verify, $new_points, $expense_points)); + // If this is an outfit offer, convert array into an integer. + if ($buy['type'] == 5) { + if (is_array($buy['itemid'])) { + if (COUNT($buy['itemid']) == 2) $buy['itemid'] = ($buy['itemid'][0] * 1000) + $buy['itemid'][1]; + else $buy['itemid'] = $buy['itemid'][0]; + } + } + // Do the magic (insert into db, or change sex etc) // If type is 2 or 3 if ($buy['type'] == 2) { @@ -269,11 +277,22 @@ foreach ($shop_list as $key => $offer) { Points: Action: - $offers): ?> + $offers): + if (!is_array($offers['itemid'])) $offers['itemid'] = [$offers['itemid']]; + if (COUNT($offers['itemid']) > 2): ?> + + +

Error: Outfit offer don't support more than 2 outfits. configured. +
[]

+ + + - img + + img +