• 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 TFS 1.2 - How to access the target of a spell

Joined
Dec 13, 2015
Messages
45
Reaction score
13
I'm trying for hours to find a way to access the target of my spell.

I've searched trough all TFS 1.2 functions and couldn't find anything besides creature:getTarget().

The problem with creature:getTarget() is that the player's target is not always the same as the spell's target, so it won't work for me.
 
Solution
what do you want the spell to do?
heal an area and remove a specific condition subId?

until a solution is found, you could change the spell and make it manually check the area around you (instead of using a combat object with area and condition dispel) and removing paralyze with subId 1, its not the best for efficiency, but if its not being spammed its not that bad

@MatheusMkalo @Omni Cloud sorry for tagging you two, but does any of you know a solution to targets of aoe spells?
if you dont ill ask on the github repo
You can do it using :

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
As Dnomyar said or you could do something with:

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")...
Give a little more detail as to what you are trying to do and I'll do my best to help =]

I want my healing spells to only remove the paralyze condition with a specific subID.
I did all I could to use combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE), inside the combat object. But using this It will remove all paralyze conditions with any subID.

To only remove condition in case subID = 1 I had to use doRemoveCondition inside my onCastSpell() function.
Code:
function onCastSpell(creature, var)
    doRemoveCondition(creature, CONDITION_PARALYZE)
    doRemoveCondition(creature, CONDITION_PARALYZE, 1)
    return combat:execute(creature, var)
end
No problem when self-healing. But this won't work when using heal friend or a healing rune on another player. If I don't find a way to:
Code:
doRemoveCondition(spell target here, CONDITION_PARALYZE)
doRemoveCondition(spell target here, CONDITION_PARALYZE, 1)
I'll only be capable of implementing what I want on self-healing spells.
 
yeah, just tried
print(Creature(variant.number):getName())
and it returns the name of my target
however, print_r(Variant(variant)) still works, since Variant(variant) seems to convert it, but its still classified as a regular table?

after testing, for aoe spells the variant seems to contain the players CID, and not the monsters that actually get hit :/

edit:
with
print_r(Variant(variant))
print_r(variant)
i get
3a5e876a85209658aec24adc327f09ca.png

which seems very weird o.o
 
that number is most likely the CID of the target then
x:blah() only works on metatables, and variant is just a regular table afaik
You are right.

no your assumption was right, var returns a normal table, but Variant converts it into the userdata and returns the data easier.
Code:
Creature(var.number)
would be the equal to it.

Variant(var):getNumber() didn't work but Creature(var.number) did. Nice.

Thanks so much guys! This was very intersting, I learned a lot! Love you.
 
You are right.



Variant(var):getNumber() didn't work but Creature(var.number) did. Nice.

Thanks so much guys! This was very intersting, I learned a lot! Love you.
yeah, that works for singletarget spells, but player:getTarget() also works in those cases, variant doesnt seem to contain all the targets that get hit for aoe though?
i guess you could getSpectators(...) if you cant solve it in any other way, but its not really a good way
 
yeah, just tried
print(Creature(variant.number):getName())
and it returns the name of my target
however, print_r(Variant(variant)) still works, since Variant(variant) seems to convert it, but its still classified as a regular table?

after testing, for aoe spells the variant seems to contain the players CID, and not the monsters that actually get hit :/

edit:
with
print_r(Variant(variant))
print_r(variant)
i get
3a5e876a85209658aec24adc327f09ca.png

which seems very weird o.o
if it's an aoe spell it should atleast create an array of positions where there was damage done
 
weird, not really the behaviour I would expect, might even be a bug. should certainly be reported I'd say.
i tried everything related to variant i could find in luascript.cpp etc, but i couldnt get it to return any positions hit or targets in any way :(
ill post it on github i guess later
 
yeah, that works for singletarget spells, but player:getTarget() also works in those cases, variant doesnt seem to contain all the targets that get hit for aoe though?
i guess you could getSpectators(...) if you cant solve it in any other way, but its not really a good way

I guess I won't be able to use this method for Mass Heal them. I can live with that though.
 
what do you want the spell to do?
heal an area and remove a specific condition subId?

until a solution is found, you could change the spell and make it manually check the area around you (instead of using a combat object with area and condition dispel) and removing paralyze with subId 1, its not the best for efficiency, but if its not being spammed its not that bad

@MatheusMkalo @Omni Cloud sorry for tagging you two, but does any of you know a solution to targets of aoe spells?
if you dont ill ask on the github repo
 
Last edited:
Back
Top