Advertisement
RoksasNunes

shop

Nov 10th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.42 KB | None | 0 0
  1. function onThink(interval, lastExecution, thinkInterval)
  2.  
  3.     local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
  4.    
  5.     if(result:getID() ~= -1) then
  6.         while(true) do
  7.             cid = getCreatureByName(tostring(result:getDataString("player")))
  8.             product = tonumber(result:getDataInt("product"))
  9.             idTransaction = tonumber(result:getDataInt("id"))
  10.             itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
  11.             if isPlayer(cid) then
  12.                 local id = tonumber(itemr:getDataInt("item"))
  13.                 local tid = tonumber(result:getDataInt("id"))
  14.                 local count = tonumber(itemr:getDataInt("count"))
  15.                 local tipe = tonumber(itemr:getDataInt("type"))
  16.                 local productn = tostring(itemr:getDataString("name"))
  17.                 if isInArray({5,8},tipe) then
  18.                     if getPlayerFreeCap(cid) >= getItemWeightById(id, count) then
  19.                         --if isContainer(getPlayerSlotItem(cid, 3).uid) then
  20.                         received = doPlayerGiveItemSHOP(cid, id, count, 0, idTransaction)                                      
  21.                         --received = doAddContainerItem(getPlayerSlotItem(cid, 3).uid, id,count)
  22.                         if received == true then
  23.                             doPlayerSendTextMessage(cid,19, "You have received >> "..productn.." << from our shop system")
  24.                             db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
  25.                         else
  26.                             doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space on container to receive >> "..productn.." <<")
  27.                         end
  28.                     --else
  29.                         --doPlayerSendTextMessage(cid,19, "Sorry, you don't have a container to receive >> "..productn.." <<")
  30.                     --end
  31.                     else
  32.                         doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
  33.                     end
  34.                                
  35.                 elseif tipe == 20 then         
  36.                     doPlayerAddMount(cid, id)
  37.                     doSendMagicEffect(getThingPos(cid), 14)
  38.                     doPlayerSendTextMessage(cid, 19, "You have received >> "..productn.." << from your shop system.")
  39.  
  40.                 elseif tipe == 21 then
  41.                     doPlayerAddOutfit(cid, id, 3)
  42.                     doSendMagicEffect(getThingPos(cid), 14)
  43.                     doPlayerSendTextMessage(cid, 19, "You have received >> "..productn.." << from your shop system.")
  44.  
  45.                 elseif isInArray({6,7}, tipe) then
  46.                     if tipe == 6 then
  47.                         bcap = 8
  48.                         bid = 1987
  49.                     elseif tipe == 7 then
  50.                         bcap = 20
  51.                         bid = 1988
  52.                     end
  53.                     if isItemRune(id) then
  54.                         count = 1
  55.                     end
  56.                     if getPlayerFreeCap(cid) >= (getItemWeightById(1987, 1) + getItemWeightById(id,count * bcap)) then
  57.                         --local bag = doCreateItemEx(bid, 1)
  58.                         --for i = 1,bcap do
  59.                         --doAddContainerItem(bag, id, count)
  60.                         --end
  61.                         received = doPlayerGiveItemContainer(cid, 1988, id, count, 0)
  62.                         --received = doPlayerAddItemEx(getPlayerSlotItem(cid, 3).uid, bag)
  63.                         if received == true then
  64.                             doPlayerSendTextMessage(cid,19, "You have received >> "..productn.." << from our shop system")
  65.                             db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
  66.                         else
  67.                             doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space to receive >> "..productn.." <<")
  68.                         end
  69.                     else
  70.                         doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
  71.                     end
  72.                 end
  73.             end
  74.             itemr:free()
  75.             if not(result:next()) then
  76.                 break
  77.             end
  78.         end
  79.             result:free()
  80.         end
  81.     return true
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement