Guest User

Untitled

a guest
May 20th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 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. SQL_COMUNICATION_INTERVAL = SQL_interval * 1000
  8. function onLogin(cid)
  9. if(InitShopComunication == 0) then
  10. local eventServ = addEvent(sql_communication, SQL_COMUNICATION_INTERVAL, {})
  11. InitShopComunication = eventServ
  12. end
  13. registerCreatureEvent(cid, "PlayerDeath")
  14. return TRUE
  15. end
  16.  
  17. function sql_communication(parameters)
  18. dofile("./config.lua")
  19. env = assert(luasql.mysql())
  20. con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
  21. result_plr = assert(con:execute("SELECT * FROM z_ots_comunication WHERE `type` = 'login';"))
  22. todo = result_plr:fetch({}, "a")
  23. while todo do
  24. id = tonumber(todo.id)
  25. action = tostring(todo.action)
  26. delete = tonumber(todo.delete_it)
  27. cid = getPlayerByName(tostring(todo.name))
  28. if isPlayer(cid) == TRUE then
  29. local itemtogive_id = tonumber(todo.param1)
  30. local itemtogive_count = tonumber(todo.param2)
  31. local container_id = tonumber(todo.param3)
  32. local container_count = tonumber(todo.param4)
  33. local add_item_type = tostring(todo.param5)
  34. local add_item_name = tostring(todo.param6)
  35. local received_item = 0
  36. local full_weight = 0
  37. if add_item_type == 'container' then
  38. container_weight = getItemWeight(container_id, 1)
  39. if isItemRune(itemtogive_id) == TRUE then
  40. items_weight = container_count * getItemWeight(itemtogive_id, 1)
  41. else
  42. items_weight = container_count * getItemWeight(itemtogive_id, itemtogive_count)
  43. end
  44. full_weight = items_weight + container_weight
  45. else
  46. full_weight = getItemWeight(itemtogive_id, itemtogive_count)
  47. if isItemRune(itemtogive_id) == TRUE then
  48. full_weight = getItemWeight(itemtogive_id, 1)
  49. else
  50. full_weight = getItemWeight(itemtogive_id, itemtogive_count)
  51. end
  52. end
  53. local free_cap = getPlayerFreeCap(cid)
  54. if full_weight <= free_cap then
  55. if add_item_type == 'container' then
  56. local new_container = doCreateItemEx(container_id, 1)
  57. local iter = 0
  58. while iter ~= container_count do
  59. doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
  60. iter = iter + 1
  61. end
  62. received_item = doPlayerAddItemEx(cid, new_container)
  63. else
  64. local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  65. received_item = doPlayerAddItemEx(cid, new_item)
  66. end
  67. if received_item == RETURNVALUE_NOERROR then
  68. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')
  69. delete = assert(con:execute("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";"))
  70. assert(con:execute("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";"))
  71. else
  72. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
  73. end
  74. else
  75. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS 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.')
  76. end
  77. end
  78. todo = result_plr:fetch (todo, "a")
  79. end
  80. con:close()
  81. env:close()
  82. local eventServ = addEvent(sql_communication, SQL_COMUNICATION_INTERVAL, parameters)
  83. end
Add Comment
Please, Sign In to add comment