Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 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 isSummon(target) and getCreatureMaster(target) == cid then
  107. return false
  108. end
  109.  
  110. if getTilePzInfo(getThingPos(target)) then
  111. return false
  112. end
  113.  
  114. if isPlayer(cid) then
  115. if isInParty(cid) then
  116. if isPlayer(target) and getPlayerParty(cid) == getPlayerParty(target) then
  117. return false
  118. end
  119. end
  120.  
  121. if isSummon(target) then
  122. local master = getCreatureMaster(target)
  123. if master == cid then
  124. return false
  125. end
  126.  
  127. if isInParty(cid) then
  128. if isPlayer(master) and getPlayerParty(cid) == getPlayerParty(master) then
  129. return false
  130. end
  131. end
  132. end
  133. end
  134.  
  135. if isPlayer(target) and (isPlayerGhost(target) or getPlayerLevel(target) <= getConfigValue('protectionLevel')) then
  136. return false
  137. end
  138.  
  139. if isSummon(cid) then
  140. local master = getCreatureMaster(cid)
  141. if master == target then
  142. return false
  143. end
  144.  
  145. if isSummon(target) then
  146. target = getCreatureMaster(target)
  147. end
  148.  
  149. if isPlayer(master) and isPlayer(target) and isInParty(master) and getPlayerParty(master) == getPlayerParty(target) then
  150. return false
  151. end
  152. end
  153.  
  154. return true
  155. end
  156.  
  157. local function doDamage(cid, position, n)
  158. for _, pos in pairs(position) do
  159. if canCreate(pos) then
  160. if damageEffect ~= CONST_ME_NONE then
  161. doSendMagicEffect(pos, damageEffect)
  162. end
  163.  
  164. local target = getTopCreature(pos).uid
  165. if canAttack(cid, target) then
  166. local health = -(getCreatureMaxHealth(target) * 0.1)
  167. doTargetCombatHealth(0, target, COMBAT_ENERGYDAMAGE, health, health, CONST_ME_NONE)
  168. end
  169. end
  170. end
  171.  
  172. if n > 0 then
  173. addEvent(doDamage, damageDelay, cid, position, n - 1)
  174. end
  175. end
  176.  
  177. function onCastSpell(cid, var)
  178. local pos = getThingPos(cid)
  179.  
  180. local positions = {}
  181. positions[VARIABLE_WALL] = {}
  182. positions[VARIABLE_PLAYER] = {}
  183. positions[VARIABLE_DAMAGE] = {}
  184.  
  185. for py = 1, #config do
  186. for px = 1, #config[py] do
  187. local var = config[py][px]
  188. if var ~= VARIABLE_NONE then
  189. local pos = {x = pos.x + (px - ((#config - 1) / 2) - 1), y = pos.y + (py - ((#config - 1) / 2) - 1), z = pos.z}
  190.  
  191. if var == VARIABLE_WALL then
  192. table.insert(positions[VARIABLE_WALL], pos)
  193. elseif var == VARIABLE_PLAYER then
  194. table.insert(positions[VARIABLE_PLAYER], pos)
  195. elseif var == VARIABLE_DAMAGE then
  196. table.insert(positions[VARIABLE_DAMAGE], pos)
  197. end
  198. end
  199. end
  200. end
  201.  
  202. doCreatureSetNoMove(cid, true)
  203. doCreateWalls(positions[VARIABLE_WALL])
  204. doSendEffect(positions[VARIABLE_PLAYER])
  205. doDamage(cid, positions[VARIABLE_DAMAGE], delay / damageDelay)
  206. addEvent(function()
  207. if isPlayer(cid) then
  208. doCreatureSetNoMove(cid, false)
  209. end
  210. end, delay)
  211. return true
  212. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement