mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-04-29 18:59:21 +02:00

- changed folder name from LUA to Lua - Added installation instructions - fixed playerdeath variables (fixes #430) - Added outfit IDs up to Jouster outfit to the sync outfit script - Removed unecessary instruction - Added revscriptsys version of all scripts
104 lines
3.9 KiB
Lua
104 lines
3.9 KiB
Lua
-- Znote Shop v1.1 for Znote AAC on TFS 0.2.13+ Mystic Spirit.
|
|
function onSay(cid, words, param)
|
|
local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
|
|
local cooldown = 15 -- in seconds.
|
|
|
|
if getPlayerStorageValue(cid, storage) <= os.time() then
|
|
setPlayerStorageValue(cid, storage, os.time() + cooldown)
|
|
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",
|
|
"Instant house purchase"
|
|
}
|
|
print("Player: " .. getCreatureName(cid) .. " triggered !shop talkaction.")
|
|
-- Create the query
|
|
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
|
|
if orderQuery ~= false then
|
|
-- Fetch order values
|
|
local q_id = result.getDataInt(orderQuery, "id")
|
|
local q_type = result.getDataInt(orderQuery, "type")
|
|
local q_itemid = result.getDataInt(orderQuery, "itemid")
|
|
local q_count = result.getDataInt(orderQuery, "count")
|
|
|
|
local description = "Unknown or custom type"
|
|
if type_desc[q_type] ~= nil then
|
|
description = type_desc[q_type]
|
|
end
|
|
print("Processing type "..q_type..": ".. description)
|
|
|
|
-- ORDER TYPE 1 (Regular item shop products)
|
|
if q_type == 1 then
|
|
served = true
|
|
-- Get weight
|
|
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 received ".. 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
|
|
|
|
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
|
|
|
|
-- ORDER TYPE 6 (Mounts)
|
|
-- Not supported on TFS 0.2
|
|
|
|
-- Add custom order types here
|
|
-- Type 1 is for itemids (Already coded here)
|
|
-- Type 2 is for premium (Coded on web)
|
|
-- Type 3 is for gender change (Coded on web)
|
|
-- Type 4 is for character name change (Coded on web)
|
|
-- Type 5 is for character outfit and addon (Already coded here)
|
|
-- Type 6 is for mounts (Not for TFS 0.2)
|
|
-- Type 7 is for Instant house purchase (Not for TFS 0.2)
|
|
-- So use type 8+ for custom stuff, like etc packages.
|
|
-- if q_type == 8 then
|
|
-- end
|
|
result.free(orderQuery)
|
|
if not served then
|
|
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
|
|
end
|
|
else
|
|
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.")
|
|
end
|
|
else
|
|
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time())
|
|
end
|
|
return false
|
|
end
|