Advertisement
Kaiquegabriel

Untitled

Jul 27th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. -- ### CONFIG ###
  2. -- message send to player by script "type" (types you can check in "global.lua")
  3. SHOP_MSG_TYPE = 19
  4. -- time (in seconds) between connections to SQL database by shop script
  5. SQL_interval = 30
  6. -- ### END OF CONFIG ###
  7. function onThink(interval, lastExecution)
  8. local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")
  9. if(result_plr:getID() ~= -1) then
  10. while(true) do
  11. id = tonumber(result_plr:getDataInt("id"))
  12. action = tostring(result_plr:getDataString("action"))
  13. delete = tonumber(result_plr:getDataInt("delete_it"))
  14. cid = getCreatureByName(tostring(result_plr:getDataString("name")))
  15. if isPlayer(cid) == TRUE then
  16. local itemtogive_id = tonumber(result_plr:getDataInt("param1"))
  17. local itemtogive_count = tonumber(result_plr:getDataInt("param2"))
  18. local container_id = tonumber(result_plr:getDataInt("param3"))
  19. local container_count = tonumber(result_plr:getDataInt("param4"))
  20. local add_item_type = tostring(result_plr:getDataString("param5"))
  21. local add_item_name = tostring(result_plr:getDataString("param6"))
  22. local received_item = 0
  23. local full_weight = 0
  24. if add_item_type == 'container' then
  25. container_weight = getItemWeightById(container_id, 1)
  26. if isItemRune(itemtogive_id) == TRUE then
  27. items_weight = container_count * getItemWeightById(itemtogive_id, 1)
  28. else
  29. items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)
  30. end
  31. full_weight = items_weight + container_weight
  32. else
  33. full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
  34. if isItemRune(itemtogive_id) == TRUE then
  35. full_weight = getItemWeightById(itemtogive_id, 1)
  36. else
  37. full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
  38. end
  39. end
  40. local free_cap = getPlayerFreeCap(cid)
  41. if full_weight <= free_cap then
  42. if add_item_type == 'container' then
  43. local new_container = doCreateItemEx(container_id, 1)
  44. doItemSetAttribute(new_container, "description", 'Bought by ' .. getCreatureName(cid) .. ' [ID:' .. id .. '].')
  45. local iter = 0
  46. while iter ~= container_count do
  47. local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  48. doItemSetAttribute(new_item, "description", 'Bought by ' .. getCreatureName(cid) .. ' [ID:' .. id .. '].')
  49. doAddContainerItemEx(new_container, new_item)
  50. iter = iter + 1
  51. end
  52. received_item = doPlayerAddItemEx(cid, new_container)
  53. else
  54. local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  55. doItemSetAttribute(new_item, "description", 'Bought by ' .. getCreatureName(cid) .. ' [ID:' .. id .. '].')
  56. received_item = doPlayerAddItemEx(cid, new_item)
  57. end
  58. if received_item == RETURNVALUE_NOERROR then
  59. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'Received >> '.. add_item_name ..' << from Olderian shop.')
  60. doPlayerSave(cid)
  61. db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
  62. db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
  63. else
  64. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from Olderian shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
  65. end
  66. else
  67. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from Olderian shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
  68. end
  69. end
  70. if not(result_plr:next()) then
  71. break
  72. end
  73. end
  74. result_plr:free()
  75. end
  76. return TRUE
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement