• 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 TFS 1.3 spell question

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
177
Location
Sweden
Is there any way you can randomize the spell area for each time casting an spell?

For example I have 3 areas setup like this:

Lua:
local area = {
{
    {1, 1, 1},
    {1, 3, 1},
    {1, 1, 1}
},{
    {0, 0, 0},
    {0, 3, 0},
    {0, 0, 0}
},{
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1 ,1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
}}

And i want to randomize between these 3, i tried using: (and a lot others)
Code:
combat:setArea(createCombatArea(area[math.random(1,3)]))
But since that only combat type will load during start, it will always throw the same area.

To make it even more complicated, this is actually a weapon script, so the statements Ive done might actually not be true for spells.
 
Is there any way you can randomize the spell area for each time casting an spell?

For example I have 3 areas setup like this:

Lua:
local area = {
{
    {1, 1, 1},
    {1, 3, 1},
    {1, 1, 1}
},{
    {0, 0, 0},
    {0, 3, 0},
    {0, 0, 0}
},{
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1 ,1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
}}

And i want to randomize between these 3, i tried using: (and a lot others)
Code:
combat:setArea(createCombatArea(area[math.random(1,3)]))
But since that only combat type will load during start, it will always throw the same area.

To make it even more complicated, this is actually a weapon script, so the statements Ive done might actually not be true for spells.
I believe that this portion of the spell needs to be set during server startUp, so it's impossible to randomise the area.

However.. if you created 3 identical 'combats'
aka, combat1, combat2, combat3

You could randomise the combat that is used, and would achieve the same result.
 
I believe that this portion of the spell needs to be set during server startUp, so it's impossible to randomise the area.

However.. if you created 3 identical 'combats'
aka, combat1, combat2, combat3

You could randomise the combat that is used, and would achieve the same result.
Thats how i did it with a spell, but it looks so messy, thanks however for letting me know.
 
Thats how i did it with a spell, but it looks so messy, thanks however for letting me know.
I mean, I might be wrong since I've never tried with tfs 1.0+, but you can test if you want.

Here's how I'd try it.
Lua:
local areas = {
    {
        {1, 1, 1},
        {1, 3, 1},
        {1, 1, 1}
    },
    {
        {0, 0, 0},
        {0, 3, 0},
        {0, 0, 0}
    },
    {
        {1, 1, 1, 1, 1},
        {1, 1, 1, 1, 1},
        {1, 1, 3, 1 ,1},
        {1, 1, 1, 1, 1},
        {1, 1, 1, 1, 1}
    }
}



function onCast(blah blah)
  
    -- actual important part. lol
    local rand = math.random(#areas)
    combat:setArea(createCombatArea(areas[rand]))

    return combat:blah blah blah
end

-- Edit

Yeah, it just doesn't work.
Have to do the 'messy' 3 combats method.

Untitled.png
 
Lua:
local areas = {AREA_SQUARE1X1, AREA_CIRCLE3X3}
local combats = {}

for i = 1, #areas, 1 do
    local combat = Combat()
    combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
    combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HOLYAREA)
    combat:setArea(createCombatArea(areas[i]))
    function onGetFormulaValues(player, level, magicLevel)
        local min = (level / 5) + (magicLevel * 5) + 25
        local max = (level / 5) + (magicLevel * 6.2) + 45
        return -min, -max
    end
    combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
    table.insert(combats, #combats + 1, combat)
end

function onCastSpell(creature, variant)
    return combats[math.random(1, #combats)]:execute(creature, variant)
end
 
Lua:
local areas = {AREA_SQUARE1X1, AREA_CIRCLE3X3}
local combats = {}

for i = 1, #areas, 1 do
    local combat = Combat()
    combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
    combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HOLYAREA)
    combat:setArea(createCombatArea(areas[i]))
    function onGetFormulaValues(player, level, magicLevel)
        local min = (level / 5) + (magicLevel * 5) + 25
        local max = (level / 5) + (magicLevel * 6.2) + 45
        return -min, -max
    end
    combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
    table.insert(combats, #combats + 1, combat)
end

function onCastSpell(creature, variant)
    return combats[math.random(1, #combats)]:execute(creature, variant)
end
Ofcourse, you can do like that, clever. I went with the messy method however, the math.random is a really good tool to specify chances etc.
 
Back
Top