Critical Claws.lua

main 158 lines · 5.3 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1local combat = Combat()
2combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
3combat:setParameter(COMBAT_PARAM_EFFECT, 1)
4
5-- Configura��es do cr�tico
6local criticalChance = 50 -- Chance de cr�tico em %
7local criticalMultiplier = 2.5 -- Multiplicador do dano cr�tico
8local isCritical = false -- Vari�vel para rastrear se ser� cr�tico
9
10-- Fun��o para definir os valores do dano
11function onGetFormulaValues(player, level, magicLevel)
12 local min = 50
13 local max = 100
14
15 -- Se for cr�tico, aplica o multiplicador
16 if isCritical then
17 min = min * criticalMultiplier
18 max = max * criticalMultiplier
19 player:say("Cr�tico!", TALKTYPE_MONSTER_SAY) -- Mensagem indicando dano cr�tico
20 end
21
22 return -min, -max
23end
24
25combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
26
27-- Efeitos visuais para diferentes dire��es
28local effects = {
29 [NORTH] = 110,
30 [EAST] = 106,
31 [SOUTH] = 104,
32 [WEST] = 109
33}
34
35-- Fun��o para aplicar dano nas 3 SQMs horizontais na frente do conjurador
36local function applyDamage(creature, startPos, distance)
37 local dir = creature:getDirection()
38 local currentPos = startPos
39 local targetFound = false
40
41 -- Itera sobre a �rea de dano
42 for i = 0, distance - 1 do
43 addEvent(function()
44 if not creature or creature:isRemoved() then return end
45
46 for offset = -1, 1 do
47 local tilePos
48 if dir == NORTH then
49 tilePos = Position(currentPos.x + offset, currentPos.y - 1, currentPos.z)
50 elseif dir == SOUTH then
51 tilePos = Position(currentPos.x + offset, currentPos.y + 1, currentPos.z)
52 elseif dir == EAST then
53 tilePos = Position(currentPos.x + 1, currentPos.y + offset, currentPos.z)
54 elseif dir == WEST then
55 tilePos = Position(currentPos.x - 1, currentPos.y + offset, currentPos.z)
56 end
57
58 local tile = Tile(tilePos)
59 if tile then
60 local target = tile:getTopCreature()
61 if target and (target:isMonster() or target:isPlayer()) and target:getId() ~= creature:getId() then
62 targetFound = true
63
64 -- Aplica o efeito 173 se for cr�tico
65 if isCritical then
66 target:getPosition():sendMagicEffect(173)
67 end
68
69 combat:execute(creature, Variant(target:getPosition()))
70 end
71 end
72 end
73
74 -- Move para a pr�xima posi��o de dano
75 if dir == NORTH then
76 currentPos.y = currentPos.y - 1
77 elseif dir == SOUTH then
78 currentPos.y = currentPos.y + 1
79 elseif dir == EAST then
80 currentPos.x = currentPos.x + 1
81 elseif dir == WEST then
82 currentPos.x = currentPos.x - 1
83 end
84 end, i * 100)
85 end
86
87 -- Se n�o encontrar nenhum alvo, usa a sequ�ncia 51, 52, 53
88 addEvent(function()
89 if not targetFound then
90 creature:setStorageValue(99917, 0)
91 end
92 end, distance * 100)
93end
94
95-- Fun��o para mostrar os efeitos visuais
96local function showEffectInFront(creature)
97 local dir = creature:getDirection()
98 local pos = creature:getPosition()
99 pos.x = pos.x + 1
100 pos.y = pos.y + 1
101 local effect = effects[dir] or CONST_ME_ENERGYAREA
102 pos:sendMagicEffect(effect)
103end
104
105-- Fun��o principal para lan�ar a magia
106function onCastSpell(creature, var)
107 local waittime = 0
108 local storage = 99916
109
110 if creature:getStorageValue(storage) > os.time() then
111 creature:sendCancelMessage("Voc� s� pode usar esta magia novamente em [" .. (creature:getStorageValue(storage) - os.time()) .. "] segundos.")
112 return false
113 end
114
115 creature:setStorageValue(storage, os.time() + waittime)
116
117 local originalOutfit = creature:getOutfit()
118
119 -- Calcula se ser� um ataque cr�tico antes de lan�ar a magia
120 isCritical = math.random(1, 100) <= criticalChance
121
122 -- Define a sequ�ncia de outfits com base no cr�tico
123 local outfits
124 if isCritical then
125 outfits = {{lookType = 70}, {lookType = 71}, {lookType = 72}} -- Sequ�ncia de cr�tico
126 else
127 outfits = {{lookType = 51}, {lookType = 52}, {lookType = 53}} -- Sequ�ncia padr�o
128 end
129
130 -- Troca o lookType durante a execu��o da magia
131 for i = 1, #outfits do
132 addEvent(function()
133 if creature and not creature:isRemoved() then
134 creature:setOutfit(outfits[i])
135 end
136 end, (i - 1) * 80)
137 end
138
139 -- Executa os efeitos visuais e o dano ap�s 500ms
140 addEvent(function()
141 if not creature or creature:isRemoved() then return end
142 playSound(creature, "rat_attack.ogg")
143 local startPos = creature:getPosition()
144 local distance = 1
145 showEffectInFront(creature)
146 applyDamage(creature, startPos, distance)
147 end, 200)
148
149 -- Restaura o outfit original ap�s o t�rmino da magia
150 addEvent(function()
151 if creature and not creature:isRemoved() then
152 creature:setOutfit(originalOutfit)
153 end
154 end, (#outfits * 80) + 100)
155
156 return false
157end
158
Top