• 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 Party damaging pets in party! Script help!

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
745
Solutions
9
Reaction score
125
Hello guys! I have this script for TFS 1.2:
Code:
function Creature:onTargetCombat(target)
    if not self then
        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

That works perfect to prevent damage from players in the same party. The thing is, is it possible to add pets (Summons) to this script? I dont want myself or my partners damaging their pets while in party.

Thanks in advance for your time!
 
Last edited:
My bad, though i said it on first post. Its TFS 1.2 and yeah, they are just summons. Edited first post with info.
 
Code:
    if self:isPlayer() and target:isPlayer() then                    ---- THIS WHOLE SCRIPT MEANS THAT YOU CANNOT ATTACK PLAYER SUMMONS WITHOUT YOU OR SUMMON OWNER BEING SKULLED
        local party, guild = self:getParty(), self:getGuild()            ---- NOR YOU CAN'T ATTACK PARTY AND GUILD ALLIES, SAME GOES TO YOURS OR THEIRS SUMMONS.
        if party or guild then                                            ---- SUMMONS WILL NOW DAMAGE YOU(WITH AREA SPELLS) ONLY WHEN YOU ARE SKULLED.
            local targetParty, targetGuild = target:getParty(), target:getGuild()
            if targetParty and targetParty == party or targetGuild and targetGuild == guild then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    elseif self:isPlayer() and target:isMonster() then
        local master = target:getMaster()
        if master and master:isPlayer() then
            local party, targetParty = self:getParty(), master:getParty()
            if (party ~= nil and targetParty ~= nil) and party == targetParty or self ~= master and not isInArray(skullTypes, master:getSkull()) and not isInArray(skullTypes, self:getSkull()) or self == master then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            local guild, targetGuild = self:getGuild(), master:getGuild()
            if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild or self ~= master and not isInArray(skullTypes, master:getSkull()) and not isInArray(skullTypes, self:getSkull()) or self == master then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    elseif self:isMonster() and target:isPlayer() then
        local master = self:getMaster()
        if master and master:isPlayer() then
            local party, targetParty = target:getParty(), master:getParty()
            if (party ~= nil and targetParty ~= nil) and party == targetParty then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            local guild, targetGuild = target:getGuild(), master:getGuild()
            if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            if not isInArray(skullTypes, target:getSkull()) and not isInArray(skullTypes, master:getSkull()) then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    elseif self:isMonster() and self:getMaster() and target:isMonster() and target:getMaster() then
        local master = target:getMaster()
        local master2 = self:getMaster()
        if master and master:isPlayer() and master2 and master2:isPlayer() then
            local party, targetParty = master2:getParty(), master:getParty()
            if (party ~= nil and targetParty ~= nil) and party == targetParty then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            local guild, targetGuild = master2:getGuild(), master:getGuild()
            if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            if not isInArray(skullTypes, master2:getSkull()) and not isInArray(skullTypes, master:getSkull()) then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    end

This whole code looks messy(yeah xD), but it works. So you cannot attack your party/guild allies' summons and vice versa, same goes to attack own summon, you can't attack them and your friends also can't, the only way to kill your summon is to have skull - white, red, black.

Paste it to '..data/events/scripts/creatures' under "function Creature:eek:nTargetCombat(target)".
Go to events and make this "<event class="Creature" method="onTargetCombat" enabled="1" />" enabled(set to 1). Tell me if it works. :)
 
Code:
function Creature:onTargetCombat(target)
    if not self then
        return true
    end

    if self:isPlayer() and target:isMonster() then
        local master = target:getMaster()
        if master and master:isPlayer() then
            local party, targetParty = self:getParty(), master:getParty()
            if ((party and targetParty) and party == targetParty) then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    end

    return true
end
 
Last edited:
Thanks for the answers!

Code:
    if self:isPlayer() and target:isPlayer() then                    ---- THIS WHOLE SCRIPT MEANS THAT YOU CANNOT ATTACK PLAYER SUMMONS WITHOUT YOU OR SUMMON OWNER BEING SKULLED
        local party, guild = self:getParty(), self:getGuild()            ---- NOR YOU CAN'T ATTACK PARTY AND GUILD ALLIES, SAME GOES TO YOURS OR THEIRS SUMMONS.
        if party or guild then                                            ---- SUMMONS WILL NOW DAMAGE YOU(WITH AREA SPELLS) ONLY WHEN YOU ARE SKULLED.
            local targetParty, targetGuild = target:getParty(), target:getGuild()
            if targetParty and targetParty == party or targetGuild and targetGuild == guild then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    elseif self:isPlayer() and target:isMonster() then
        local master = target:getMaster()
        if master and master:isPlayer() then
            local party, targetParty = self:getParty(), master:getParty()
            if (party ~= nil and targetParty ~= nil) and party == targetParty or self ~= master and not isInArray(skullTypes, master:getSkull()) and not isInArray(skullTypes, self:getSkull()) or self == master then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            local guild, targetGuild = self:getGuild(), master:getGuild()
            if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild or self ~= master and not isInArray(skullTypes, master:getSkull()) and not isInArray(skullTypes, self:getSkull()) or self == master then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    elseif self:isMonster() and target:isPlayer() then
        local master = self:getMaster()
        if master and master:isPlayer() then
            local party, targetParty = target:getParty(), master:getParty()
            if (party ~= nil and targetParty ~= nil) and party == targetParty then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            local guild, targetGuild = target:getGuild(), master:getGuild()
            if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            if not isInArray(skullTypes, target:getSkull()) and not isInArray(skullTypes, master:getSkull()) then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    elseif self:isMonster() and self:getMaster() and target:isMonster() and target:getMaster() then
        local master = target:getMaster()
        local master2 = self:getMaster()
        if master and master:isPlayer() and master2 and master2:isPlayer() then
            local party, targetParty = master2:getParty(), master:getParty()
            if (party ~= nil and targetParty ~= nil) and party == targetParty then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            local guild, targetGuild = master2:getGuild(), master:getGuild()
            if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
            if not isInArray(skullTypes, master2:getSkull()) and not isInArray(skullTypes, master:getSkull()) then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    end

This whole code looks messy(yeah xD), but it works. So you cannot attack your party/guild allies' summons and vice versa, same goes to attack own summon, you can't attack them and your friends also can't, the only way to kill your summon is to have skull - white, red, black.

Paste it to '..data/events/scripts/creatures' under "function Creature:eek:nTargetCombat(target)".
Go to events and make this "<event class="Creature" method="onTargetCombat" enabled="1" />" enabled(set to 1). Tell me if it works. :)

It works but now, nobody can damage creatures, i can get skull on the master, but summons get 0 dmg nor i get skulled when i do AoE attacks.

Code:
function Creature:onTargetCombat(target)
    if self:isPlayer() and target:isMonster() then
        local master = target:getMaster()
        if master and master:isPlayer() then
            local party, targetParty = self:getParty(), master:getParty()
            if party and party == targetParty then
                return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
            end
        end
    end

    return true
end

Thanks printer, but it gives me and error:

k3FAgTm.png


Edit:
Updated the main post with the real script im using for no party damage. The older one wasnt being used. My bad.
 
Last edited:
Okey! Now if you are in party, pets dont get damage but players do.. also, if you are not in a party you can damage your pet :/ I think merging my script with yours printer its the answer, dunno how to do that haha!

Meanwhile im trying to work with Moj script >.< But none seems to be the working 100% Keep it up guys, you are the best! :) Thanks for your time
 
Back
Top