Guest User

Znoteshop.lua

a guest
Apr 7th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. -- Znote Shop v1.0 for Znote AAC on TFS 1.0+.
  2. function onSay(cid, words, param)
  3.     local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
  4.     local cooldown = 15 -- in seconds.
  5.     local player = Player(cid)
  6.  
  7.     if player:getStorageValue(storage) <= os.time() then
  8.         player:setStorageValue(storage, os.time() + cooldown)
  9.  
  10.         -- Create the query
  11.         local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. player:getAccountId() .. " LIMIT 1;")
  12.  
  13.         -- Detect if we got any results
  14.         if orderQuery ~= false then
  15.             -- Fetch order values
  16.             local q_id = result.getDataInt(orderQuery, "id")
  17.             local q_type = result.getDataInt(orderQuery, "type")
  18.             local q_itemid = result.getDataInt(orderQuery, "itemid")
  19.             local q_count = result.getDataInt(orderQuery, "count")
  20.             result.free(orderQuery)
  21.  
  22.             -- ORDER TYPE 1 (Regular item shop products)
  23.             if q_type == 1 then
  24.                 -- Get wheight
  25.                 if player:getFreeCapacity() >= ItemType(q_itemid):getWeight(q_count) then
  26.                     db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
  27.                     player:addItem(q_itemid, q_count)
  28.                     player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. q_count .. " x " .. ItemType(q_itemid):getName() .. "!")
  29.                 else
  30.                     player:sendTextMessage(MESSAGE_STATUS_WARNING, "Need more CAP!")
  31.                 end
  32.             end
  33.             -- Add custom order types here
  34.             -- Type 2 is reserved for premium days and is handled on website, not needed here.
  35.             -- Type 3 is reserved for character gender(sex) change and is handled on website as well.
  36.             -- So use type 4+ for custom stuff, like etc packages.
  37.             -- if q_type == 4 then
  38.             -- end
  39.         else
  40.             player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have no orders.")
  41.         end
  42.     else
  43.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(storage) - os.time())
  44.     end
  45.     return false
  46. end
Add Comment
Please, Sign In to add comment