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

Area effect using math?

Zazeros

Member
Joined
Feb 13, 2012
Messages
67
Reaction score
17
Hello guys, my title can be a little confusing, but I will try to explain.

In my script (action), i want an area effect when the action happen, and its simple... But i want something big, very big, and so, i will have to put sqm per sqm in the whole area that i want. I think an example will help you guys understand:

When the player clicks in an certain item, it will happen an effect in a certain area, like this: doSendMagicEffect({x= 1567, y= 976, z= 7}, 12), its simple.
But, if i want in area, like 4x4, will i need to put sqm per sqm, 16 times? Or is there a way to use math and select an area and it will happen in the whole area?

Also, i want it to propagate, like it will happen 4x4 first, then 8x8, then 16x16, something like that
Please, help =(
 
Solution
The naive approach (not tested):

Lua:
local config = {
    [0] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1003, y = 1003, z = 7}
    },
    [1] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1007, y = 1007, z = 7}
    },
    [2] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1015, y = 1015, z = 7}
    }
}

function do_area_effect(from_pos, to_pos, effect)
    for i = from_pos.z, to_pos.z do
        for j = from_pos.x, to_pos.x do
            for k = from_pos.y, to_pos.y do
                doSendMagicEffect({x = j, y = k, z = i}, effect)
            end...
The naive approach (not tested):

Lua:
local config = {
    [0] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1003, y = 1003, z = 7}
    },
    [1] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1007, y = 1007, z = 7}
    },
    [2] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1015, y = 1015, z = 7}
    }
}

function do_area_effect(from_pos, to_pos, effect)
    for i = from_pos.z, to_pos.z do
        for j = from_pos.x, to_pos.x do
            for k = from_pos.y, to_pos.y do
                doSendMagicEffect({x = j, y = k, z = i}, effect)
            end
        end
    end
end

for idx, cfg in ipairs(config) do
    addEvent(do_area_effect, idx * 200, cfg.from_pos, cfg.to_pos, cfg.effect)
end
 
Solution
The naive approach:

Lua:
local config = {
    [0] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1003, y = 1003, z = 7}
    },
    [1] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1007, y = 1007, z = 7}
    },
    [2] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1015, y = 1015, z = 7}
    }
}

function do_area_effect(from_pos, to_pos, effect)
    for i = from_pos.z, to_pos.z do
        for j = from_pos.x, to_pos.x do
            for k = from_pos.y, to_pos.y do
                doSendMagicEffect({x = j, y = k, z = i}, effect)
            end
        end
    end
end

for idx, cfg in ipairs(config) do
    addEvent(do_area_effect, idx * 200, cfg.from_pos, cfg.to_pos, cfg.effect)
end
I was basically going to write the same thing.

If the positions aren't static, and you're using the player as the focal point, you can do the math OP wanted.

Lua:
local range = 4
local playerPosition = player:getPosition()
local fromPos = Position(playerPosition.x - range, playerPosition.y - range, playerPosition.z)
local toPos = Position(playerPosition.x + range, playerPosition.y + range, playerPosition.z)

do_area_effect(fromPos, toPos, effect)
 
Code:
function something(caster, range, steps)
    if steps > 0 and Player(caster) then
        addEvent(something, 2000, caster, range + 4, steps - 1)
    end
end

something(player:getId(), 4, 3)

You can mix it with examples above
 
Last edited:
@amatria , @Xikini , @zbizu
Guys, thank you very much, sorry for my dumbness, but how can I select which config should happen next?1624733123847.png
I though it was here, but can't figure how

for idx, cfg in ipairs(config) do
addEvent(do_area_effect, idx * 200, cfg.from_pos, cfg.to_pos, cfg.effect)
end
 
@amatria , @Xikini , @zbizu
Guys, thank you very much, sorry for my dumbness, but how can I select which config should happen next?View attachment 59855
I though it was here, but can't figure how

for idx, cfg in ipairs(config) do
addEvent(do_area_effect, idx * 200, cfg.from_pos, cfg.to_pos, cfg.effect)
end
Lua:
config[0].effect
Lua:
do_area_effect(config[0].from_pos, config[0].to_pos, config[0].effect)
 
I saw the other answer just now, sry

Edit: Nice, now i understand. Thank you guys s2
This is what I meant.
Lua:
local config = {
    [0] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1003, y = 1003, z = 7}
    },
    [1] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1007, y = 1007, z = 7}
    },
    [2] = {
        effect = CONST_ME_POFF,
        from_pos = {x = 1000, y = 1000, z = 7},
        to_pos = {x = 1015, y = 1015, z = 7}
    }
}

local function do_area_effect(from_pos, to_pos, effect)
    for i = from_pos.z, to_pos.z do
        for j = from_pos.x, to_pos.x do
            for k = from_pos.y, to_pos.y do
                doSendMagicEffect({x = j, y = k, z = i}, effect)
            end
        end
    end
end

function onUse(blah, blah, blah)
    do_area_effect(config[0].from_pos, config[0].to_pos, config[0].effect) -- immediate
    addEvent(do_area_effect, 1000, config[1].from_pos, config[1].to_pos, config[1].effect) -- 1 second delay
    addEvent(do_area_effect, 2000, config[2].from_pos, config[2].to_pos, config[2].effect) -- 2 second delay
    return true
end
 
@Xikini Why the last one always happens twice? If the last one is 2 sec delay, the 'chain effect' will happen, and then 2 sec later it will happen the last one again, i.e, 4 seconds later
Edit: Actually, not the last one, they all happens twice or 3x
Lua:
    addEvent(do_area_effect, idx * 1000, config[0].from_pos, config[0].to_pos, config[0].effect)
    addEvent(do_area_effect, idx * 3000, config[1].from_pos, config[1].to_pos, config[1].effect)
    addEvent(do_area_effect, idx * 5000, config[2].from_pos, config[2].to_pos, config[2].effect)
    addEvent(do_area_effect, idx * 7000, config[3].from_pos, config[3].to_pos, config[3].effect)
 
Last edited:
@amatria
Lua:
--by Richi~ --
function onUse(cid, item, frompos, item2, topos)

local gems = {13375}
local altars = {{33134}}

local type = item.type
if type == 0 then
type = 1
end


if isInArray(gems, item.itemid)== TRUE then
for aa=1, #gems do
if item.itemid == gems[aa] then
a=aa
end
end
if isInArray(altars[a], item2.uniqueid)== TRUE then
if getPlayerStorageValue(cid, 176540) <= 20 then
doPlayerSendTextMessage(cid,25, "V")
return false
end
doPlayerRemoveItem(cid, 13375, 1)
doSendMagicEffect({x= 1567, y= 976, z= 7}, 12)




local config = {
    [0] = {
        effect = 12,
        from_pos = {x = 1565, y = 974, z = 7},
        to_pos = {x = 1568, y = 977, z = 7}
    },
    [1] = {
        effect = 12,
        from_pos = {x = 1562, y = 973, z = 7},
        to_pos = {x = 1570, y = 979, z = 7}
    },
    [2] = {
        effect = 12,
        from_pos = {x = 1561, y = 972, z = 7},
        to_pos = {x = 1573, y = 981, z = 7}
    },
    [3] = {
        effect = 12,
        from_pos = {x = 1548, y = 962, z = 7},
        to_pos = {x = 1587, y = 991, z = 7}
    }
}

function do_area_effect(from_pos, to_pos, effect)
    for i = from_pos.z, to_pos.z do
        for j = from_pos.x, to_pos.x do
            for k = from_pos.y, to_pos.y do
                doSendMagicEffect({x = j, y = k, z = i}, effect)
            end
        end
    end
end

for idx, cfg in ipairs(config) do
    addEvent(do_area_effect, idx * 1000, config[0].from_pos, config[0].to_pos, config[0].effect)
    addEvent(do_area_effect, idx * 3000, config[1].from_pos, config[1].to_pos, config[1].effect)
    addEvent(do_area_effect, idx * 5000, config[2].from_pos, config[2].to_pos, config[2].effect)
    addEvent(do_area_effect, idx * 7000, config[3].from_pos, config[3].to_pos, config[3].effect)
end


        
setPlayerStorageValue(cid,176540,22)
doPlayerSendTextMessage(cid,25, "")

else
return 2
end

end
else
return 0
end
return 1
end
 
Back
Top