• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua setTarget [TFS 1.2]

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
746
Solutions
9
Reaction score
125
Hello everyone!

I've been doing testing with game.getSpectators and tried something like this:

Code:
local creatures = Game.getSpectators(creature:getPosition(), false, false, 7, 7, 7, 7)
    if #creatures == 0 then
        return true
    end

for i = 1, #creatures do
if creatures[i]:isMonster() then
--print(creatures[1]:getName())
--print(creatures[1]:getId())
creature:setTarget(creatures[2]:getId())
end
end

I've tested with creatures[ i ], creatures[1], creatures[ i ]:getId(), etc etc etc.. but the player NEVER gets target even it doesnt come up with any error.

Its because of the code or because creature:setTarget(target) will not actually target a creature? (by target i mean like right click (attack) on monster and set red square).

Thank you for your time.
 
I tested that. But even with it:
Code:
local creatures = Game.getSpectators(creature:getPosition(), false, false, 7, 7, 7, 7)
    if #creatures == 0 then
        return true
    end
for i = 1, #creatures do
if creatures[i]:isMonster() then
creature:setTarget(creatures[2])
end
If you are a player and execute this it doesnt actually target. (Again, by target i mean set red square on monster like (right click, attack) Its because of the client?

Thank you in advance.
 
I tested that. But even with it:
Code:
local creatures = Game.getSpectators(creature:getPosition(), false, false, 7, 7, 7, 7)
    if #creatures == 0 then
        return true
    end
for i = 1, #creatures do
if creatures[i]:isMonster() then
creature:setTarget(creatures[2])
end
If you are a player and execute this it doesnt actually target. (Again, by target i mean set red square on monster like (right click, attack) Its because of the client?

Thank you in advance.
Try
LUA:
for i = 1, #creatures do
    print( creatures[i]:getId(), creatures[i]:getName(), creatures[i]:isMonster() )
end
 
Code:
1073750521      Gazer   true
1073750482      Bonelord        true

The code is working i guess, but i think setTarget does not actually target as in setredsquare to target. If i get close to the target, i damage him with basic attack, but i dont have a visual target.

Here's a little video preview of the bug. I think its a problem with the client, but maybe im wrong. Some light on the issue would be amazing.

Thank you all!
BhSvlhQ.gif
 
Last edited:
Where is this being loaded? Because there is a method in creature which target's a player or monster.
HTML:
<event class="Creature" method="onTargetCombat" enabled="1" />
LUA:
function Creature:onTargetCombat(target)
    print(target:getName())
    return RETURNVALUE_NOERROR
end
Code:
Monk
Monk
Monk
Monk
Cyclops
Cyclops
Cyclops
Cyclops
I checked in both clients for 10.98, otclient and the regular tibia client and the send square does not work when a creature targets another creature.. i believe it just might be a player driven event. You might have to actually add the method in the sources so you can use it in a script.
Because its declared in protocolgame.h & player.h and defined in protocolgame.cpp & player.cpp but nowhere in luascript.cpp and if it isn't called at all in luascript.cpp then you can't use it in a script.
I have it defined in my alternate source, but you will need to define it in yours and it will have to or should be defined in creature this way it be can applied to all things not just a player.
 
Its called from a Spell, but yeah, so far is what i though. Its a player action from client.

Ill check sources but i think i wont manage. Ill do my best tho.
Thank you for your help!

If anyone has any other info on this issue, let me know!

Thank you all for your time.
 
Back
Top