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

Solved Avoid damage from own summons

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
249
Solutions
3
Reaction score
30
Location
Hell
Hello OtLand!
I need help with this: Is there a way to avoid summons hurting the owner of the summon? I have a vocation based on summons and they can get killed by their own summons.
Thanks for the help!
 
Solution
no fuckin clue why that function would be executing for stuff like potions but
Lua:
function Creature:onTargetCombat(target)
    if not self then
        return RETURNVALUE_NOERROR
    end
    local master = self:getMaster()
    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return RETURNVALUE_NOERROR
end
XML:
<event type="healthchange" name="summons healthchange" script="summon damage.lua"/>
<event type="manachange" name="summons manachange" script="summon damage.lua"/>

summon damage.lua
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local summons = creature:getSummons()
    if summons and #summons > 0 table.contains(summons, attacker) then
        return 0, primaryType, 0, secondaryType
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onManaChange(creature, attacker, manaChange, origin)
    local summons = creature:getSummons()
    if summons and #summons > 0 table.contains(summons, attacker) then
        return 0
    end
    return manaChange
end

login.lua
Lua:
player:registerEvent("summons healthchange")
player:registerEvent("summons manachange")
 
XML:
<event type="healthchange" name="summons healthchange" script="summon damage.lua"/>
<event type="manachange" name="summons manachange" script="summon damage.lua"/>

summon damage.lua
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local summons = creature:getSummons()
    if summons and #summons > 0 table.contains(summons, attacker) then
        return 0, primaryType, 0, secondaryType
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onManaChange(creature, attacker, manaChange, origin)
    local summons = creature:getSummons()
    if summons and #summons > 0 table.contains(summons, attacker) then
        return 0
    end
    return manaChange
end

login.lua
Lua:
player:registerEvent("summons healthchange")
player:registerEvent("summons manachange")
It's not working, I'm still receiving damage from my own summons.
 
XML:
<event type="healthchange" name="summonsHealthChange" script="summon_healthChange.lua"/>

Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  local master = creature:getMaster()
  if master and master == target then
    return 0, primaryType, 0, secondaryType
  end
  return primaryDamage, primaryType, secondaryDamage, secondaryType
end

You can register this on the monster xml file that have summons:
XML:
<monster>
  ...

  <!-- Only this piece inside <monster> tag -->
  <script>
    <event name="summonsHealthChange" />
  </script>

</monster>

Or you could register easily on all monsters if you have a callback function like "onSpawn".

Note: Monsters and summons have no mana, so you don't need a script for that.
 
So would it be like this?
Lua:
function Creature:onChangeOutfit(outfit)
    return true
end

function Creature:onAreaCombat(tile, isAggressive)
    return true
end

function Creature:onTargetCombat(target)
    if not self then
local master = creature:getMaster()
if master and master == target then
return false
end
        return true
    end

    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return true
end
 
no, like this
Lua:
function Creature:onTargetCombat(target)
    local master = self:getMaster()
    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return RETURNVALUE_NOERROR
end
 
I'm not receiving damage from enemies anymore, but now I'm geting this issue:
Code:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:10: attempt to index local 'self' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/creature.lua:10: in function <data/events/scripts/creature.lua:9>
        [C]: in function 'doTargetCombatMana'
        data/actions/scripts/potsys/potions.lua:52: in function <data/actions/scripts/potsys/potions.lua:24>

Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:10: attempt to index local 'self' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/creature.lua:10: in function <data/events/scripts/creature.lua:9>
        [C]: in function 'doTargetCombatHealth'
        data/actions/scripts/potsys/potions.lua:112: in function <data/actions/scripts/potsys/potions.lua:24>
I can't use potions right now.
 
Last edited:
no fuckin clue why that function would be executing for stuff like potions but
Lua:
function Creature:onTargetCombat(target)
    if not self then
        return RETURNVALUE_NOERROR
    end
    local master = self:getMaster()
    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return RETURNVALUE_NOERROR
end
 
Solution
no fuckin clue why that function would be executing for stuff like potions but
Lua:
function Creature:onTargetCombat(target)
    if not self then
        return RETURNVALUE_NOERROR
    end
    local master = self:getMaster()
    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return RETURNVALUE_NOERROR
end

I'm using exactly this script on 'events/creature.lua' on TFS 1.2 and its working perfectly.
Lua:
function Creature:onTargetCombat(target)
    if not self then
        return RETURNVALUE_NOERROR
    end
    local master = self:getMaster()
    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end
    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return RETURNVALUE_NOERROR
end
I don't receive damage from my own summons and isn't causing any issue. It also has a system that ignores damage from party members in the lines starting from 'if party then'.
Thank you so much @Static_ , @Thexamx and @River KA for all your help! I hope this script could help someone else with the same needs.
 
Last edited:
I'm using exactly this script on 'events/creature.lua' on TFS 1.2 and its working perfectly.
Lua:
function Creature:onTargetCombat(target)
    if not self then
        return RETURNVALUE_NOERROR
    end
    local master = self:getMaster()
    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end
    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return RETURNVALUE_NOERROR
end
I don't receive damage from my own summons and isn't causing any issue. It also has a system that ignores damage from party members in the lines starting from 'if party then'.
Thank you so much @Static_ , @Thexamx and @River KA for all your help! I hope this script could help someone else with the same needs.
THIS IS THE SOLUTION FOR TFS 1.2 I CONFIRM. THANK YOU PAL !!
 
Code:
function Creature:onTargetCombat(target)
    if not self then
        return RETURNVALUE_NOERROR
    end
    local master = self:getMaster()
    local targetmaster =target:getMaster()
    if master and master == target then
    -- attacking master
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end
    if master and targetmaster and targetmaster == master then
        -- attacking master summons
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isPlayer() then
    --target party protection
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    if target:isPlayer() then
         if master then
             if master:getParty() == target:getParty()  and target:getParty() ~= 0 then
               -- attracking  party memeber
                  return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
              end
        end
    else

     if master then
     if (targetmaster) then
     local targmparty = target:getMaster():getParty()
         if (targmparty) then
                 if master:getParty() ==  targmparty  and targmparty ~= 0 then
              --attacking party summoned creature
                  return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                  end
        end
    end
    end
    end
    return RETURNVALUE_NOERROR
end


the code wasn't doing exactly what I wanted.

I made a quick fix to protect party members,their summons and your summons as well.

100% FRIENDLY FIRE SAFE

ROUGHLY TESTED... but seems to be working fine !
 
Code:
function Creature:onTargetCombat(target)
    if not self then
        return RETURNVALUE_NOERROR
    end
    local master = self:getMaster()
    local targetmaster =target:getMaster()
    if master and master == target then
    -- attacking master
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end
    if master and targetmaster and targetmaster == master then
        -- attacking master summons
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if self:isPlayer() and target:isPlayer() then
    --target party protection
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    if target:isPlayer() then
         if master then
             if master:getParty() == target:getParty()  and target:getParty() ~= 0 then
               -- attracking  party memeber
                  return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
              end
        end
    else

     if master then
     if (targetmaster) then
     local targmparty = target:getMaster():getParty()
         if (targmparty) then
                 if master:getParty() ==  targmparty  and targmparty ~= 0 then
              --attacking party summoned creature
                  return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                  end
        end
    end
    end
    end
    return RETURNVALUE_NOERROR
end


the code wasn't doing exactly what I wanted.

I made a quick fix to protect party members,their summons and your summons as well.

100% FRIENDLY FIRE SAFE

ROUGHLY TESTED... but seems to be working fine !
I tried pasting this into data\events\scripts\creature.lua , but it doesn't work. Any ideas?
 
Back
Top