• 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 0.X] Self destruction spell

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,444
Solutions
17
Reaction score
168
Location
Brazil
Hello guys, Im creating a monster who will explode, generating a huge damage and killing itself. Im searching for codes but found nothing. I've got this one but dont work (monster dont do damage, just die and spell animation dont appear). Can u guys please help me to fix or create a new one?

LUA:
local combat_arr = {
[1] = AREA_CROSS1X1,
[2] = AREA_CIRCLE2X2,
[3] = AREA_CIRCLE3X3
}

local dmin, dmax = 3000, 5000
local combat = {} -- keep empty
local monsters = true -- true or false
local suicide = true -- true or false

function onGetFormulaValues()
    return - math.random(dmin, dmax)
end

for i = 1, 3 do
    combat[i] = createCombatObject()
    setCombatParam(combat[i], COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat[i], COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
    setCombatCallback(combat[i], CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues") 
    area = createCombatArea(combat_arr[i])
    setCombatArea(combat[i], area)
end

local function newCombat(uid, combat, var)
    if isPlayer(uid) then    
        if not isPlayer(getThingFromPos(var.pos)) and not monsters then
            dmin, dmax = 0, 0
        end
        var.pos = getThingPos(uid)
        doCombat(uid, combat, var)
    end
    return true
end

function onCastSpell(cid, var)    
        newCombat(cid, combat[1], var) 
        addEvent(500, newCombat, cid, combat[2], var)
        addEvent(1000, newCombat, cid, combat[3], var)    
        if suicide then 
            addEvent(10001, doCreatureAddHealth, cid, -getCreatureHealth(cid))
        end 
    return true
end
 
Try this:
LUA:
local warn = true

local combatDamage, warning = createCombatObject(), createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(warning, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(warning, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea, warningArea = createCombatArea(AREA_CROSS5X5), createCombatArea(AREA_CIRCLE3X3)
setCombatArea(combatDamage, combatDamageArea)
setCombatArea(warning, warningArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    function explode()
        if warn then return doCombat(cid, warning, var) end
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        local event = addEvent(function()
            if isPlayer(cid) or isMonster(cid) then
                doCombat(cid, combatDamage, var)
            end
        end, 500)

        return event
    end

    return explode()
end
Post automatically merged:

To determine the damage, you need to add a XML tag to a monster, something like this:
XML:
<attack name="explode" interval="3000" chance="13" min="-1000" max="-3000"/>
 
Try this:
LUA:
local warn = true

local combatDamage, warning = createCombatObject(), createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(warning, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(warning, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea, warningArea = createCombatArea(AREA_CROSS5X5), createCombatArea(AREA_CIRCLE3X3)
setCombatArea(combatDamage, combatDamageArea)
setCombatArea(warning, warningArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    function explode()
        if warn then return doCombat(cid, warning, var) end
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        local event = addEvent(function()
            if isPlayer(cid) or isMonster(cid) then
                doCombat(cid, combatDamage, var)
            end
        end, 500)

        return event
    end

    return explode()
end
Post automatically merged:

To determine the damage, you need to add a XML tag to a monster, something like this:
XML:
<attack name="explode" interval="3000" chance="13" min="-1000" max="-3000"/>
Seems better then before, now monster hit fire in area, but dont die (or get lost) after this.
 
Try:
LUA:
local warn = true

local combatDamage, warning = createCombatObject(), createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(warning, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(warning, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea, warningArea = createCombatArea(AREA_CROSS5X5), createCombatArea(AREA_CIRCLE3X3)
setCombatArea(combatDamage, combatDamageArea)
setCombatArea(warning, warningArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    if warn then
        return doCombat(cid, warning, var)
    end
    function combat()
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        return doCombat(cid, combatDamage, var)
    end

    addEvent(combat, 1000)
end
 
Try:
LUA:
local warn = true

local combatDamage, warning = createCombatObject(), createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(warning, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(warning, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea, warningArea = createCombatArea(AREA_CROSS5X5), createCombatArea(AREA_CIRCLE3X3)
setCombatArea(combatDamage, combatDamageArea)
setCombatArea(warning, warningArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    if warn then
        return doCombat(cid, warning, var)
    end
    addEvent(function()
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        return doCombat(cid, combatDamage, var)
    end, 500)
end
Same thing, the monster do the hit (or explosion) but keep alive. I want it desappear after explode.
 
If you want to do creature disappear, try this:
LUA:
local warn = true

local combatDamage, warning = createCombatObject(), createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(warning, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(warning, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea, warningArea = createCombatArea(AREA_CROSS5X5), createCombatArea(AREA_CIRCLE3X3)
setCombatArea(combatDamage, combatDamageArea)
setCombatArea(warning, warningArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    if warn then
        return doCombat(cid, warning, var)
    end
    function combat()
        doRemoveCreature(cid)
        return doCombat(cid, combatDamage, var)
    end

    addEvent(combat, 1000)
end
 
If you want to do creature disappear, try this:
LUA:
local warn = true

local combatDamage, warning = createCombatObject(), createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(warning, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(warning, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea, warningArea = createCombatArea(AREA_CROSS5X5), createCombatArea(AREA_CIRCLE3X3)
setCombatArea(combatDamage, combatDamageArea)
setCombatArea(warning, warningArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    if warn then
        return doCombat(cid, warning, var)
    end
    function combat()
        doRemoveCreature(cid)
        return doCombat(cid, combatDamage, var)
    end

    addEvent(combat, 1000)
end
still dont desappear after attack, none error on console.
 
As we talked on Discord, and you said there's no need to use addEvent, so:
LUA:
local combatDamage = createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea = createCombatArea(AREA_CROSS5X5)
setCombatArea(combatDamage, combatDamageArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    doCreatureAddHealth(cid, -getCreatureHealth(cid))

    return doCombat(cid, combatDamage, var)
end
And as per your confirmation, the script is now 100% working.
If you can mark this answer as a solution, I would appreciate it.
 
As we talked on Discord, and you said there's no need to use addEvent, so:
LUA:
local combatDamage = createCombatObject()
setCombatParam(combatDamage, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combatDamage, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)

local combatDamageArea = createCombatArea(AREA_CROSS5X5)
setCombatArea(combatDamage, combatDamageArea)

function onGetFormulaValues(cid, level, maglevel)
    local base = 250
    local variation = 50

    local min = math.max((base - variation), ((3 * maglevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * maglevel + 2 * level) * (base + variation) / 100))

    return -min, -max
end

setCombatCallback(combatDamage, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    doCreatureAddHealth(cid, -getCreatureHealth(cid))

    return doCombat(cid, combatDamage, var)
end
And as per your confirmation, the script is now 100% working.
If you can mark this answer as a solution, I would appreciate it.
Worked, thank you!
 
Back
Top