• 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 Force Monsters Only Focus Summons Always the Player Have Summons?

Yan18

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

As the title said, I would like to know how to force monsters focus on the summons players always the players have summons? I tried:


in Data/Events/Scripts/creature.lua:

Lua:
function Creature:onTargetCombat(target)
   
    if not self then
        return RETURNVALUE_NOERROR
    end
   
    if target:isPlayer() and self:isMonster() then
        if #target:getSummons() >= 1 then
            self:setTarget(target:getSummons()[1])
        return true
       
        else
            return false
        end
    end
       
    return RETURNVALUE_NOERROR
end

The code above even works, but constantly the monster change the target between the player and summon.

I tried too in monster.xml (monster file, not the file that contains the monsters file registered) set target chance to 0:
XML:
<targetchange interval="1000" chance="0" />

But the monsters always focus the player firstly and after that never change the target more while him lose the focus. I belive the monster focus the player first even I have summon before the monster can target, is because the source.

And lastly I tried to set in monster.xml set chance to 100 and interval to 1 in target tag bevause the first case, the monster focus firstly the player, and happen the same problem of the first case, the monster change the target constantly:

XML:
<targetchange interval="1" chance="100" />

To solve the problem, is in sourvce (C++) or in Lua?
 
I tested your code and noticed it refused to follow the summon.
The following worked for me.

Lua:
function Creature:onTargetCombat(target)
    if target:isPlayer()
    and self:isMonster()
    and #target:getSummons() >= 1 then
        self:removeTarget(target)
        self:selectTarget(target:getSummons()[1])
    end
    if hasEventCallback(EVENT_CALLBACK_ONTARGETCOMBAT) then
        return EventCallback(EVENT_CALLBACK_ONTARGETCOMBAT, self, target)
    else
        return RETURNVALUE_NOERROR
    end
end

If you wish that monsters avoid targeting players then you will have to modify searchTarget
 
Last edited:
I tested your code and noticed it refused to follow the summon.
The following worked for me.

Lua:
function Creature:onTargetCombat(target)
    if target:isPlayer()
    and self:isMonster()
    and #target:getSummons() >= 1 then
        self:removeTarget(target)
        self:selectTarget(target:getSummons()[1])
    end
    if hasEventCallback(EVENT_CALLBACK_ONTARGETCOMBAT) then
        return EventCallback(EVENT_CALLBACK_ONTARGETCOMBAT, self, target)
    else
        return RETURNVALUE_NOERROR
    end
end

If you wish that monsters avoid targeting players then you will have to modify searchTarget
Thanks to try help bro! I tried your code, but I can't target none monsters. The monster focus me but after him focus the summon and keeping focusing the summon correctly. But I can't target none monster.

Your script generates an error:

C:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:29: attempt to call global 'hasEventCallback' (a nil value)
stack traceback:
        [C]: in function 'hasEventCallback'
        data/events/scripts/creature.lua:29: in function <data/events/scripts/creature.lua:9>
 
Thanks to try help bro! I tried your code, but I can't target none monsters. The monster focus me but after him focus the summon and keeping focusing the summon correctly. But I can't target none monster.

Your script generates an error:

C:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:29: attempt to call global 'hasEventCallback' (a nil value)
stack traceback:
        [C]: in function 'hasEventCallback'
        data/events/scripts/creature.lua:29: in function <data/events/scripts/creature.lua:9>

🤔
replace
Lua:
    if hasEventCallback(EVENT_CALLBACK_ONTARGETCOMBAT) then
        return EventCallback(EVENT_CALLBACK_ONTARGETCOMBAT, self, target)
    else
        return RETURNVALUE_NOERROR
    end
with
Lua:
return RETURNVALUE_NOERROR
 
🤔
replace
Lua:
    if hasEventCallback(EVENT_CALLBACK_ONTARGETCOMBAT) then
        return EventCallback(EVENT_CALLBACK_ONTARGETCOMBAT, self, target)
    else
        return RETURNVALUE_NOERROR
    end
with
Lua:
return RETURNVALUE_NOERROR
The error got was because my server doesn't have the function hasEventCallback, then your script won't works.
 
Back
Top