• 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.2 doubt spectators

lazarus321

Member
Joined
May 8, 2017
Messages
209
Reaction score
20
Can anyone explain to me why this spell works only if the player uses it and does not work if the summon uses it?
Basically it does a check and who is your master and asks him to say his name.

C#:
function onCastSpell(creature, var)
    local targets = {}
    local player = Player(creature)
    local playerPos = creature:getPosition()
   
local spectators = Game.getSpectators(playerPos, false, false, 4, 4, 4, 4)
for i = 1, #spectators do
    local spectator = spectators[i]
    spectator:say(spectator:getMaster():getName(), TALKTYPE_SAY)
end

end
 
Last edited:
Solution
Can anyone explain to me why this spell works only if the player uses it and does not work if the summon uses it?
Basically it does a check and who is your master and asks him to say his name.

C#:
function onCastSpell(creature, var)
    local targets = {}
    local player = Player(creature)
    local playerPos = creature:getPosition()
  
local spectators = Game.getSpectators(playerPos, false, false, 4, 4, 4, 4)
for i = 1, #spectators do
    local spectator = spectators[i]
    spectator:say(spectator:getMaster():getName(), TALKTYPE_SAY)
end

end
Variables target and player are useless. Also this will cause errors if the spectator does not have a master. You must check if there's a master first then have the spec say it's name...
Can anyone explain to me why this spell works only if the player uses it and does not work if the summon uses it?
Basically it does a check and who is your master and asks him to say his name.

C#:
function onCastSpell(creature, var)
    local targets = {}
    local player = Player(creature)
    local playerPos = creature:getPosition()
  
local spectators = Game.getSpectators(playerPos, false, false, 4, 4, 4, 4)
for i = 1, #spectators do
    local spectator = spectators[i]
    spectator:say(spectator:getMaster():getName(), TALKTYPE_SAY)
end

end
Variables target and player are useless. Also this will cause errors if the spectator does not have a master. You must check if there's a master first then have the spec say it's name.

Lua:
function onCastSpell(creature, variant)
    for key, spec in pairs(Game.getSpectators(creature:getPosition(), false, false, 4, 4, 4, 4)) do
        local master = spec:getMaster()
        if master then
            spec:say(master:getName(), TALKTYPE_SAY)
        end
    end
    return true
end
 
Solution
Back
Top