• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Magic attack monster

Azerty

Active Member
Joined
Apr 15, 2022
Messages
322
Solutions
4
Reaction score
34
Good morning, does anyone know how I can make this spell damage monsters?

Lua:
local condition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_SUBID, 88888)
condition:setParameter(CONDITION_PARAM_TICKS, 5 * 1000)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 0.01)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 5 * 1000)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat:setFormula(COMBAT_FORMULA_DAMAGE, -7000, 0, -10000, 0)

 arr1 = {
{0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

local area1 = createCombatArea(arr1)
combat:setArea(area1)

-----------------------------------------------------------------------------

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat2:setFormula(COMBAT_FORMULA_DAMAGE, -7000, 0, -10000, 0)

 arr2 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

local area2 = createCombatArea(arr2)
combat2:setArea(area2)

--------------------------------------------------------------------------

local combat3 = Combat()
combat3:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat3:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat3:setFormula(COMBAT_FORMULA_DAMAGE, -7000, 0, -10000, 0)

 arr3 = {
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

local area3 = createCombatArea(arr3)
combat3:setArea(area3)

--------------------------------------------------------------------------

local combat4 = Combat()
combat4:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat4:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat4:setFormula(COMBAT_FORMULA_DAMAGE, -7000, 0, -10000, 0)

 arr4 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

local area4 = createCombatArea(arr4)
combat4:setArea(area4)

--------------------------------------------------------------

function onCastSpell(creature, var)
    if not creature:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT, 88888) then
        creature:addCondition(condition)
        addEvent(function(cid, var)
        local creature = Creature(cid)
        if not creature then
            return
        end
        if creature:getDirection() == 0 then
            combat:execute(creature, positionToVariant(creature:getPosition()))
        elseif creature:getDirection() == 1 then
            combat2:execute(creature, positionToVariant(creature:getPosition()))
        elseif creature:getDirection() == 2 then
            combat3:execute(creature, positionToVariant(creature:getPosition()))
        elseif creature:getDirection() == 3 then
            combat4:execute(creature, positionToVariant(creature:getPosition()))
        end
end, 4000, creature:getId(), var)
    else
        return
    end
    return true
end
 
By casting it?
yes
Post automatically merged:

I managed to make this script but I'm not able to make sure that the magic effect doesn't occur in the same sqm as the monster, can anyone help me?

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_SMALLCLOUDS)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onTargetCreature(creature, target)
    if creature:isPlayer() or target:isPlayer() or not creature:isFriend(target) then
        return false
    end
    
    local creaturePos = creature:getPosition() -- Posição do monstro
    local creatureDir = creature:getDirection()
    
    local targetPositions = getTargetPositions(creaturePos, creatureDir)
    
    for _, pos in ipairs(targetPositions) do
 
        if not samePosition(pos, creaturePos) then
            doAreaCombatHealth(creature:getId(), COMBAT_DEATHDAMAGE, pos, AREA_BEAM, -7500, -7500, CONST_ME_SMALLCLOUDS)
        end
    end

    return true
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

function getTargetPositions(startPos, direction)
    local targetPositions = {}
    local nextPos = startPos
 
    nextPos = getNextPositionInDirection(nextPos, direction)

    for i = 1, 3 do

        if samePosition(nextPos, startPos) then

            nextPos = getNextPositionInDirection(nextPos, direction)
        end

        table.insert(targetPositions, nextPos)
        
        nextPos = getNextPositionInDirection(nextPos, direction)
    end
    
    return targetPositions
end

function samePosition(pos1, pos2)
    return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z
end

function getNextPositionInDirection(startPos, direction)
    local nextPos = {x = startPos.x, y = startPos.y, z = startPos.z}
    
    if direction == NORTH then
        nextPos.y = nextPos.y - 1
    elseif direction == EAST then
        nextPos.x = nextPos.x + 1
    elseif direction == SOUTH then
        nextPos.y = nextPos.y + 1
    elseif direction == WEST then
        nextPos.x = nextPos.x - 1
    end
    
    return nextPos
end
 
Last edited:
Back
Top