Guest User

shop.lua

a guest
Jan 6th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 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 = 18
  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.storeQuery("SELECT * FROM z_ots_comunication")
  9. if(result_plr ~= false) then
  10. repeat
  11. local id = tonumber(result.getDataInt(result_plr, "id"))
  12. local action = tostring(result.getDataString(result_plr, "action"))
  13. local delete = tonumber(result.getDataInt(result_plr, "delete_it"))
  14. local cid = getPlayerByName(tostring(result.getDataString(result_plr, "name")))
  15. if(cid) then
  16. local itemtogive_id = tonumber(result.getDataInt(result_plr, "param1"))
  17. local itemtogive_count = tonumber(result.getDataInt(result_plr, "param2"))
  18. local container_id = tonumber(result.getDataInt(result_plr, "param3"))
  19. local container_count = tonumber(result.getDataInt(result_plr, "param4"))
  20. local add_item_type = tostring(result.getDataString(result_plr, "param5"))
  21. local add_item_name = tostring(result.getDataString(result_plr, "param6"))
  22. local storage = tostring(result.getDataString(result_plr, "param7"))
  23. local received_item = 0
  24. local full_weight = 0
  25. if(add_item_type == 'container') then
  26. container_weight = getItemWeight(container_id, 1)
  27. if(isItemRune(itemtogive_id)) then
  28. items_weight = container_count * getItemWeight(itemtogive_id, 1)
  29. else
  30. items_weight = container_count * getItemWeight(itemtogive_id, itemtogive_count)
  31. end
  32. full_weight = items_weight + container_weight
  33. else
  34. full_weight = getItemWeight(itemtogive_id, itemtogive_count)
  35. if(isItemRune(itemtogive_id)) then
  36. full_weight = getItemWeight(itemtogive_id, 1)
  37. else
  38. full_weight = getItemWeight(itemtogive_id, itemtogive_count)
  39. end
  40. end
  41. local free_cap = getPlayerFreeCap(cid)
  42. if(full_weight <= free_cap) then
  43. if(add_item_type == 'container') then
  44. local new_container = doCreateItemEx(container_id, 1)
  45. local iter = 0
  46. while(iter ~= container_count) do
  47. doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
  48. iter = iter + 1
  49. end
  50. received_item = doPlayerAddItemEx(cid, new_container)
  51. else
  52. local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  53. received_item = doPlayerAddItemEx(cid, new_item)
  54. end
  55. if(type(received_item) == "number" and received_item == RETURNVALUE_NOERROR) then
  56. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received '.. add_item_name ..' from ArenaTibia Shop.')
  57. setPlayerStorageValue(cid,storage)
  58. db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
  59. db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
  60. else
  61. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' from ArenaTibia Shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
  62. end
  63. else
  64. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' ArenaTibia 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.')
  65. end
  66. end
  67. until not result.next(result_plr)
  68. result.free(result_plr)
  69. end
  70. return true
  71. end
Advertisement
Add Comment
Please, Sign In to add comment