Advertisement
Kushovu

Untitled

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