• 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+ [TFS 1.3] How To Do Player Can't Attack Summons?

Yan18

Member
Joined
Jun 14, 2014
Messages
104
Solutions
3
Reaction score
17
Hello folks!

I want to do the player can't attack and target their summons.

I tried to do in Data/Events/creature.lua:

Lua:
function Creature:onTargetCombat(target)
local master = self:getMaster()

    if not self then
        return RETURNVALUE_NOERROR
    end

    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isPlayer() then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isSummonable() then
        return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
    end

    return RETURNVALUE_NOERROR
end

It didn't generates an error, but didn't work.


---------------------------------------------------------------------------------------------

EDIT

I solved my problem, I did a check in the source and it worked!

This was my solution:

Open the source and go in combat.cpp and look for the function: ReturnValue Combat::canTargetCreature(Player* attacker, Creature* target) and add the code below inside:

C++:
ReturnValue Combat::canTargetCreature(Player* attacker, Creature* target)
{
    if (attacker->getPlayer() && target->getCreature()->isSummon())
    {
        return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
    }

    ... // ANOTHER BLOCKS BELOW FROM THE FUNCTION
    
}
 
Last edited:
@Elsilva157
U should do this in spells (In c++)

C++:
// Verification if it is a summon
if (target->getCreature()->isSummon()) {
    // Ignore the damage in summons
    continue;
}

// Apply normal damage for other Targets
...

If you want change the spell lua

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.4) + 8
    local max = (level / 5) + (magicLevel * 2.2) + 14
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    local target = creature:getTarget()
    if target == nil or not target:isCreature() then
        return false
    end

    if target:isSummon() then
        creature:sendCancelMessage("You cannot target summons with this spell.")
        return false
    end

    return combat:execute(creature, variant)
end
 
Back
Top