Advertisement
Guest User

shop.lua

a guest
Nov 12th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 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. full_weight = getItemWeightById(itemtogive_id, 1)
  26. end
  27. local free_cap = getPlayerFreeCap(cid)
  28. if full_weight <= free_cap then
  29. if add_item_type == 'container' then
  30. local new_container = doCreateItemEx(container_id, 1)
  31. local iter = 0
  32. while iter ~= container_count do
  33. new_item = doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
  34. iter = iter + 1
  35. end
  36. received_item = doPlayerAddItemEx(cid, new_container)
  37. doItemSetAttribute(new_item, "owner", getCreatureName(cid))
  38. else
  39. new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  40. received_item = doPlayerAddItemEx(cid, new_item)
  41. doItemSetAttribute(new_item, "owner", getCreatureName(cid))
  42. end
  43. if received_item == RETURNVALUE_NOERROR then
  44. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'Voce acaba de receber o item >> '.. add_item_name ..' << de nosso shopping, obrigado por ser um ilustrissimo donate!')
  45. db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
  46. db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
  47. doPlayerSave(cid)
  48. else
  49. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'Seu item >> '.. add_item_name ..' << esta esperando por voce. Por favor faça o local para este item em sua mochila e aguarde cerca de 30 segundos para obte-lo.')
  50. end
  51. else
  52. doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'Seu item >> '.. add_item_name ..' << esta esperando por voce. O peso do item e '.. full_weight ..' oz., Vc tem no momento '.. free_cap ..' oz. de capacidade livre. Coloque alguns itens no deposito e espere cerca de 30 segundos para obte-lo.')
  53. end
  54. end
  55. if not(result_plr:next()) then
  56. break
  57. end
  58. end
  59. result_plr:free()
  60. end
  61. return TRUE
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement