Advertisement
Fwaky

Untitled

Dec 27th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. -- Will be moved to Globalevents at a later time.
  2. function onSay(cid, words, param, channel)
  3.     local player = Player(cid)
  4.     local charName = player:getName()
  5.     local doDebug = true
  6.    
  7.     local orderQuery = db.storeQuery("SELECT * FROM `z_shop_history_item` WHERE `trans_real` = 0 AND `to_name` = "..db.escapeString(charName))
  8.     print("New Debug")
  9.     if(orderQuery ~= false) then
  10.         -- Order details
  11.         local orderCount, orderItemId = 0
  12.         local orderId       = result.getDataInt(orderQuery, "id")
  13.         local offerName     = result.getDataString(orderQuery, "offer_id")
  14.         -- Check what offer ID is to get Itemid and Count
  15.         local offerQuery = db.storeQuery("SELECT * FROM `z_shop_offer` WHERE `offer_name` =  "..db.escapeString(offerName))
  16.         if(offerQuery ~= false) then
  17.             -- Offer exists
  18.             offerCount  = result.getDataInt(offerQuery, "count1")
  19.             if(offerCount == 0) then
  20.                 offerCount = 1
  21.             end
  22.             offerItemId = result.getDataInt(offerQuery, "itemid1")
  23.            
  24.             -- Check weight
  25.             if(player:getFreeCapacity() >= ItemType(offerItemId):getWeight(offerCount)) then
  26.                 -- Give item(s)
  27.                 player:addItem(offerItemId, offerCount)
  28.                 player:sendTextMessage(MESSAGE_STATUS_WARNING, "[SHOP] You have "..offerCount.." x "..offerName.." from the shop, thank your for your donation!")
  29.                 -- Update DB.
  30.                 db.query("UPDATE `z_shop_history_item` SET `trans_real` = 1 WHERE `z_shop_history_item`.`id` = "..db.escapeString(orderId))
  31.             else
  32.                 player:sendTextMessage(MESSAGE_STATUS_WARNING, "[SHOP] Tried to award "..offerCount.." x "..offerName.." to you, but you don't have enough cap!")
  33.             end
  34.         else
  35.             if(doDebug) then print("Offer query returned nil!") print("SELECT * FROM `z_shop_offer` WHERE `offer_name` =  "..db.escapeString(q_name)) end
  36.         end
  37.     else
  38.         if(doDebug) then print("Order query returned nil") end
  39.     end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement