Switch
New Member
- Joined
- Oct 27, 2020
- Messages
- 21
- Reaction score
- 3
I made a little magic system that works by updating the player's outfit ... but I would like suggestions on how I can improve my code
Lua:
SpellConfig = {
delay = 150,
animation = {
[1] = {
lookType = 1204,
damaged = false,
},
[2] = {
lookType = 1205,
damaged = false,
},
[3] = {
lookType = 1206,
damaged = false,
},
[4] = {
lookType = 1207,
damaged = true,
direction = true,
},
[5] = {
lookType = 1207,
damaged = true,
direction = true,
},
[6] = {
lookType = 1207,
damaged = true,
direction = true,
},
[7] = {
lookType = 1208,
damaged = false,
direction = true,
},
[8] = {
final = true,
damaged = false,
},
}
}
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
function onGetFormulaValues(player, level, maglevel)
local min = (level / 5) + (maglevel * 1.2) + 7
local max = (level / 5) + (maglevel * 2) + 12
return -min, -max
end
combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
local spell = Spell(SPELL_INSTANT)
function spell.onCastSpell(player, var)
local outfit = player:getOutfit()
local dir = player:getDirection()
local currentDelay = SpellConfig.delay
player:setMovementBlocked(true)
for index, animState in ipairs(SpellConfig.animation) do
addEvent(function()
if animState.final then
player:setMovementBlocked(false)
player:setOutfit(outfit)
else
local newOutfit = player:getOutfit()
newOutfit.lookType = animState.lookType
player:setOutfit(newOutfit)
end
if animState.direction then
player:move(dir, FLAG_IGNOREBLOCKCREATURE)
end
if animState.damaged then
var.pos = player:getPosition()
var.pos:sendMagicEffect(CONST_ME_HITBYFIRE)
combat:execute(player, var)
end
end, currentDelay - SpellConfig.delay)
currentDelay = currentDelay + SpellConfig.delay
end
end
spell:name("Konoha Senpuu")
spell:words("Konoha Senpuu")
spell:id(220)
spell:level(1)
spell:magicLevel(0)
spell:needTarget(false)
spell:isAggressive(true)
spell:register()