• 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 Function Monster onSelectTarget(self, target)

Maybe if you have the teddy bear from annihilator make an orshabaal not target you the first time then remove the item?

using a script you can set in the monster' behaviour to not target a Elite Knight but a mage
or the weaker player in the screen
I'm curious about the last past: to get an array of the current players on the screen, is there a faster way than LUA iterating all tiles or is there already a way (C++ code?) im not aware of?
 
Can anyone confirm me if this function works for the last TFS commits?
I can't seem to find what I'm supposed to find on tfs 1.2 codes.
 
Can anyone confirm me if this function works for the last TFS commits?
I can't seem to find what I'm supposed to find on tfs 1.2 codes.
this is irrelevant since 1.2 has Creature:eek:nTargetCombat(target) in creature events.
all you need to do is add if self:isMonster() then in your code and it'll work like this one
 
this is irrelevant since 1.2 has Creature:eek:nTargetCombat(target) in creature events.
all you need to do is add if self:isMonster() then in your code and it'll work like this one

I might be blind or whatever, but I can't find what you said here:
https://github.com/otland/forgottenserver/blob/master/src/creatureevent.cpp

Also, what I'm trying to do is a pseudo passive monster through selectTarget.

@Edit
Wait. It's on events.h Lol;
Imma try it out, if it works, Imma post the code here to guide those who wish to use such feature.

Yeah, sadly it doesn't seem to work. At least I couldn't make it to.

Code:
function Creature:onTargetCombat(target)
    if self:isMonster() then
        return false
    end
    return true
end
I made this code just for pure testing and it doesn't even triggers the event at all.
I tried to register it through monster:registerEvent("onTargetCombat") and it did seem to register it, but didn't trigger though.

Code:
    print(self:getName() .. " is selecting a target.")
Doesn't trigger for creatures but it doees trigger for a player.
 
Last edited:
I might be blind or whatever, but I can't find what you said here:
https://github.com/otland/forgottenserver/blob/master/src/creatureevent.cpp

Also, what I'm trying to do is a pseudo passive monster through selectTarget.

@Edit
Wait. It's on events.h Lol;
Imma try it out, if it works, Imma post the code here to guide those who wish to use such feature.

Yeah, sadly it doesn't seem to work. At least I couldn't make it to.

Code:
function Creature:onTargetCombat(target)
    if self:isMonster() then
        return false
    end
    return true
end
I made this code just for pure testing and it doesn't even triggers the event at all.
I tried to register it through monster:registerEvent("onTargetCombat") and it did seem to register it, but didn't trigger though.
it's supposed to be in events/scripts/creature.lua, i guess i worded it badly
also set it to enabled="1" in the events.xml
i'm not sure if return value matters though
 
it's supposed to be in events/scripts/creature.lua, i guess i worded it badly
also set it to enabled="1" in the events.xml
i'm not sure if return value matters though

Yeah I made sure my xml is
Code:
    <event class="Creature" method="onTargetCombat" enabled="1" />

Tried this simple code as said above, but it doesn't print while the monster attacks, tho.
Code:
function Creature:onTargetCombat(target)
    print(self:getName() .. " is selecting a target.")
    if self:isMonster() then
        return false
    end
    return true
end


Nevermind. I saw my error. It does trigger when the monster tries to COMBAT the target. Not exactly select its target. Even though it's not the same as the thread's function, I guess it's enough.
Thanks @Xeraphus !
 
Yeah I made sure my xml is
Code:
    <event class="Creature" method="onTargetCombat" enabled="1" />

Tried this simple code as said above, but it doesn't print while the monster attacks, tho.
Code:
function Creature:onTargetCombat(target)
    print(self:getName() .. " is selecting a target.")
    if self:isMonster() then
        return false
    end
    return true
end
it only works when the creature selects the target, it works for me:
Lua:
function Creature:onTargetCombat(target)
    print(target)
    return true
end
prints userdata: 0x1c5ffb00
 
it only works when the creature selects the target, it works for me:
Lua:
function Creature:onTargetCombat(target)
    print(target)
    return true
end
prints userdata: 0x1c5ffb00

Is your your monster capable doing of doing combat to you?
I've tested it a couple times here and it works when the monster tries to combat the player only.
If you aren't sure about it, try with a ranged monster that has closed combat. It probably will select your target successfully but won't print anything.
 
Is your your monster capable doing of doing combat to you?
I've tested it a couple times here and it works when the monster tries to combat the player only.
If you aren't sure about it, try with a ranged monster that has closed combat. It probably will select your target successfully but won't print anything.
i guess the only case that it doesn't follow is a monster that isn't within range
players attacking monsters from a distance does execute the method but not monsters attacking players from a distance
idunno
 
Return -1 if you dont want them to select you as targrt. But occssionally they still will follow you. And even if you mKe konster unfollow. You, it doesnt work all the time. This bug has been on source from the beginning.
 
Return -1 if you dont want them to select you as targrt. But occssionally they still will follow you. And even if you mKe konster unfollow. You, it doesnt work all the time. This bug has been on source from the beginning.

that was my motivation to create it

Can anyone confirm me if this function works for the last TFS commits?
I can't seem to find what I'm supposed to find on tfs 1.2 codes.

more information
 
The function does not work in player? To return something when a player selects a target in the case
 
Back
Top