• 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!

Solved spell beam

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,483
Solutions
9
Reaction score
215
hello folks I'm trying make a custom spell for a boss ...
the I want that the monster call the spell with delay of 7 seconds to give the damage
but my spell is a "beam" then I want to fix the direction that the spells happen
actually my spell works fine about the damage and the timer but the direction always is in the north
how fix it ?
then, my spells.xml
Code:
<instant name="zacutter beam" words="###418" aggressive="1" direction="1" blockwalls="1" needlearn="1" script="monster/zacutter beam.lua"/>
and the script zacutter beam.lua
Code:
local voc = {1, 2, 3, 4, 5, 6, 7, 8}

    arr = {
    {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, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
    }

local area = createCombatArea(arr)

local combat = Combat()
combat:setArea(area)

function onTargetTile(creature, pos)
    local creatureTable = {}
    local n, i = Tile({x=pos.x, y=pos.y, z=pos.z}).creatures, 1
    if n ~= 0 then
        local v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        while v ~= 0 do
            if isCreature(v) == true then
                table.insert(creatureTable, v)
                if n == #creatureTable then
                    break
                end
            end
            i = i + 1
            v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        end
    end
    if #creatureTable ~= nil and #creatureTable > 0 then
        for r = 1, #creatureTable do
            if creatureTable[r] ~= creature then
                local min = 1000
                local max = 1000
                local player = Player(creatureTable[r])
               
                if isPlayer(creatureTable[r]) == true and isInArray(voc, player:getVocation():getId()) then
                    doTargetCombatHealth(creature, creatureTable[r], COMBAT_ENERGYDAMAGE, -min, -max, CONST_ME_NONE)
                elseif isMonster(creatureTable[r]) == true then
                    doTargetCombatHealth(creature, creatureTable[r], COMBAT_ENERGYDAMAGE, -min, -max, CONST_ME_NONE)
                end
            end
        end
    end
    pos:sendMagicEffect(CONST_ME_YELLOWENERGY)
    return true
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

local function delayedCastSpell(cid, var)
    local creature = Creature(cid) 
    if not creature then 
        return 
    end
    if creature:getHealth() >= 1 then
        creature:say("ZZZZZZZIIIIII! TAKE MY WAVE!", TALKTYPE_MONSTER_YELL)
        return combat:execute(creature, positionToVariant(creature:getPosition()))
    end
    return
end

function onCastSpell(creature, var)
    creature:say("Zacutter is charging your ultimate! RUN!", TALKTYPE_MONSTER_YELL)
    addEvent(delayedCastSpell, 7000, creature:getId(), var)
    return true
end
thanks
 
Solution
To get fixed direction you need position in variant to be one square ahead of you.
You can save this function in lib and use it when you need:
Code:
function getCasterPosition(position, direction)
    if(direction == NORTH) then
        return {x=position.x, y=position.y-1, z=position.z}
    elseif(direction == EAST) then
        return {x=position.x+1, y=position.y, z=position.z}
    elseif(direction == SOUTH) then
        return {x=position.x, y=position.y+1, z=position.z}
    elseif(direction == WEST) then
        return {x=position.x-1, y=position.y, z=position.z}
    end

    return position
end
and do combat like this:
Code:
combat:execute(creature, positionToVariant(getCasterPosition(creature:getPosition()...
I am not familiar with lua spells at all, but I see that the arr map of the spell effect seem to only be in one direction?

Perhaps change it up depending on Creature:getDirection() ?
Etc use "arrNorth" spell map for the north direction.

What does the values in the arr map represent? Could it be they represent direction already?
Perhaps try this, see what happens:
Code:
 arr = {
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {4, 4, 4, 4, 4, 4, 0, 2, 2, 2, 2, 2, 2},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    }
 
Just do it like this;

Code:
arr = {
    [0] = {
        {0, 0, 0, .....}
    },
    [1] = {
    },
    [2] = {
    },
    [3] = {
    }
}
also, 3 is the creature/player position not 2.

where the index being creature:getdirection().[/code]
 
I am not familiar with lua spells at all, but I see that the arr map of the spell effect seem to only be in one direction?

Perhaps change it up depending on Creature:getDirection() ?
Etc use "arrNorth" spell map for the north direction.

What does the values in the arr map represent? Could it be they represent direction already?
Perhaps try this, see what happens:
Code:
 arr = {
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {4, 4, 4, 4, 4, 4, 0, 2, 2, 2, 2, 2, 2},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    }
I did not tested it but seems that don't work, the 3 is the creature and it will have effect and damage, the 2 is the creature but don't have effect or damage, the 1 is just the area that will have effect and damage...
Just do it like this;

Code:
arr = {
    [0] = {
        {0, 0, 0, .....}
    },
    [1] = {
    },
    [2] = {
    },
    [3] = {
    }
}

where the index being creature:getdirection().
could you explain better ? or write some exemple, with the line creature:getDirection()
 
To get fixed direction you need position in variant to be one square ahead of you.
You can save this function in lib and use it when you need:
Code:
function getCasterPosition(position, direction)
    if(direction == NORTH) then
        return {x=position.x, y=position.y-1, z=position.z}
    elseif(direction == EAST) then
        return {x=position.x+1, y=position.y, z=position.z}
    elseif(direction == SOUTH) then
        return {x=position.x, y=position.y+1, z=position.z}
    elseif(direction == WEST) then
        return {x=position.x-1, y=position.y, z=position.z}
    end

    return position
end
and do combat like this:
Code:
combat:execute(creature, positionToVariant(getCasterPosition(creature:getPosition(), creature:getDirection())))
 
Solution
To get fixed direction you need position in variant to be one square ahead of you.
You can save this function in lib and use it when you need:
Code:
function getCasterPosition(position, direction)
    if(direction == NORTH) then
        return {x=position.x, y=position.y-1, z=position.z}
    elseif(direction == EAST) then
        return {x=position.x+1, y=position.y, z=position.z}
    elseif(direction == SOUTH) then
        return {x=position.x, y=position.y+1, z=position.z}
    elseif(direction == WEST) then
        return {x=position.x-1, y=position.y, z=position.z}
    end

    return position
end
and do combat like this:
Code:
combat:execute(creature, positionToVariant(getCasterPosition(creature:getPosition(), creature:getDirection())))
thank you, your original function works with an issue, to all directions was the adverse
north beam to south etc...
then I invert the function
Code:
function getCasterPosition(position, direction)
    if(direction == SOUTH) then
        return {x=position.x, y=position.y-1, z=position.z}
    elseif(direction == WEST) then
        return {x=position.x+1, y=position.y, z=position.z}
    elseif(direction == NORTH) then
        return {x=position.x, y=position.y+1, z=position.z}
    elseif(direction == EAST) then
        return {x=position.x-1, y=position.y, z=position.z}
    end

    return position
end
 
or you can just do it like this;

Code:
arrSquare = {
   {0, 3, 0},
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1},
}

arrDiag = {
   {1, 1, 0, 0, 0, 0, 0, 0, 0},
   {1, 1, 1, 1, 0, 0, 0, 0, 0},
   {0, 1, 1, 1, 0, 0, 0, 0, 0},
   {0, 1, 1, 1, 1, 0, 0, 0, 0},
   {0, 0, 0, 1, 1, 1, 1, 0, 0},
   {0, 0, 0, 0, 1, 1, 1, 0, 0},
   {0, 0, 0, 0, 1, 1, 1, 1, 1},   
   {0, 0, 0, 0, 0, 0, 1, 1, 0},
   {0, 0, 0, 0, 0, 0, 1, 0, 3}
}

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATH)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_DEATH)
combat:setArea(createCombatArea(arrSquare, arrDiag)

arrdiag isn't exactly like waht u want, but cba to sit and fix it sorry :D
 

Similar threads

Back
Top