• 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] What Function Is Equivalente to onAttack or onCombat from TFS 0.X?

Yan18

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

I would like to know what function I can use to get Attacker and Target in combat to set target. I tried use the function Creature: onTargetCombat(target) from file creature.lua but it didn't work.

I need to set target from monsters to my summons instead me when I have a summon. I searched but I didn't find out.
 
Last edited:
Solution
show us what code have you tried, there are very useful functions for what you want to do:

Lua:
Creature.getTarget
Creature.setTarget

Monster.addTarget
Monster.removeTarget
Monster.getTargetList
Monster.getTargetCount
Monster.selectTarget
Monster.searchTarget
Yes, I will use the function Creature:setTarget(creature), but I need a attack event to use this function, because I need to get the attacker and target userdata to verify if is monster (enemy) and I will the target for can set the target to my summon.

About the way that I tried, it was like this:

Lua:
local master = self:getMaster()
local trainer = target:getMaster()

    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end...
show us what code have you tried, there are very useful functions for what you want to do:

Lua:
Creature.getTarget
Creature.setTarget

Monster.addTarget
Monster.removeTarget
Monster.getTargetList
Monster.getTargetCount
Monster.selectTarget
Monster.searchTarget
 
show us what code have you tried, there are very useful functions for what you want to do:

Lua:
Creature.getTarget
Creature.setTarget

Monster.addTarget
Monster.removeTarget
Monster.getTargetList
Monster.getTargetCount
Monster.selectTarget
Monster.searchTarget
Yes, I will use the function Creature:setTarget(creature), but I need a attack event to use this function, because I need to get the attacker and target userdata to verify if is monster (enemy) and I will the target for can set the target to my summon.

About the way that I tried, it was like this:

Lua:
local master = self:getMaster()
local trainer = target:getMaster()

    if master and master == target then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

    if master and trainer and master == trainer then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end

I tried like above because I followed this topic: Solved - Avoid damage from own summons (https://otland.net/threads/avoid-damage-from-own-summons.253873/) but that not working with me :(.

Up!

I don't like spams, but I need help.

I figured out the problem, it was because in Data/Events/events.xml the event onTargetCombat was with enabled 0:

XML:
<event class="Creature" method="onTargetCombat" enabled="0" />

Then I set enabled from 0 to 1:

XML:
<event class="Creature" method="onTargetCombat" enabled="1" />

And it solved my problem!
 
Solution
Back
Top