Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. function selfIdle()
  2. following = false
  3. attacking = false
  4.  
  5. selfAttackCreature(0)
  6. target = 0
  7. end
  8.  
  9. function selfSayChannel(cid, message)
  10. return selfSay(message, cid, false)
  11. end
  12.  
  13. function selfMoveToCreature(id)
  14. if(not id or id == 0) then
  15. return
  16. end
  17.  
  18. local t = getCreaturePosition(id)
  19. if(not t.x or t.x == nil) then
  20. return
  21. end
  22.  
  23. selfMoveTo(t.x, t.y, t.z)
  24. return
  25. end
  26.  
  27. function getNpcDistanceToCreature(id)
  28. if(not id or id == 0) then
  29. selfIdle()
  30. return nil
  31. end
  32.  
  33. local c = getCreaturePosition(id)
  34. if(not c.x or c.x == 0) then
  35. return nil
  36. end
  37.  
  38. local s = getCreaturePosition(getNpcId())
  39. if(not s.x or s.x == 0 or s.z ~= c.z) then
  40. return nil
  41. end
  42.  
  43. return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y))
  44. end
  45.  
  46. function doMessageCheck(message, keyword)
  47. if(type(keyword) == "table") then
  48. return table.isStrIn(keyword, message)
  49. end
  50.  
  51. local a, b = message:lower():find(keyword:lower())
  52. if(a ~= nil and b ~= nil) then
  53. return true
  54. end
  55.  
  56. return false
  57. end
  58.  
  59. function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
  60. local amount = amount or 1
  61. local subType = subType or 1
  62. local ignoreCap = ignoreCap and true or false
  63.  
  64. local item = 0
  65. if(isItemStackable(itemid)) then
  66. if(isItemRune(itemid)) then
  67. amount = amount * subType
  68. end
  69.  
  70. local count = amount
  71. repeat
  72. item = doCreateItemEx(itemid, math.min(100, count))
  73. if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
  74. return 0, 0
  75. end
  76.  
  77. count = count - math.min(100, count)
  78. until count == 0
  79. return amount, 0
  80. end
  81.  
  82. local a = 0
  83. if(inBackpacks) then
  84. local container = doCreateItemEx(backpack, 1)
  85. local b = 1
  86. for i = 1, amount do
  87. item = doAddContainerItem(container, itemid, subType)
  88. if(itemid == ITEM_PARCEL) then
  89. doAddContainerItem(item, ITEM_LABEL)
  90. end
  91.  
  92. if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
  93. if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
  94. b = b - 1
  95. break
  96. end
  97.  
  98. a = i
  99. if(amount > i) then
  100. container = doCreateItemEx(backpack, 1)
  101. b = b + 1
  102. end
  103. end
  104. end
  105.  
  106. return a, b
  107. end
  108.  
  109. for i = 1, amount do
  110. item = doCreateItemEx(itemid, subType)
  111. if(itemid == ITEM_PARCEL) then
  112. doAddContainerItem(item, ITEM_LABEL)
  113. end
  114.  
  115. if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
  116. break
  117. end
  118.  
  119. a = i
  120. end
  121.  
  122. return a, 0
  123. end
  124.  
  125. function doRemoveItemIdFromPos(id, n, position)
  126. local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
  127. if(thing.itemid ~= id) then
  128. return false
  129. end
  130.  
  131. doRemoveItem(thing.uid, n)
  132. return true
  133. end
  134.  
  135. function getNpcName()
  136. return getCreatureName(getNpcId())
  137. end
  138.  
  139. function getNpcPos()
  140. return getCreaturePosition(getNpcId())
  141. end
  142.  
  143. function selfGetPosition()
  144. local t = getNpcPos()
  145. return t.x, t.y, t.z
  146. end
  147.  
  148. msgcontains = doMessageCheck
  149. moveToPosition = selfMoveTo
  150. moveToCreature = selfMoveToCreature
  151. selfMoveToPosition = selfMoveTo
  152. selfGotoIdle = selfIdle
  153. isPlayerPremiumCallback = isPremium
  154. doPosRemoveItem = doRemoveItemIdFromPos
  155. doNpcBuyItem = doPlayerRemoveItem
  156. doNpcSetCreatureFocus = selfFocus
  157. getNpcCid = getNpcId
  158. getDistanceTo = getNpcDistanceTo
  159. getDistanceToCreature = getNpcDistanceToCreature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement