JoseluisGGR

Untitled

Jul 21st, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. EquipObject = {}
  2. EquipObject.Slots = {
  3. [48] = CONST_SLOT_LEFT,
  4. [49] = CONST_SLOT_HEAD,
  5. [50] = CONST_SLOT_NECKLACE,
  6. [52] = CONST_SLOT_BACKPACK,
  7. [56] = CONST_SLOT_ARMOR,
  8. [112] = CONST_SLOT_LEGS,
  9. [176] = CONST_SLOT_FEET,
  10. [304] = CONST_SLOT_RING,
  11. [560] = CONST_SLOT_AMMO,
  12. [2096] = SLOTP_TWO_HAND -- We only use slot position in this!
  13. }
  14. function onRecvbyte(player, msg, byte)
  15. local itemType = Game.getItemIdByClientId(msg:getU16())
  16. local item = player:getItemById(itemType:getId(), true)
  17. if not item then
  18. item = player:getItemById(itemType:getTransformEquipId(), true)
  19. if not item then
  20. item = player:getItemById(itemType:getTransformDeEquipId(), true)
  21. end
  22.  
  23. if not item then
  24. return player:sendCancelMessage("Sorry not possible.")
  25. end
  26. end
  27.  
  28. local newItemType = ItemType(item:getId())
  29. local slotP = EquipObject.Slots[newItemType:getSlotPosition()]
  30.  
  31. if newItemType:getWeaponType() == WEAPON_SHIELD then
  32. slotP = CONST_SLOT_RIGHT
  33. end
  34.  
  35. if slotP == CONST_SLOT_BACKPACK then
  36. player:sendCancelMessage("You can't equip a backpack.")
  37. elseif slotP == SLOTP_TWO_HAND then
  38. local slotLeft_item = player:getSlotItem(CONST_SLOT_LEFT)
  39. local slotRight_Item = player:getSlotItem(CONST_SLOT_RIGHT)
  40. if slotLeft_item then
  41. if slotLeft_item:getId() == newItemType:getId() then
  42. slotLeft_item:moveToSlot(player, 0)
  43. else
  44. if slotRight_Item then
  45. slotRight_Item:moveToSlot(player, 0)
  46. end
  47. item:moveToSlot(player, CONST_SLOT_LEFT)
  48. end
  49. else
  50. if slotRight_Item then
  51. slotRight_Item:moveToSlot(player, 0)
  52. end
  53. item:moveToSlot(player, CONST_SLOT_LEFT)
  54. end
  55. elseif slotP == CONST_SLOT_RING then
  56. local slotRing_item = player:getSlotItem(CONST_SLOT_RING)
  57. if slotRing_item then
  58. if slotRing_item:getId() == newItemType:getId() then
  59. slotRing_item:moveToSlot(player, 0)
  60. elseif slotRing_item:getId() == newItemType:getTransformEquipId() then
  61. slotRing_item:moveToSlot(player, 0)
  62. elseif slotRing_item:getId() == newItemType:getTransformDeEquipId() then
  63. slotRing_item:moveToSlot(player, 0)
  64. else
  65. item:moveToSlot(player, CONST_SLOT_RING)
  66. end
  67. else
  68. item:moveToSlot(player, CONST_SLOT_RING)
  69. end
  70. elseif slotP == CONST_SLOT_RIGHT then
  71. local slotRight_Item = player:getSlotItem(CONST_SLOT_RIGHT)
  72. local slotLeft_item = player:getSlotItem(CONST_SLOT_LEFT)
  73. if slotRight_Item then
  74. if slotRight_Item:getId() == item:getId() then
  75. slotRight_Item:moveToSlot(player, 0)
  76. else
  77. item:moveToSlot(player, CONST_SLOT_RIGHT)
  78. end
  79. else
  80. if slotLeft_item and EquipObject.Slots[ItemType(slotLeft_item:getId()):getSlotPosition()] == SLOTP_TWO_HAND then
  81. slotLeft_item:moveToSlot(player, 0)
  82. end
  83. item:moveToSlot(player, CONST_SLOT_RIGHT)
  84. end
  85. elseif slotP == CONST_SLOT_FEET then
  86. -- do some shit
  87. elseif slotP then
  88. local slotItem = player:getSlotItem(slotP)
  89.  
  90.  
  91. if slotItem then
  92. if slotItem:getId() == item:getId() then
  93. item:moveToSlot(player, 0)
  94. else
  95. EquipObject.StackAdd(player, item, slotP, newItemType:isStackable())
  96. end
  97. else
  98. EquipObject.StackAdd(player, item, slotP, newItemType:isStackable())
  99. end
  100. end
  101. return player:sendCancelMessage("You are exhausted.")
  102. end
  103.  
  104. EquipObject.StackAdd = function(player, item, slotP, isStackable)
  105. if isStackable and item:getCount() < 100 and item:getCount() < player:getItemCount(item:getId()) then
  106. local itemId, count = item:getId(), 0
  107. while player:getItemCount(itemId) do
  108. if count == 100 then break end
  109. local _item = player:getItemById(itemId, true)
  110. if not _item then break end
  111. if _item:getCount() > 100 - count then
  112. _item:remove(100 - count)
  113. count = 100
  114. else
  115. count = count + _item:getCount()
  116. _item:remove()
  117. end
  118. end
  119.  
  120. player:addItem(itemId, count, true, 1, slotP)
  121. else
  122. item:moveToSlot(player, slotP)
  123. end
  124. end
Advertisement
Add Comment
Please, Sign In to add comment