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

Stop Movement [TFS 1.X]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,284
Location
Sweden?
Hello,

well i have heard alot of complains about how to stop player or creatures from move. Well we know that we can add speed 0 to all, but it's not effective since, if they move, they will move but barley noticeable :p

So i made this simple function to add into your global.lua
Code:
local function allowMovementEvent(cid, allow, oldPosition)
    local creature = Creature(cid)
    if not creature then
        return false
    end

    if allow then
        return stopEvent(event)
    else
        stopEvent(event)
    end

    creature:teleportTo(oldPosition, true)
   
    event = addEvent(allowMovementEvent, 100, cid, allow, oldPosition)
end

function Creature.allowMovement(self, allow)
    allowMovementEvent(self:getId(), allow, self:getPosition())
end

How to use:
Code:
player:allowMovement(false)

Cheers.
 
That is perfect!
I will try that out for my "Stun" spells!

Kind Regards,
Eldin
.
 
This just won't work.

You have a global variable (it's global.lua, right? :p) This means it will only work for one player at a time.
When applying the function to player A, it'll work fine. But when applying the function to player B, it takes over the cid in event.
This ultimately allows player A to move again, but player B is still immovable until it stops or is replaced by the next user of the function.

Teleporting a player back to the original position every 100 milliseconds is a pretty hacky solution and is far from efficient.

Lastly, changing speed to 0 works fine. The speed change isn't applied until the first step is made.
So, you're gonna be moving very very very very slow at speed 1 until you reach next tile, then you won't be able to move anywhere.

In my opinion, 1.X needs a new creature/player event named onMove() that is triggered each time they're moved. Until then, there really isn't a great way to imitate the removed mayNotMove() function in Lua.
 
This just won't work.

You have a global variable (it's global.lua, right? :p) This means it will only work for one player at a time.
When applying the function to player A, it'll work fine. But when applying the function to player B, it takes over the cid in event.
This ultimately allows player A to move again, but player B is still immovable until it stops or is replaced by the next user of the function.

Teleporting a player back to the original position every 100 milliseconds is a pretty hacky solution and is far from efficient.

Lastly, changing speed to 0 works fine. The speed change isn't applied until the first step is made.
So, you're gonna be moving very very very very slow at speed 1 until you reach next tile, then you won't be able to move anywhere.

In my opinion, 1.X needs a new creature/player event named onMove() that is triggered each time they're moved. Until then, there really isn't a great way to imitate the removed mayNotMove() function in Lua.
Well last time i tried to add onMove the the offical project, it was never accepted. Due to i tried to still mimic mayNotMove. Then after while, i heard maybe onMove will not be the best solution.
 
Sorry to get offtopic on this post, however a couple comments here raised some questions.


You have a global variable (it's global.lua, right? :p) This means it will only work for one player at a time.

What about with metamethods? Say I use CustomSkill.new("Mining", player, "MiningSkill", "MiningSkillTries") in the script, but for the parameters and functions and everything written for the rest of it is in global.lua? Would I still encounter same problem if multiple players tried to do it at the same time?


if allow then return stopEvent(event) else stopEvent(event) end

I never seen stopEvent() declared/defined. Nor did I see the parameter (event). I don't understand how this works? Please educate me :D
 
What about with metamethods? Say I use CustomSkill.new("Mining", player, "MiningSkill", "MiningSkillTries") in the script, but for the parameters and functions and everything written for the rest of it is in global.lua? Would I still encounter same problem if multiple players tried to do it at the same time?

Think about it like this: A function is a block on the memory that perform certain pre configured actions. You have only one block and two users. If they use it one at a time, it'll work perfectly, but if it there's a need for the to use at the same time, it'll not work as intended. See allowMovementEvent as an example. It's one block to stop movements of one person, so if you need to stop the movement of another you need another block, but here it uses the same block, so the first person will go back to moving.

If you code your functions with this in mind you'll not encounter the same problem.

I never seen stopEvent() declared/defined. Nor did I see the parameter (event). I don't understand how this works? Please educate me :D

stopEvent is declared in luascripts.cpp

As for event, it's declared at the end of the function allowMovementEvent. If you try to print it, on the very first use of the function it'll be nil, but after that it'll get a number value assigned by addEvent.

Think like this: You have that block (function) and after use, you don't wash it. The next person to use the block will see the dirty the person before left behind. It's what's happening.
 
Isn't this the same thing?
Code:
function Player:onMove(allow, fromPosition, position)
    if allow then
        self:teleportTo(position, true)
        return true
    else
        self:teleportTo(fromPosition, false)
        return false
    end   
end

Code:
function onStepIn(cid, item, position, fromPosition)
    Player(cid):onMove(false, fromPosition, position)
end
 
Isn't this the same thing?
Code:
function Player:onMove(allow, fromPosition, position)
    if allow then
        self:teleportTo(position, true)
        return true
    else
        self:teleportTo(fromPosition, false)
        return false
    end  
end

Code:
function onStepIn(cid, item, position, fromPosition)
    Player(cid):onMove(false, fromPosition, position)
end

Not quite, what PrinterLua script meant to do was that at any circumstance the player will not move. With yours, it'll only not move on tiles that you configure beforehand.
 
Back
Top