Guest User

Untitled

a guest
Jun 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. function sql_communication(parameters)
  2. print "executing sql_communication"
  3. dofile("./config.lua")
  4. env = assert(luasql.mysql())
  5. con = assert(env:connect(sql_db, sql_user, sql_pass, sql_host, sql_port))
  6. result_plr = assert(con:execute("SELECT * FROM z_ots_comunication WHERE `type` = 'login';"))
  7. todo = result_plr:fetch({}, "a")
  8. while todo do
  9. id = tonumber(todo.id)
  10. action = tostring(todo.action)
  11. delete = tonumber(todo.delete_it)
  12. cid = getPlayerByName(tostring(todo.name))
  13. if isPlayer(cid) == TRUE then
  14. local itemtogive_id = tonumber(todo.param1)
  15. local itemtogive_count = tonumber(todo.param2)
  16. local container_id = tonumber(todo.param3)
  17. local container_count = tonumber(todo.param4)
  18. local add_item_type = tostring(todo.param5)
  19. local add_item_name = tostring(todo.param6)
  20. local received_item = 0
  21. local full_weight = 0
  22.  
  23. local free_cap = getPlayerFreeCap(cid)
  24. if full_weight <= free_cap then
  25. if add_item_type == 'container' then
  26. local new_container = doCreateItemEx(container_id, 1)
  27. local iter = 0
  28. while iter ~= container_count do
  29. doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
  30. iter = iter + 1
  31. end
  32. received_item = doPlayerAddItemEx(cid, new_container)
  33. else
  34. local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  35. received_item = doPlayerAddItemEx(cid, new_item)
  36. end
  37. if received_item == RETURNVALUE_NOERROR then
  38. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')
  39. delete = assert(con:execute("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";"))
  40. assert(con:execute("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";"))
  41. else
  42. 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.')
  43. end
  44. else
  45. 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.')
  46. end
  47. end
  48. todo = result_plr:fetch (todo, "a")
  49. end
  50. con:close()
  51. env:close()
  52. local eventServ = addEvent(sql_communication, SQL_COMUNICATION_INTERVAL, parameters)
  53. end
Add Comment
Please, Sign In to add comment