Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. local VARIABLE_NONE = 0
  2. local VARIABLE_WALL = 1
  3. local VARIABLE_PLAYER = 2
  4. local VARIABLE_DAMAGE = 3
  5.  
  6. local wallEffect = CONST_ME_BIGPLANTS
  7. local playerEffect = 215
  8. local damageEffect = 79
  9.  
  10. local itemId = 1498
  11. local delay = 2 * 1000
  12. local damageDelay = 0.4 * 1000
  13.  
  14. local config = {
  15. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  16. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  17. {0, 1, 3, 3, 3, 3, 3, 3, 3, 1, 0},
  18. {0, 1, 3, 3, 3, 3, 3, 3, 3, 1, 0},
  19. {0, 1, 3, 3, 3, 3, 3, 3, 3, 1, 0},
  20. {0, 1, 3, 3, 3, 2, 3, 3, 3, 1, 0},
  21. {0, 1, 3, 3, 3, 3, 3, 3, 3, 1, 0},
  22. {0, 1, 3, 3, 3, 3, 3, 3, 3, 1, 0},
  23. {0, 1, 3, 3, 3, 3, 3, 3, 3, 1, 0},
  24. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  25. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  26. }
  27.  
  28. local function doRemoveWallItem(position)
  29. local item = getTileItemById(position, itemId)
  30. if item.uid > 0 then
  31. if wallEffect ~= CONST_ME_NONE then
  32. doSendMagicEffect(position, wallEffect)
  33. end
  34.  
  35. doRemoveItem(item.uid)
  36. end
  37. end
  38.  
  39. local function canCreate(pos)
  40. local item = getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = STACKPOS_GROUND})
  41. if item.uid == 0 then
  42. return false
  43. end
  44.  
  45. local info = getTileInfo(pos)
  46. if info.protection or info.nopvp then
  47. return false
  48. end
  49.  
  50. for it = 0, info.items do
  51. item = getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = it})
  52. local floorChange = getItemInfo(item.itemid)
  53. if not floorChange then
  54. return true
  55. end
  56.  
  57. for i = NORTH, NORTHEAST + 1 do
  58. if floorChange.floorChange[i] then
  59. return false
  60. end
  61. end
  62. end
  63.  
  64. return true
  65. end
  66.  
  67. local function doCreateWalls(position)
  68. for _, pos in pairs(position) do
  69. local item = getTileItemById(pos, itemId)
  70. if item.uid == 0 then
  71. if canCreate(pos) then
  72. doCreateItem(itemId, pos)
  73. if wallEffect ~= CONST_ME_NONE then
  74. doSendMagicEffect(pos, wallEffect)
  75. end
  76.  
  77. addEvent(doRemoveWallItem, delay, pos)
  78. end
  79. end
  80. end
  81. end
  82.  
  83. local function doSendEffect(position)
  84. if playerEffect == CONST_ME_NONE then
  85. return true
  86. end
  87.  
  88. for _, pos in pairs(position) do
  89. doSendMagicEffect({x = pos.x + 3, y = pos.y + 4, z = pos.z}, playerEffect)
  90. end
  91. end
  92.  
  93. local function canAttack(cid, target)
  94. if not cid then
  95. return true
  96. end
  97.  
  98. if isNpc(target) then
  99. return false
  100. end
  101.  
  102. if cid == target or not isCreature(target) then
  103. return false
  104. end
  105.  
  106. if getTilePzInfo(getThingPos(target)) then
  107. return false
  108. end
  109.  
  110. if isPlayer(cid) then
  111. if isInParty(cid) then
  112. if isPlayer(target) and getPlayerParty(cid) == getPlayerParty(target) then
  113. return false
  114. end
  115. end
  116. end
  117.  
  118. if isPlayer(target) and (isPlayerGhost(target) or getPlayerLevel(target) <= getConfigValue('protectionLevel')) then
  119. return false
  120. end
  121.  
  122. if isSummon(cid) then
  123. local master = getCreatureMaster(cid)
  124. if master == target then
  125. return false
  126. end
  127.  
  128. if isSummon(target) then
  129. target = getCreatureMaster(target)
  130. end
  131.  
  132. if isPlayer(master) and isPlayer(target) and isInParty(master) and getPlayerParty(master) == getPlayerParty(target) then
  133. return false
  134. end
  135. end
  136.  
  137. return true
  138. end
  139.  
  140. local function doDamage(cid, position, n)
  141. for _, pos in pairs(position) do
  142. if canCreate(pos) then
  143. if damageEffect ~= CONST_ME_NONE then
  144. doSendMagicEffect(pos, damageEffect)
  145. end
  146.  
  147. local target = getTopCreature(pos).uid
  148. if canAttack(cid, target) then
  149. local health = -(getCreatureMaxHealth(target) * 0.1)
  150. doTargetCombatHealth(0, target, COMBAT_ENERGYDAMAGE, health, health, CONST_ME_NONE)
  151. end
  152. end
  153. end
  154.  
  155. if n > 0 then
  156. addEvent(doDamage, damageDelay, cid, position, n - 1)
  157. end
  158. end
  159.  
  160. function onCastSpell(cid, var)
  161. local pos = getThingPos(cid)
  162.  
  163. local positions = {}
  164. positions[VARIABLE_WALL] = {}
  165. positions[VARIABLE_PLAYER] = {}
  166. positions[VARIABLE_DAMAGE] = {}
  167.  
  168. for py = 1, #config do
  169. for px = 1, #config[py] do
  170. local var = config[py][px]
  171. if var ~= VARIABLE_NONE then
  172. local pos = {x = pos.x + (px - ((#config - 1) / 2) - 1), y = pos.y + (py - ((#config - 1) / 2) - 1), z = pos.z}
  173.  
  174. if var == VARIABLE_WALL then
  175. table.insert(positions[VARIABLE_WALL], pos)
  176. elseif var == VARIABLE_PLAYER then
  177. table.insert(positions[VARIABLE_PLAYER], pos)
  178. elseif var == VARIABLE_DAMAGE then
  179. table.insert(positions[VARIABLE_DAMAGE], pos)
  180. end
  181. end
  182. end
  183. end
  184.  
  185. doCreatureSetNoMove(cid, true)
  186. doCreateWalls(positions[VARIABLE_WALL])
  187. doSendEffect(positions[VARIABLE_PLAYER])
  188. doDamage(cid, positions[VARIABLE_DAMAGE], delay / damageDelay)
  189. addEvent(function()
  190. if isPlayer(cid) then
  191. doCreatureSetNoMove(cid, false)
  192. end
  193. end, delay)
  194. return true
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement