• 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+ Dont accept that my Summon receives my damage

darkmubr

Member
Joined
Mar 8, 2019
Messages
47
Solutions
1
Reaction score
13
i want change combat.cpp for dont accept my own damage in my summon.

I noticed that in no-pvp mode my summon does not get damage. But I also can not deal damage to enemy summon.

what I want: do not hit my summon but hit whatever else.

I did some testing and it looks like this can be adjusted around here.

Someone help me?

LUA:
if (g_game.getWorldType() == WORLD_TYPE_NO_PVP ) {
        if (attacker->getPlayer() || (attacker->isSummon() && attacker->getMaster()->getPlayer())) {
            if (target->getPlayer()) {
                if (!isInPvpZone(attacker, target)) {
                    return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
                }
            }

            if (target->isSummon() && target->getMaster()->getPlayer()) {
                if (!isInPvpZone(attacker, target)) {
                    return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
                }
            }
        }
    }
 
Solution
my summon_creature.lua:

LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and primaryType ~= COMBAT_HEALING then
        local master = creature:getMaster()
        if master and master:isPlayer() and master.uid == attacker.uid then
            return 0, 0, 0, 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onCastSpell(creature, variant)
    if creature:getSkull() == SKULL_BLACK then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    local monsterName = variant:getString()
    local monsterType = MonsterType(monsterName)

    if not monsterType...
i want change combat.cpp for dont accept my own damage in my summon.

I noticed that in no-pvp mode my summon does not get damage. But I also can not deal damage to enemy summon.

what I want: do not hit my summon but hit whatever else.

I did some testing and it looks like this can be adjusted around here.

Someone help me?

LUA:
if (g_game.getWorldType() == WORLD_TYPE_NO_PVP ) {
        if (attacker->getPlayer() || (attacker->isSummon() && attacker->getMaster()->getPlayer())) {
            if (target->getPlayer()) {
                if (!isInPvpZone(attacker, target)) {
                    return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
                }
            }

            if (target->isSummon() && target->getMaster()->getPlayer()) {
                if (!isInPvpZone(attacker, target)) {
                    return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
                }
            }
        }
    }
If someone can figure out how to do this in sources for you that will be great but here is an alternative:

Add your summon:registerEvent("EVENTNAME") at the end of this script before the return true:
TFS 1.3 - Summon Creature Spell

Then here is the event:
LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and primaryType ~= COMBAT_HEALING then
        local master = creature:getMaster()
        if master and master:isPlayer() and master.uid == attacker.uid then
            return 0, 0, 0, 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
If someone can figure out how to do this in sources for you that will be great but here is an alternative:

Add your summon:registerEvent("EVENTNAME") at the end of this script before the return true:
TFS 1.3 - Summon Creature Spell

Then here is the event:
LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and primaryType ~= COMBAT_HEALING then
        local master = creature:getMaster()
        if master and master:isPlayer() and master.uid == attacker.uid then
            return 0, 0, 0, 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end


my summon_creature.lua:

LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and primaryType ~= COMBAT_HEALING then
        local master = creature:getMaster()
        if master and master:isPlayer() and master.uid == attacker.uid then
            return 0, 0, 0, 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onCastSpell(creature, variant)
    if creature:getSkull() == SKULL_BLACK then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    local monsterName = variant:getString()
    local monsterType = MonsterType(monsterName)

    if not monsterType then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if not creature:hasFlag(PlayerFlag_CanSummonAll) then
        if not monsterType:isSummonable() then
            creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end

        if #creature:getSummons() >= 2 then
            creature:sendCancelMessage("You cannot summon more creatures.")
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    local manaCost = monsterType:getManaCost()
    if creature:getMana() < manaCost and not creature:hasFlag(PlayerFlag_HasInfiniteMana) then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local position = creature:getPosition()
    local summon = Game.createMonster(monsterName, position, true)
    if not summon then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        position:sendMagicEffect(CONST_ME_POFF)
        return false
    end

    creature:addMana(-manaCost)
    creature:addManaSpent(manaCost)
    creature:addSummon(summon)
    position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    summon:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    summon:registerEvent("onHealthChange")
   
    return true
end

Did I add the code correctly?

Because the way it is, it does not work. I still can attack my summon
 
my summon_creature.lua:

LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and primaryType ~= COMBAT_HEALING then
        local master = creature:getMaster()
        if master and master:isPlayer() and master.uid == attacker.uid then
            return 0, 0, 0, 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onCastSpell(creature, variant)
    if creature:getSkull() == SKULL_BLACK then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    local monsterName = variant:getString()
    local monsterType = MonsterType(monsterName)

    if not monsterType then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if not creature:hasFlag(PlayerFlag_CanSummonAll) then
        if not monsterType:isSummonable() then
            creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end

        if #creature:getSummons() >= 2 then
            creature:sendCancelMessage("You cannot summon more creatures.")
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    local manaCost = monsterType:getManaCost()
    if creature:getMana() < manaCost and not creature:hasFlag(PlayerFlag_HasInfiniteMana) then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local position = creature:getPosition()
    local summon = Game.createMonster(monsterName, position, true)
    if not summon then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        position:sendMagicEffect(CONST_ME_POFF)
        return false
    end

    creature:addMana(-manaCost)
    creature:addManaSpent(manaCost)
    creature:addSummon(summon)
    position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    summon:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    summon:registerEvent("onHealthChange")
  
    return true
end

Did I add the code correctly?

Because the way it is, it does not work. I still can attack my summon
summon:registerEvent("Summon_Damage")

creaturescripts.xml
XML:
<event type="healthchange" name="Summon_Damage" script="summon_damage.lua" />

Then add the onHealthChange into its own script, data/creaturescripts/scripts/summon_damage.lua
 
Solution
summon:registerEvent("Summon_Damage")

creaturescripts.xml
XML:
<event type="healthchange" name="Summon_Damage" script="summon_damage.lua" />

Then add the onHealthChange into its own script, data/creaturescripts/scripts/summon_damage.lua

Wow, it worked.

Sorry for my stupidity, lol.
 
@Apollos it worked. But I found a bug.

Summon does not take any more damage. But I can target him.


This implies that I can train skills infinitely with him (get infinite skills).

I think the best solution would be to return with RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE when target him (summon).

The problem is: I do not know how to do it.

Anybody know?
 
@Apollos it worked. But I found a bug.

Summon does not take any more damage. But I can target him.


This implies that I can train skills infinitely with him (get infinite skills).

I think the best solution would be to return with RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE when target him (summon).

The problem is: I do not know how to do it.

Anybody know?
Try this:
LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and primaryType ~= COMBAT_HEALING and origin == ORIGIN_SPELL then
        local master = creature:getMaster()
        if master and master:isPlayer() and master.uid == attacker.uid then
            return 0, 0, 0, 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

EDIT: Changed 2 to ORIGIN_SPELL.
 
Last edited:
Try this:
LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and primaryType ~= COMBAT_HEALING and origin == 2 then
        local master = creature:getMaster()
        if master and master:isPlayer() and master.uid == attacker.uid then
            return 0, 0, 0, 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Don't work.

With origin == 2 i can attack my summon.
 
Don't work.

With origin == 2 i can attack my summon.
Why would you want to remove the option to attack your summon when targeted? Then you can't train on your own summon. If someone intentionally targets their summon they want to kill it.

This solution will stop spell damage but allow direct damage.
 
Why would you want to remove the option to attack your summon when targeted? Then you can't train on your own summon. If someone intentionally targets their summon they want to kill it.

This solution will stop spell damage but allow direct damage.


I will have a vocation that will make exclusive use of summons, understand?

So it's not very smart that I (summoner) kill my own creature.

Your solution causes me to be unable to deal damage on my own summon. However, I keep gaining skill because it is possible to target me so that I can abuse this weakness.
 
I will have a vocation that will make exclusive use of summons, understand?

So it's not very smart that I (summoner) kill my own creature.

Your solution causes me to be unable to deal damage on my own summon. However, I keep gaining skill because it is possible to target me so that I can abuse this weakness.
I understand but I disagree. If I a summoner player decided to target my summon then I intend to kill it. Although if this is truly what you need then you have the option of this:

Enable onTargetCombat in events.xml

And change the function within creature.lua to this:
LUA:
function Creature:onTargetCombat(target)
    if self:isPlayer() then
        local master = target:getMaster()
        if master and master.uid == self.uid then
            return RETURNVALUE_NOTPOSSIBLE
        end
    end
    return RETURNVALUE_NOERROR
end

You can probably remove the onHealthChange fix we did before, I'm pretty sure this will negate any spell damage as well. Just know that players will be unable to train on their summons anymore.
 
I understand but I disagree. If I a summoner player decided to target my summon then I intend to kill it. Although if this is truly what you need then you have the option of this:

Enable onTargetCombat in events.xml

And change the function within creature.lua to this:
LUA:
function Creature:onTargetCombat(target)
    if self:isPlayer() then
        local master = target:getMaster()
        if master and master.uid == self.uid then
            return RETURNVALUE_NOTPOSSIBLE
        end
    end
    return RETURNVALUE_NOERROR
end

You can probably remove the onHealthChange fix we did before, I'm pretty sure this will negate any spell damage as well. Just know that players will be unable to train on their summons anymore.

If I a summoner player decided to target my summon then I intend to kill it

YES. This must continue to exist.

What I said is that it does not make sense to summon and I can kill him myself.

Third parties must and can kill. Did you understand what I said?

So that your last solution does not meet that.
 
If I a summoner player decided to target my summon then I intend to kill it

YES. This must continue to exist.

What I said is that it does not make sense to summon and I can kill him myself.

Third parties must and can kill. Did you understand what I said?

So that your last solution does not meet that.
I meant to write "If I a summoner player decided to target my own summon". This solution I just posted will stop you from attacking your own summon. Other players will still be able to.

Edit: Also you may replace RETURNVALUE_NOTPOSSIBLE with RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE.
 
Last edited:
Back
Top