• 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 How can I create custom monster spells?

drakylucas

Intermediate OT User
Joined
Dec 15, 2015
Messages
236
Solutions
7
Reaction score
121
Hello guys, I'm editing this topic since I solved some of problems that I had describe.
My last doubt (I guess): How I can dynamically change the spell area?

this is my current spell (for monster):
Code:
local areas = {AREA_CROSS1X1, AREA_SQUARE1X1}
local area = areas[math.random(1,#areas)]


local combat = Combat()
local combat2 = Combat()


combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat:setArea(createCombatArea(area))

combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat2:setArea(createCombatArea(area))
combat2:setFormula(COMBAT_FORMULA_DAMAGE,-10000, 0, -50000, 0)

local function executeSpell(n, creature, variant)
    if(Creature(creature)) then
        print("Test - n = "..n)
        variant.pos = Creature(creature):getPosition()
        if(n < 3) then
            combat:execute(creature, variant)
            return addEvent(executeSpell,800, n+1, creature, variant)
        else
            return combat2:execute(creature,variant)
        end
    end
end

function onCastSpell(creature, variant)
    return executeSpell(1, creature:getId(),variant)
end

The problem is: I can't use combat:setArea inside onCastSpell, because the TFS needs to load it before the execution of the spell (I get an error if I try to use it inside onCastSpell), and this
Code:
local area = areas[math.random(1,#areas)]
is executing just 1 time, so all times the spell that should be dynamic is having the same area.

Thanks
 
Last edited:
Edit:
I managed to do it, but I think it's a little WOP (POG, in portuguese)

Lua:
local areas = {AREA_CROSS1X1, AREA_SQUARE1X1}

local combat = Combat()
local combatWithDamage = Combat()

local combat2 = Combat()
local combat2WithDamage = Combat()

local combats = {
    [1] = {combat, combatWithDamage},
    [2] = {combat2, combat2WithDamage}
}

-- creating combat1
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat:setArea(createCombatArea(areas[1]))

combatWithDamage:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatWithDamage:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combatWithDamage:setArea(createCombatArea(areas[1]))
combatWithDamage:setFormula(COMBAT_FORMULA_DAMAGE,-10000, 0, -50000, 0)

--creating combat 2
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat2:setArea(createCombatArea(areas[2]))

combat2WithDamage:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2WithDamage:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat2WithDamage:setArea(createCombatArea(areas[2]))
combat2WithDamage:setFormula(COMBAT_FORMULA_DAMAGE,-10000, 0, -50000, 0)

-- function to loop
local function executeSpell(n, combatNumber, creature, variant)
    if(Creature(creature)) then
        variant.pos = Creature(creature):getPosition()
        if(n < 3) then
            combats[combatNumber][1]:execute(creature, variant)
            return addEvent(executeSpell,800, n+1,combatNumber, creature, variant)
        else
            return combats[combatNumber][2]:execute(creature,variant)
        end
    end
end

function onCastSpell(creature, variant)
    return executeSpell(1, math.random(1,#combats), creature:getId(),variant)
end


Is there a better way to do this, without creating too many combats? (The only thing that changes from one to other is the area)
 
Back
Top