function onThink(interval, lastExecution) local orderQuery = db.storeQuery([[ SELECT MIN(`po`.`player_id`) AS `player_id`, `shop`.`id`, `shop`.`type`, `shop`.`itemid`, `shop`.`count` FROM `players_online` AS `po` INNER JOIN `players` AS `p` 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) GROUP BY `shop`.`id` ]]) -- Detect if we got any results if orderQuery ~= false then local type_desc = { "itemids", "pending premium (skip)", "pending gender change (skip)", "pending character name change (skip)", "Outfit and addons", "Mounts" } repeat local player_id = result.getDataInt(orderQuery, 'player_id') local orderId = result.getDataInt(orderQuery, 'id') local orderType = result.getDataInt(orderQuery, 'type') local orderItemId = result.getDataInt(orderQuery, 'itemid') local orderCount = result.getDataInt(orderQuery, 'count') local served = false local player = Player(player_id) if player ~= nil then print("Processing shop order for: [".. player:getName() .."] type "..orderType..": ".. type_desc[orderType]) local tile = Tile(player:getPosition()) if tile ~= nil and tile:hasFlag(TILESTATE_PROTECTIONZONE) then -- ORDER TYPE 1 (Regular item shop products) if orderType == 1 then served = true -- Get wheight if player:getFreeCapacity() >= ItemType(orderItemId):getWeight(orderCount) then 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 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() .. ".") end end -- 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 player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!") print("Process canceled. [".. player:getName() .."] already have outfit: ["..orderItemId.."] with addon: ["..orderCount.."].") end end -- ORDER TYPE 6 (Mounts) if orderType == 6 then served = true -- Make sure player don't already have this outfit and addon if not player:hasMount(orderItemId) then db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";") player:addMount(orderItemId) player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new mount!") print("Process complete. [".. player:getName() .."] has recieved mount: ["..orderItemId.."]") else player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!") print("Process canceled. [".. player:getName() .."] already have mount: ["..orderItemId.."].") end end -- 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?") end else 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.") end else print("Skipped one shop order. Reason: Player with id [".. player_id .."] is not online.") end until not result.next(orderQuery) result.free(orderQuery) end return true end