• 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!

Solved [TFS 1.2] Movement (If player then..)

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
If a player is on playerPositions, then next player that tries to enter gets message & teleportTo(fromPosition).
As of right now, nobody can enter the room, even if playerPos is nil.

Code:
local playerPositions = Position(603, 975, 15)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end

            if playerPositions == nil then
            return false
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "This table is full.")
            player:teleportTo(fromPosition, false)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            return true
            end
        end

solution:
Code:
local playerPositions = Position(1002, 935, 10)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
        local specs, spec = Game.getSpectators(playerPositions, false, false, 1, 1, 1, 1)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:teleportTo(fromPosition, false)
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You Shall Not Pass.")
                return true
            end
        end
    end
 
Last edited:
iterateArea or something like a constant to check (i = 0)
you can always check orts datapack for scripts like those (I mean similar to tibia shits)
 
As long as you have an action/unique ID set up for the tile on map editor and the movements.xml links to this specific script, there is no need for most of the stuff you've done. Not only that, but the formatting and organization overall is bad.

That being said, whenever you return false from an onStepIn() movement the creature won't move. This means you want to return true when the movement should be successful. This may be why you are having malfunctioning but no errors.
 
if playerPositions == nil then return true
this is the "true Statement. if there is no player on playerPositions then it cancels out & the player passes the tile with the action id. False, the player does not enter.. which then does player:teleportTo(fromPosition). I get all this.
 
cus you are not checking if there is a player or not, as I said, take a look at orts codes
You are actually correct, wht this part:
Code:
if playerPositions == nil then
    return false
else
does is it returns false if the playerPosition is nil, which will never happen because it is defined in the first line of the script.

There is no checking of whether there is a player/creature there or not whatsoever.
 
take a look at orts codes

I honestly don't know what else to do.

Code:
local playerPositions = Position(603, 975, 15)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
        for i = 0, #playerPositions do
            if getTopCreature(playerPositions[i]) == nil then
        return true
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "This table is full.")
            player:teleportTo(fromPosition, false)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return false
            end
         end
     end
 
Last edited:
You still are not actually checking if there is a player there.
Let me be very thorough with this. First, take a look at this improved version of your code:
Code:
function onStepIn(creature, topos, frompos)
   --Check if the creature that stepped in this tile is a player
   --By the way, checking "if not creature then" is being paranoid
   if (not creature or not creature:isPlayer()) then
     return false
   end

   --This could be player = creature:getPlayer() depending on your Lua script version and settings
   player = Player(creature)

   --This can be changed to a lot of stuff depending on your Lua script version and settings
   topCreature = getTopCreature(topos)

   --This time it's not being paranoid, it's about making it safe
   if (not topCreature or topCreature == nil) then
     return true
   end

   if (topCreature:isPlayer() == false) then
     --return true allows the movement to occur
     return true
   else
     --Potentially could be changed to sendCancelMessage() but whatever
     player:sendTextMessage(MESSAGE_INFO_DESCR, "This table is full.")
  
     --return false prevents the movement from happening, thus there is no need to actually teleport the player (unless you are paranoid)
     player:teleportTo(fromPosition, false)
  
     --This effect could lok a little bit strange specifically because the player is not being moved at all, since you returned true. Up to you though
     player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
     return false
   end
    --Failsafe return true
    return true
end

I left a lot of comments for you to get the idea, because this might not work depending on your TFS version (or whatever distro you are using).

Notice that on line 19 I performed a check to see if the creature that happens to be in that tile is a player or not. You never made such a check.
 
Last edited:
Notice that on line 19 I performed a check to see if the creature that happens to be in that tile is a player or not. You never made such a check.
this is lovely of you, but your script still doesn't function. isPlayer is coming back as nil
 
this is lovely of you, but your script still doesn't function. isPlayer is coming back as nil
What about you trying this instead:
Code:
if (Player(topCreature) == nil or Payer(topCreature) == false or topCreature:getPlayer() == false or topCreature:getPlayer() == nil) then
this should take care of all situations I think are likely to occur
 
I am using topos, which is the position the player is walking to. If you strictly need this then go ahead and use it, but I would imagine you'd want this to happen only in a specific tile with a specific action or unique id, since running this Lua script for every single creature movement in the entire game is very slow and worrying.
If this is what you need, I'd advise doing it in the sources using C++ for performance reasons.
 
Well, I suppose we are on different pages as far as the script is to go. you have 2 player(two) one is on point "A" (playerPositions) the other player is trying to pass point "B", which is set on an action id. If Player on Point "A" is on (playerPositions), then player cannot pass point "B". there is more than 1 (one) tile being used. If no player on point "A", then script will allow entrance past point"B".
 
What I got from this is:
________
__XY___
________

X is the position the player is in. He pressed -> arrow, and is trying to move to Y position.
From what I understood, you want the player to not be able to go to Y if there is a player in Y already.
Is that correct?
If it is correct, X is called frompos and Y is called topos, not requiring a position variable to be set - that is, if you are linking the script with an action or unique id.

If this isn't correct, could you explain a little bit more?
 
this can't be that difficult.. :/
It probably isn't, but you'll have to explain better than this. Anyways, I have just modified your original script on the first post to see if that suffices your need:

Code:
local playerPositions = Position(603, 975, 15)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
    topCreature = playerPositions:getTopCreature
    if (Player(topCreature) == nil or Payer(topCreature) == false or topCreature:getPlayer() == false or topCreature:getPlayer() == nil) then
        return true
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "This table is full.")
        player:teleportTo(fromPosition, false)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return false
    end
end
 
Last edited:
This fixed the issue.

Code:
local playerPositions = Position(1002, 935, 10)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
        local specs, spec = Game.getSpectators(playerPositions, false, false, 1, 1, 1, 1)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:teleportTo(fromPosition, false)
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You Shall Not Pass.")
                return true
            end
        end
    end
 
Back
Top