Process all orders at once in shop talkaction script

This commit is contained in:
Znote 2019-09-09 02:16:37 +02:00
parent c5323dbc78
commit c0f891b2d7
4 changed files with 286 additions and 212 deletions

View File

@ -7,20 +7,31 @@ function onSay(cid, words, param)
setPlayerStorageValue(cid, storage, os.time() + cooldown) setPlayerStorageValue(cid, storage, os.time() + cooldown)
local accid = getAccountNumberByPlayerName(getCreatureName(cid)) local accid = getAccountNumberByPlayerName(getCreatureName(cid))
local type_desc = {
"itemids",
"pending premium (skip)",
"pending gender change (skip)",
"pending character name change (skip)",
"Outfit and addons"
}
print("Player: " .. getCreatureName(cid) .. " triggered !shop talkaction.")
-- Create the query -- Create the query
local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. " LIMIT 1;") local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. ";")
local served = false
-- Detect if we got any results -- Detect if we got any results
if orderQuery ~= false then if orderQuery ~= false then
repeat
-- Fetch order values -- Fetch order values
local q_id = result.getDataInt(orderQuery, "id") local q_id = result.getDataInt(orderQuery, "id")
local q_type = result.getDataInt(orderQuery, "type") local q_type = result.getDataInt(orderQuery, "type")
local q_itemid = result.getDataInt(orderQuery, "itemid") local q_itemid = result.getDataInt(orderQuery, "itemid")
local q_count = result.getDataInt(orderQuery, "count") local q_count = result.getDataInt(orderQuery, "count")
result.free(orderQuery) print("Processing type "..q_type..": ".. type_desc[q_type])
-- ORDER TYPE 1 (Regular item shop products) -- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then if q_type == 1 then
served = true
-- Get wheight -- Get wheight
local playerCap = getPlayerFreeCap(cid) local playerCap = getPlayerFreeCap(cid)
local itemweight = getItemWeight(q_itemid, q_count) local itemweight = getItemWeight(q_itemid, q_count)
@ -34,6 +45,7 @@ function onSay(cid, words, param)
end end
-- ORDER TYPE 5 (Outfit and addon) -- ORDER TYPE 5 (Outfit and addon)
if q_type == 5 then if q_type == 5 then
served = true
-- Make sure player don't already have this outfit and addon -- Make sure player don't already have this outfit and addon
if not canPlayerWearOutfit(cid, q_itemid, q_count) then if not canPlayerWearOutfit(cid, q_itemid, q_count) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -57,10 +69,14 @@ function onSay(cid, words, param)
-- So use type 7+ for custom stuff, like etc packages. -- So use type 7+ for custom stuff, like etc packages.
-- if q_type == 7 then -- if q_type == 7 then
-- end -- end
until not result.next(orderQuery)
result.free(orderQuery)
if not served then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
end
else else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.") doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.")
end end
else else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time()) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time())
end end

View File

@ -7,20 +7,32 @@ function onSay(cid, words, param)
setPlayerStorageValue(cid, storage, os.time() + cooldown) setPlayerStorageValue(cid, storage, os.time() + cooldown)
local accid = getAccountNumberByPlayerName(getCreatureName(cid)) local accid = getAccountNumberByPlayerName(getCreatureName(cid))
local type_desc = {
"itemids",
"pending premium (skip)",
"pending gender change (skip)",
"pending character name change (skip)",
"Outfit and addons",
"Mounts"
}
print("Player: " .. getCreatureName(cid) .. " triggered !shop talkaction.")
-- Create the query -- Create the query
local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. ";") local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. ";")
local served = false
-- Detect if we got any results -- Detect if we got any results
if orderQuery ~= false then if orderQuery ~= false then
repeat
-- Fetch order values -- Fetch order values
local q_id = result.getDataInt(orderQuery, "id") local q_id = result.getDataInt(orderQuery, "id")
local q_type = result.getDataInt(orderQuery, "type") local q_type = result.getDataInt(orderQuery, "type")
local q_itemid = result.getDataInt(orderQuery, "itemid") local q_itemid = result.getDataInt(orderQuery, "itemid")
local q_count = result.getDataInt(orderQuery, "count") local q_count = result.getDataInt(orderQuery, "count")
result.free(orderQuery) print("Processing type "..q_type..": ".. type_desc[q_type])
-- ORDER TYPE 1 (Regular item shop products) -- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then if q_type == 1 then
served = true
-- Get wheight -- Get wheight
local playerCap = getPlayerFreeCap(cid) local playerCap = getPlayerFreeCap(cid)
local itemweight = getItemWeightById(q_itemid, q_count) local itemweight = getItemWeightById(q_itemid, q_count)
@ -35,6 +47,7 @@ function onSay(cid, words, param)
end end
-- ORDER TYPE 5 (Outfit and addon) -- ORDER TYPE 5 (Outfit and addon)
if q_type == 5 then if q_type == 5 then
served = true
-- Make sure player don't already have this outfit and addon -- Make sure player don't already have this outfit and addon
if not canPlayerWearOutfit(cid, q_itemid, q_count) then if not canPlayerWearOutfit(cid, q_itemid, q_count) then
local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -48,6 +61,7 @@ function onSay(cid, words, param)
-- ORDER TYPE 6 (Mounts) -- ORDER TYPE 6 (Mounts)
if q_type == 6 then if q_type == 6 then
served = true
-- Make sure player don't already have this outfit and addon -- Make sure player don't already have this outfit and addon
if not getPlayerMount(cid, q_itemid) then -- Failed to find a proper hasMount 0.3 function? if not getPlayerMount(cid, q_itemid) then -- Failed to find a proper hasMount 0.3 function?
local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") local delete = db.storeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -69,10 +83,14 @@ function onSay(cid, words, param)
-- So use type 7+ for custom stuff, like etc packages. -- So use type 7+ for custom stuff, like etc packages.
-- if q_type == 7 then -- if q_type == 7 then
-- end -- end
until not result.next(orderQuery)
result.free(orderQuery)
if not served then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
end
else else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.") doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.")
end end
else else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time()) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time())
end end

View File

@ -7,19 +7,31 @@ function onSay(cid, words, param)
setPlayerStorageValue(cid, storage, os.time() + cooldown) setPlayerStorageValue(cid, storage, os.time() + cooldown)
local accid = getAccountNumberByPlayerName(getCreatureName(cid)) local accid = getAccountNumberByPlayerName(getCreatureName(cid))
local type_desc = {
"itemids",
"pending premium (skip)",
"pending gender change (skip)",
"pending character name change (skip)",
"Outfit and addons",
"Mounts"
}
print("Player: " .. getCreatureName(cid) .. " triggered !shop talkaction.")
-- Create the query -- Create the query
local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. " LIMIT 1;") local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. ";")
local served = false
-- Detect if we got any results -- Detect if we got any results
if orderQuery ~= false then if orderQuery ~= false then
repeat
-- Fetch order values -- Fetch order values
local q_id = result.getDataInt(orderQuery, "id") local q_id = result.getDataInt(orderQuery, "id")
local q_type = result.getDataInt(orderQuery, "type") local q_type = result.getDataInt(orderQuery, "type")
local q_itemid = result.getDataInt(orderQuery, "itemid") local q_itemid = result.getDataInt(orderQuery, "itemid")
local q_count = result.getDataInt(orderQuery, "count") local q_count = result.getDataInt(orderQuery, "count")
result.free(orderQuery) print("Processing type "..q_type..": ".. type_desc[q_type])
-- ORDER TYPE 1 (Regular item shop products) -- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then if q_type == 1 then
served = true
-- Get wheight -- Get wheight
local playerCap = getPlayerFreeCap(cid) local playerCap = getPlayerFreeCap(cid)
local itemweight = getItemWeightById(q_itemid, q_count) local itemweight = getItemWeightById(q_itemid, q_count)
@ -45,6 +57,7 @@ function onSay(cid, words, param)
end end
-- ORDER TYPE 5 (Outfit and addon) -- ORDER TYPE 5 (Outfit and addon)
if q_type == 5 then if q_type == 5 then
served = true
-- Make sure player don't already have this outfit and addon -- Make sure player don't already have this outfit and addon
if not canPlayerWearOutfit(cid, q_itemid, q_count) then if not canPlayerWearOutfit(cid, q_itemid, q_count) then
db.executeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") db.executeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -57,6 +70,7 @@ function onSay(cid, words, param)
-- ORDER TYPE 6 (Mounts) -- ORDER TYPE 6 (Mounts)
if q_type == 6 then if q_type == 6 then
served = true
-- Make sure player don't already have this outfit and addon -- Make sure player don't already have this outfit and addon
if not getPlayerMount(cid, q_itemid) then -- Failed to find a proper hasMount 0.3 function? if not getPlayerMount(cid, q_itemid) then -- Failed to find a proper hasMount 0.3 function?
db.executeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") db.executeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -77,8 +91,13 @@ function onSay(cid, words, param)
-- So use type 7+ for custom stuff, like etc packages. -- So use type 7+ for custom stuff, like etc packages.
-- if q_type == 7 then -- if q_type == 7 then
-- end -- end
until not result.next(orderQuery)
result.free(orderQuery)
if not served then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
end
else else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.") doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders.")
end end
else else

View File

@ -6,20 +6,33 @@ function onSay(player, words, param)
if player:getStorageValue(storage) <= os.time() then if player:getStorageValue(storage) <= os.time() then
player:setStorageValue(storage, os.time() + cooldown) player:setStorageValue(storage, os.time() + cooldown)
local type_desc = {
"itemids",
"pending premium (skip)",
"pending gender change (skip)",
"pending character name change (skip)",
"Outfit and addons",
"Mounts"
}
print("Player: " .. player:getName() .. " triggered !shop talkaction.")
-- Create the query -- Create the query
local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. player:getAccountId() .. " LIMIT 1;") local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. player:getAccountId() .. ";")
local served = false
-- Detect if we got any results -- Detect if we got any results
if orderQuery ~= false then if orderQuery ~= false then
repeat
-- Fetch order values -- Fetch order values
local q_id = result.getNumber(orderQuery, "id") local q_id = result.getNumber(orderQuery, "id")
local q_type = result.getNumber(orderQuery, "type") local q_type = result.getNumber(orderQuery, "type")
local q_itemid = result.getNumber(orderQuery, "itemid") local q_itemid = result.getNumber(orderQuery, "itemid")
local q_count = result.getNumber(orderQuery, "count") local q_count = result.getNumber(orderQuery, "count")
result.free(orderQuery)
print("Processing type "..q_type..": ".. type_desc[q_type])
-- ORDER TYPE 1 (Regular item shop products) -- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then if q_type == 1 then
served = true
-- Get wheight -- Get wheight
if player:getFreeCapacity() >= ItemType(q_itemid):getWeight(q_count) then if player:getFreeCapacity() >= ItemType(q_itemid):getWeight(q_count) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -32,6 +45,7 @@ function onSay(player, words, param)
-- ORDER TYPE 5 (Outfit and addon) -- ORDER TYPE 5 (Outfit and addon)
if q_type == 5 then if q_type == 5 then
served = true
-- Make sure player don't already have this outfit and addon -- Make sure player don't already have this outfit and addon
if not player:hasOutfit(q_itemid, q_count) then if not player:hasOutfit(q_itemid, q_count) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -45,6 +59,7 @@ function onSay(player, words, param)
-- ORDER TYPE 6 (Mounts) -- ORDER TYPE 6 (Mounts)
if q_type == 6 then if q_type == 6 then
served = true
-- Make sure player don't already have this outfit and addon -- Make sure player don't already have this outfit and addon
if not player:hasMount(q_itemid) then if not player:hasMount(q_itemid) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
@ -55,6 +70,7 @@ function onSay(player, words, param)
end end
end end
-- Add custom order types here -- Add custom order types here
-- Type 1 is for itemids (Already coded here) -- Type 1 is for itemids (Already coded here)
-- Type 2 is for premium (Coded on web) -- Type 2 is for premium (Coded on web)
@ -65,8 +81,13 @@ function onSay(player, words, param)
-- So use type 7+ for custom stuff, like etc packages. -- So use type 7+ for custom stuff, like etc packages.
-- if q_type == 7 then -- if q_type == 7 then
-- end -- end
until not result.next(orderQuery)
result.free(orderQuery)
if not served then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
end
else else
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have no orders.") player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders.")
end end
else else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(storage) - os.time()) player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(storage) - os.time())