Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Will be moved to Globalevents at a later time.
- function onSay(cid, words, param, channel)
- local player = Player(cid)
- local charName = player:getName()
- local doDebug = true
- local orderQuery = db.storeQuery("SELECT * FROM `z_shop_history_item` WHERE `trans_real` = 0 AND `to_name` = "..db.escapeString(charName))
- print("New Debug")
- if(orderQuery ~= false) then
- -- Order details
- local orderCount, orderItemId = 0
- local orderId = result.getDataInt(orderQuery, "id")
- local offerName = result.getDataString(orderQuery, "offer_id")
- -- Check what offer ID is to get Itemid and Count
- local offerQuery = db.storeQuery("SELECT * FROM `z_shop_offer` WHERE `offer_name` = "..db.escapeString(offerName))
- if(offerQuery ~= false) then
- -- Offer exists
- offerCount = result.getDataInt(offerQuery, "count1")
- if(offerCount == 0) then
- offerCount = 1
- end
- offerItemId = result.getDataInt(offerQuery, "itemid1")
- -- Check weight
- if(player:getFreeCapacity() >= ItemType(offerItemId):getWeight(offerCount)) then
- -- Give item(s)
- player:addItem(offerItemId, offerCount)
- player:sendTextMessage(MESSAGE_STATUS_WARNING, "[SHOP] You have "..offerCount.." x "..offerName.." from the shop, thank your for your donation!")
- -- Update DB.
- db.query("UPDATE `z_shop_history_item` SET `trans_real` = 1 WHERE `z_shop_history_item`.`id` = "..db.escapeString(orderId))
- else
- player:sendTextMessage(MESSAGE_STATUS_WARNING, "[SHOP] Tried to award "..offerCount.." x "..offerName.." to you, but you don't have enough cap!")
- end
- else
- if(doDebug) then print("Offer query returned nil!") print("SELECT * FROM `z_shop_offer` WHERE `offer_name` = "..db.escapeString(q_name)) end
- end
- else
- if(doDebug) then print("Order query returned nil") end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement