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

sendAreaEffect(centrePosition, effectTable, magicEffect, direction)

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,756
Solutions
578
Reaction score
5,305
Untested, but this would replace the default way of sending area effects, via the combat system

So instead of this..
Lua:
local gfbEffect = Combat()
gfbEffect:setArea(createCombatArea(AREA_CIRCLE3X3))

    local positions = gfbEffect:getPositions(0, {
        type = 2, -- # VARIANT_POSITION
        pos = player:getPosition()
    })
    
    for i = 1, #positions do
        positions[i]:sendMagicEffect(11)
    end
You would just do this
Lua:
sendAreaEffect(player:getPosition(), AREA_CIRCLE3X3, 11)

Below is some green text explanation, and the function.
Let me know if you test it out.
Lua:
--[[
    -> centrePosition = centre of area
        Example;
            Position(1000, 1000, 7)
            
    -> effectTable = determines area. Modular. Must be uniform rectangle
        Example;
            AREA_WAVE3 = {
                {1, 1, 1},
                {1, 1, 1},
                {0, 3, 0}
            }
            3 = centre + effect
            2 = centre
            1 = effect
            0 = no effect
            
    -> magicEffect = effect to use
        Example;
            CONST_ME_POFF
    
    -> direction = direction of spell (assumes effectTable is north) (rotates spell on x/y plane)
        Example;
            DIRECTION_NORTH or 0
            DIRECTION_EAST  or 1
            DIRECTION_SOUTH or 2
            DIRECTION_WEST  or 3
--]]
Lua:
--[[
    Example Usage;
    
        local AREA_WAVE3 = {
            {1, 1, 1},
            {1, 1, 1},
            {0, 3, 0}
        }
        
        sendAreaEffect(Position(1000, 1000, 7), AREA_WAVE3, CONST_ME_POFF) -- direction omitted, defaults north
        sendAreaEffect(Position(1000, 1000, 7), AREA_WAVE3, CONST_ME_POFF, 1) -- south (mirror/rotate 180 degree)
        sendAreaEffect(Position(1000, 1000, 7), AREA_WAVE3, CONST_ME_POFF, DIRECTION_EAST) -- east (rotate 90 degree clockwise)
]]--
put into data/lib as a custom function
Lua:
function sendAreaEffect(centrePosition, effectTable, magicEffect, direction)

    local centre = 0
    local length = #effectTable   -- north/south (amount of arrays in main array)
    local width = #effectTable[1] --  west/east (amount of items in each array)
    
    for _length = 1, length do
        if centre ~= 0 then
            break
        end
        for _width = 1, do
            if effectTable[_length][_width] > 1 then
                centre = {length = _length, width = _width}
                break
            end
        end
    end
    
    if centre == 0 then
        print("Lua Error: no centre found for effectTable. (3 = centre + effect | 2 = centre | 1 = effect | 0 = no effect)")
        return
    end
    
    local x_offset = length - centre.length -- 0
    local y_offset = width - centre.width -- 1
    
    if not Position(centrePosition) then -- Idk if this works or not. Would have to test lol
        print("Lua Error: a valid position was not used.")
        return
    end
    
    for _length = 1, length do
        for _width = 1, width do
            if effectTable[_length][_width] == 1 or effectTable[_length][_width] == 3 then
                local effectPosition = Position(centrePosition.x + ((_width - width) + x_offset), centrePosition.y + ((_length - length) + y_offset), centrePosition.z)
                if direction then
                    if direction == DIRECTION_NORTH then
                        -- do nothing
                    elseif direction == DIRECTION_SOUTH then
                        effectPosition = Position(effectPosition.x * -1, effectPosition.y * -1, effectPosition.z)
                    elseif direction == DIRECTION_EAST then
                        effectPosition = Position(effectPosition.y, effectPosition.x * -1, effectPosition.z)
                    elseif direction == DIRECTION_WEST then
                        effectPosition = Position(effectPosition.y * -1, effectPosition.x, effectPosition.z)
                    else
                        print("Lua Error: not a valid direction. use 0,1,2,3 or DIRECTION_SOUTH / WEST / EAST / NORTH")
                        return
                    end
                end
                effectPosition:sendMagicEffect(magicEffect)
            end
        end
    end
    
end
 
Tested, now that I have a server up, and here's the fixed and working code.

Lua:
function sendAreaEffect(centrePosition, effectTable, magicEffect, direction)
    
    local centre = 0
    local length = #effectTable   -- north/south (amount of arrays in main array)
    local width = #effectTable[1] --  west/east (amount of items in each array)
    
    for _length = 1, length do
        for _width = 1, width do
            if effectTable[_length][_width] > 1 then
                centre = {length = _length, width = _width}
                print(_length, _width)
                break
            end
        end
        if centre ~= 0 then
            break
        end
    end
    
    if centre == 0 then
        print("Lua Error: no centre found for effectTable. (3 = centre + effect | 2 = centre | 1 = effect | 0 = no effect)")
        return
    end
    
    if not Position(centrePosition) then -- Idk if this works or not. Would have to test lol
        print("Lua Error: a valid position was not used.")
        return
    end
    
    for _length = 1, length do
        for _width = 1, width do
            local effectType = effectTable[_length][_width]
            if effectType == 1 or effectType == 3 then
                local deltaX = _width - centre.width
                local deltaY = _length - centre.length
                
                if direction then
                    if direction == DIRECTION_NORTH then
                        deltaY = deltaY - 1
                    elseif direction == DIRECTION_SOUTH then
                        deltaY = -deltaY + 1
                    elseif direction == DIRECTION_EAST then
                        local temp = deltaX
                        deltaX = -deltaY + 1
                        deltaY = temp
                    elseif direction == DIRECTION_WEST then
                        local temp = deltaX
                        deltaX = deltaY - 1
                        deltaY = -temp
                    else
                        print("Lua Error: not a valid direction. use 0,1,2,3 or DIRECTION_SOUTH / WEST / EAST / NORTH")
                        return
                    end
                end
                local effectPosition = Position(centrePosition.x + deltaX, centrePosition.y + deltaY, centrePosition.z)
                effectPosition:sendMagicEffect(magicEffect)
            end
        end
    end 
end
 
Back
Top