Globalevent shop: Confirm player has enough available slots

This commit is contained in:
Znote 2019-09-15 22:05:32 +02:00
parent e69021e01c
commit 7f1a4af7d2

View File

@ -40,13 +40,22 @@ function onThink(interval, lastExecution)
-- ORDER TYPE 1 (Regular item shop products) -- ORDER TYPE 1 (Regular item shop products)
if orderType == 1 then if orderType == 1 then
served = true served = true
local itemType = ItemType(orderItemId)
-- Get wheight -- Get wheight
if player:getFreeCapacity() >= ItemType(orderItemId):getWeight(orderCount) then if player:getFreeCapacity() >= itemType:getWeight(orderCount) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";") local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
player:addItem(orderItemId, orderCount) -- variable = (condition) and (return if true) or (return if false)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. orderCount .. " x " .. ItemType(orderItemId):getName() .. "!") local needslots = itemType:isStackable() and math.floor(orderCount / 100) + 1 or orderCount
print("Process complete. [".. player:getName() .."] has recieved " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".") if backpack ~= nil and backpack:getEmptySlots(false) >= needslots then
else db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
player:addItem(orderItemId, orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. "!")
print("Process complete. [".. player:getName() .."] has recieved " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
else -- not enough slots
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Your main backpack is full. You need to free up "..needslots.." available slots to get " .. orderCount .. " " .. ItemType(orderItemId):getName() .. "!")
print("Process canceled. [".. player:getName() .."] need more space in his backpack to get " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
end
else -- not enough cap
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You need more CAP to carry this order!") player:sendTextMessage(MESSAGE_STATUS_WARNING, "You need more CAP to carry this order!")
print("Process canceled. [".. player:getName() .."] need more cap to carry " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".") print("Process canceled. [".. player:getName() .."] need more cap to carry " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
end end
@ -62,7 +71,7 @@ function onThink(interval, lastExecution)
player:addOutfitAddon(orderItemId, orderCount) player:addOutfitAddon(orderItemId, orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!") player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
print("Process complete. [".. player:getName() .."] has recieved outfit: ["..orderItemId.."] with addon: ["..orderCount.."]") print("Process complete. [".. player:getName() .."] has recieved outfit: ["..orderItemId.."] with addon: ["..orderCount.."]")
else else -- Already has outfit
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
print("Process canceled. [".. player:getName() .."] already have outfit: ["..orderItemId.."] with addon: ["..orderCount.."].") print("Process canceled. [".. player:getName() .."] already have outfit: ["..orderItemId.."] with addon: ["..orderCount.."].")
end end
@ -77,21 +86,20 @@ function onThink(interval, lastExecution)
player:addMount(orderItemId) player:addMount(orderItemId)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new mount!") player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new mount!")
print("Process complete. [".. player:getName() .."] has recieved mount: ["..orderItemId.."]") print("Process complete. [".. player:getName() .."] has recieved mount: ["..orderItemId.."]")
else else -- Already has mount
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!") player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!")
print("Process canceled. [".. player:getName() .."] already have mount: ["..orderItemId.."].") print("Process canceled. [".. player:getName() .."] already have mount: ["..orderItemId.."].")
end end
end end
-- If this order hasn't been processed yet (missing type handling?) if not served then -- If this order hasn't been processed yet (missing type handling?)
if not served then
print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?") print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
end end
else else -- Not in protection zone
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have a pending shop order, please enter protection zone.') player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have a pending shop order, please enter protection zone.')
print("Skipped one shop order. Reason: Player: [".. player:getName() .."] is not inside protection zone.") print("Skipped one shop order. Reason: Player: [".. player:getName() .."] is not inside protection zone.")
end end
else else -- player not logged in
print("Skipped one shop order. Reason: Player with id [".. player_id .."] is not online.") print("Skipped one shop order. Reason: Player with id [".. player_id .."] is not online.")
end end