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

TFS 1.X+ How do you add custom function to enemies that you hit?

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
Lets say we have this code here

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 52)

local area = createCombatArea({
{1, 0, 0, 1, 0, 0, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 3, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0},
{1, 0, 0, 1, 0, 0, 1}
})
setCombatArea(combat, area)

function onGetFormulaValues(cid, level, maglevel)
    min = -((level / 5) + (maglevel * 10) + 25)
    max = -((level / 5) + (maglevel * 20) + 50)
    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end

For example I would like to get health of each enemy that got hit by this spell How would I do it?


I know I can get the spectators around the player but it's not the same

I was thinking of having condition that will execute custom function but not sure if that's possible
 
Solution
If you are using TFS 1.x. Make use of the OOP coding:
Code:
local area = {
    {1, 0, 0, 1, 0, 0, 1},
    {0, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 3, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 0},
    {1, 0, 0, 1, 0, 0, 1}
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_GIANTICE)
combat:setArea(createCombatArea(area))

function onTargetCreature(creature, target)
    print("Name:", target:getName(), "Health:", target:getHealth())
    return true
end

function onGetFormulaValues(player, level, maglevel)
    min = -((level / 5) + (maglevel * 10) + 25)
    max = -((level / 5) + (maglevel * 20) + 50)
    return min...
If you are using TFS 1.x. Make use of the OOP coding:
Code:
local area = {
    {1, 0, 0, 1, 0, 0, 1},
    {0, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 3, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 0},
    {1, 0, 0, 1, 0, 0, 1}
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_GIANTICE)
combat:setArea(createCombatArea(area))

function onTargetCreature(creature, target)
    print("Name:", target:getName(), "Health:", target:getHealth())
    return true
end

function onGetFormulaValues(player, level, maglevel)
    min = -((level / 5) + (maglevel * 10) + 25)
    max = -((level / 5) + (maglevel * 20) + 50)
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(player, variant)
    return combat:execute(player, variant)
end
 
Solution
If you are using TFS 1.x. Make use of the OOP coding:
Code:
local area = {
    {1, 0, 0, 1, 0, 0, 1},
    {0, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 3, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 0},
    {1, 0, 0, 1, 0, 0, 1}
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_GIANTICE)
combat:setArea(createCombatArea(area))

function onTargetCreature(creature, target)
    print("Name:", target:getName(), "Health:", target:getHealth())
    return true
end

function onGetFormulaValues(player, level, maglevel)
    min = -((level / 5) + (maglevel * 10) + 25)
    max = -((level / 5) + (maglevel * 20) + 50)
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(player, variant)
    return combat:execute(player, variant)
end

I am in the middle of applying the OOP code :D Thanks a lot!!
 
Back
Top