Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 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, 'advance')
  14. registerCreatureEvent(cid, "PlayerDeath")
  15. registerCreatureEvent(cid, "Ushuriel")
  16. registerCreatureEvent(cid, "Zugurosh")
  17. registerCreatureEvent(cid, "Madareth")
  18. registerCreatureEvent(cid, "Golgordan")
  19. registerCreatureEvent(cid, "Annihilon")
  20. registerCreatureEvent(cid, "Hellgorak")
  21. return TRUE
  22. end
  23.  
  24. function sql_communication(parameters)
  25. local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")
  26. if(result_plr:getID() ~= -1) then
  27. while(true) do
  28. id = tonumber(result_plr:getDataInt("id"))
  29. action = tostring(result_plr:getDataString("action"))
  30. delete = tonumber(result_plr:getDataInt("delete_it"))
  31. cid = getPlayerByName(tostring(result_plr:getDataString("name")))
  32. if isPlayer(cid) == TRUE then
  33. local itemtogive_id = tonumber(result_plr:getDataInt("param1"))
  34. local itemtogive_count = tonumber(result_plr:getDataInt("param2"))
  35. local container_id = tonumber(result_plr:getDataInt("param3"))
  36. local container_count = tonumber(result_plr:getDataInt("param4"))
  37. local add_item_type = tostring(result_plr:getDataString("param5"))
  38. local add_item_name = tostring(result_plr:getDataString("param6"))
  39. local received_item = 0
  40. local full_weight = 0
  41. if add_item_type == 'container' then
  42. container_weight = getItemWeightById(container_id, 1)
  43. if isItemRune(itemtogive_id) == TRUE then
  44. items_weight = container_count * getItemWeightById(itemtogive_id, 1)
  45. else
  46. items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)
  47. end
  48. full_weight = items_weight + container_weight
  49. else
  50. full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
  51. if isItemRune(itemtogive_id) == TRUE then
  52. full_weight = getItemWeightById(itemtogive_id, 1)
  53. else
  54. full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
  55. end
  56. end
  57. local free_cap = getPlayerFreeCap(cid)
  58. if full_weight <= free_cap then
  59. if add_item_type == 'container' then
  60. local new_container = doCreateItemEx(container_id, 1)
  61. local iter = 0
  62. while iter ~= container_count do
  63. doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
  64. iter = iter + 1
  65. end
  66. received_item = doPlayerAddItemEx(cid, new_container)
  67. else
  68. local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  69. received_item = doPlayerAddItemEx(cid, new_item)
  70. end
  71. if received_item == RETURNVALUE_NOERROR then
  72. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')
  73. db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
  74. db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
  75. else
  76. 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.')
  77. end
  78. else
  79. 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.')
  80. end
  81. end
  82. if not(result_plr:next()) then
  83. break
  84. end
  85. end
  86. result_plr:free()
  87. end
  88. local eventServ = addEvent(sql_communication, SQL_COMUNICATION_INTERVAL, parameters)
  89. end
  90. function checkRecord()
  91. local onlinePlayers = getWorldCreatures(0)
  92. if(onlinePlayers > getMaxPlayers()) then
  93. broadcastMessageEx(MESSAGE_EVENT_ADVANCE, 'New record: ' .. onlinePlayers .. (onlinePlayers > 1 and ' players' or ' player').. ' are logged in.')
  94. local save = assert(io.open('record.ini', "wb"))
  95. local data = save:read("*number")
  96. save:write(onlinePlayers)
  97. save:close()
  98. end
  99. end
  100.  
  101. function getMaxPlayers()
  102.  
  103. local file = assert(io.open('record.ini', "rb"))
  104. local t = file:read("*number")
  105. file:close()
  106.  
  107. return (t == nil and 0 or t)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement