• 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 Check if monster is summon TFS 1.2

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
295
Location
Poland
Hello as the title says, but that's not all and it would be too long for a thread title. Basically I want my script to check whether:

a) attacked monster is a summon
b) if it's a summon, does it belong to me or any member of my party or guild
c) if yes then return YOUMAYNOTATTACKTHISPLAYER

That's the code I've got for now. It checks if my target is in my party or guild, but I have no idea how to write it to check if the summon belong to me or any member of my party/guild.

Code:
    if self:isPlayer() and target:isPlayer() then
        local party, guild = self:getParty(), self:getGuild()
        if party or guild then
            local targetParty, targetGuild = target:getParty(), target:getGuild()
            if targetParty and targetParty == party or targetGuild and targetGuild == guild then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
Thanks for any help. :)
 
Last edited:
Code:
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 ~= nil and targetParty ~= nil) and party == targetParty then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end

        local guild, targetGuild = self:getGuild(), master:getGuild()
        if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end
    end
end
 

I did this in events/scripts/creature.lua:

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 ~= nil and targetParty ~= nil) and party == targetParty then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end

        local guild, targetGuild = self:getGuild(), master:getGuild()
        if (guild ~= nil and targetGuild ~= nil) and guild == targetGuild then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end
    end
end
    return true
end

but i can attack my and party summons...
 
You can always use isSummon() if you can't solve it yourself ;). It's a function already implemented in the latest version of tfs 1.2
 
You can always use isSummon() if you can't solve it yourself ;). It's a function already implemented in the latest version of tfs 1.2
I have a problem with either isSummon() or getMaster() methods.
When, for example, I kill a Necromancer with its summons with a gfb (all die at the same time) the summons count as killed monsters, even if I give the following instruction to the onKill script:

Lua:
if target:isPlayer() or target:getMaster() or target:isSummon() then
return
end
The other part of the code counts killed monsters, and is counting summons also when it sould not be counting.
I hope I explained myself, if you need more info please let me know.
Cheers
Zyzz
 
I have a problem with either isSummon() or getMaster() methods.
When, for example, I kill a Necromancer with its summons with a gfb (all die at the same time) the summons count as killed monsters, even if I give the following instruction to the onKill script:

Lua:
if target:isPlayer() or target:getMaster() or target:isSummon() then
return
end
The other part of the code counts killed monsters, and is counting summons also when it sould not be counting.
I hope I explained myself, if you need more info please let me know.
Cheers
Zyzz
Lua:
if target:isPlayer() or (target:getMaster() ~= nil) or (target:isSummon() == true) then
    return
end

In that code, I noticed that checking if the target is a player, if it has a defined master or if it is an invocation. If any of these conditions are true, the code will return and it will not count the target as a dead monster.
 
Back
Top