• 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 TFS create_function acting weird

S

Shadow_

Guest
so i wrote the code and added a condition if targets > 0 then but the problem is there is no targets around and it still loads whatever inside the if, not that only it also loads the if even the condition is found or not and also passes through its else, i tried to add if targets then and it also passed so, there is something wrong with create_functions.lua or get spectators but im sure get spetators is fine.
Lua:
function Player.start1v1(self, x, y, duration)
  local targets = Game.getSpectators(self:getPosition(), false, true, x, x, y, y)
    if #targets > 0 then
      for i = 1, #targets do
          if targets[i] then
        if targets[i]:getStorageValue(storageT) <= os.time() then
          targets[i]:setStorageValue(storageT, os.time() + duration)
          self:setStorageValue(storageT, os.time() + duration)
          table.insert(targetsLIB, targets[i])
          table.insert(targetsLIB, self)
          print("both should be affected by 1v1")
      end
        end
      end
    end
end
@Nekiro @Evil Puncker what do you think guys, i couldn't think of anybody to mention but i think tfs developers might have an idea
1619542437533.png


never mind the mysql error
 
Last edited by a moderator:
what are you trying to do exactly? why not use the onTargetCombat event instead of getSpectators?
im trying to do like a 1v1 system, when a player cast specific spell, only those 2 can attack each others, and even if other player casted the same condition on another player they can't be 2v2 or 3v1 just 1v1 here and 1v1 here, its hard to explain, i used getSpectators because the user wants to define the area of the affection so like 2x2 that square any player inside it can't attack each other but can only attack the caster, and be attacked by the caster but all who are affected by the player can't attack each other
didnt you check that spectators also contains the player itself
where is your problem? i want to get spectators with respect to the caster position

EDIT : sorry, i just understanded that the player is counted as spectator, but what about the if and its else loads properly i will send example right now
 
if #targets > 0 then
this condition is always true, cause you catch yourself in getSpectators.
but I'm just assuming, cause you didnt show the code
 
im trying to do like a 1v1 system, when a player cast specific spell, only those 2 can attack each others, and even if other player casted the same condition on another player they can't be 2v2 or 3v1 just 1v1 here and 1v1 here, its hard to explain, i used getSpectators because the user wants to define the area of the affection so like 2x2 that square any player inside it can't attack each other but can only attack the caster, and be attacked by the caster but all who are affected by the player can't attack each other

where is your problem? i want to get spectators with respect to the caster position

EDIT : sorry, i just understanded that the player is counted as spectator, but what about the if and its else loads properly i will send example right now
if #targets > 0 then
this condition is always true, cause you catch yourself in getSpectators.
but I'm just assuming, cause you didnt show the code
Post automatically merged:

@StreamSide @Nekiro @Evil Puncker Much respect for you guys for the instant reply, issue solved, i never knew getSpectators counts the tile it starts from, thanks !
 
Just to explain how getSpectators actually works, it gets creatures from the tile (and all tiles around) you pass to the method, its the center position and if you pass the minX, maxX, minY, maxY these are the max ranges in each direction, which creates radius.
 
Back
Top