[Event] Walkthrough everything Ctrl + Arrow keys [TFS 1.X]

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Printer, Jan 10, 2015.

  1. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    Hello,

    Well some people have requested this missing feature which could be found in 0.3 series. Well i have made one for TFS 1.x.

    I will send a pull request to the forgottenserver project, but in case it may not be accepted. Due to, this is mby a personal future. This way is alot better than 0.3, since 0.3 was hardcoded while this is made by lua with few lines. Which make it even more easier to edit stuff.

    Go to events/events.xml and onTurn make sure write from 0 to 1.
    Now go to events/scripts and open player.lua and find Player:eek:nTurn(direction) and replace with this:
    Code:
    function Player:onTurn(direction)
        if self:getGroup():getAccess() and self:getDirection() == direction then
            local nextPosition = self:getPosition()
            nextPosition:getNextPosition(direction)
    
            self:teleportTo(nextPosition, true)
        end
    
        return true
    end
    Cheers.
     
    Last edited: Aug 31, 2015
    imkingran, kito2, LordVissie and 11 others like this.
  2. Evan

    Evan A splendid one to behold Staff Member Global Moderator

    Joined:
    May 6, 2009
    Messages:
    7,014
    Pretty clever
     
  3. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    Thanks :)
     
  4. tigerx2

    tigerx2 Member

    Joined:
    Apr 5, 2010
    Messages:
    103
    Hello :)
    I'm testing it and I found two problems:
    1. You can't just turn your character direction without moving too
    2. The whole account get this benefit, while it should only affect the GOD character
     
  5. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    That is what it meant todo, it should not autowalk to that direction ^^

    About the second thing you could replace:
    Code:
    if self:getAccountType() == ACCOUNT_TYPE_GOD then
    with:
    Code:
    if self:getGroup():getId() == 3 then
     
    tigerx2 likes this.
  6. tigerx2

    tigerx2 Member

    Joined:
    Apr 5, 2010
    Messages:
    103
    I know this is what it's meant todo, but in 0.3 you could turn yourself (without moving), and then after a sec (with the keys pressed) the character started to walkthrough. I mean, you can't turn yourself without moving, do you get it now?
     
  7. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    No? Just hold ctrl + arrow key. Then it should walkthrough walls.
     
  8. Ninja

    Ninja 「Speedwagon Foundation」 Staff Member Global Moderator

    Joined:
    Apr 6, 2010
    Messages:
    5,853
    It shouldn't move the player if the parameter direction is not the same as player direction.

    Replace
    Code:
    if self:getAccountType() == ACCOUNT_TYPE_GOD then
    with
    Code:
    if self:getDirection() == direction and self:getGroup():getAccess() then
     
    tigerx2 and Codinablack like this.
  9. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    Oh, now i see. But i like the way i did :p
     
  10. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,425
    Here is same way as it works on 0.4:
    Code:
    local dir = {}
    function Player:onTurn(direction)
      if self:getAccountType() == ACCOUNT_TYPE_GOD then
         local cid = self:getId()
         if not dir[cid] then
           dir[cid] = direction
           return true
         end
       
         if dir[cid] == direction then
           local nextPosition = self:getPosition()
           nextPosition:getNextPosition(direction)
           dir[cid] = direction
           self:teleportTo(nextPosition, true)
         else
           dir[cid] = direction
         end
      end
      return true
    end
    
    info: if script doesn't work and there are no errors set this in events.xml to "1" as here:
    Code:
    <event class="Player" method="onTurn" enabled="1" />
     
  11. Ninja

    Ninja 「Speedwagon Foundation」 Staff Member Global Moderator

    Joined:
    Apr 6, 2010
    Messages:
    5,853
    Why are you using table to store player direction? :p
     
  12. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,425
    @Ninja
    This way it doesn't need storage to run.
     
  13. Ninja

    Ninja 「Speedwagon Foundation」 Staff Member Global Moderator

    Joined:
    Apr 6, 2010
    Messages:
    5,853
    @zbizu But you don't need to store player direction in a table in order to make it work like TFS 0.4 :p

    Code:
    function Player:onTurn(direction)
        if self:getDirection() == direction and self:getGroup():getAccess() then
            local nextPosition = self:getPosition()
            nextPosition:getNextPosition(direction)
    
            self:teleportTo(nextPosition, true)
        end
        return true
    end
     
    imkingran, HeberPcL and zbizu like this.
  14. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,425
    @Ninja
    Nice. You made it very short.
     
  15. strutZ

    strutZ Australian OT Member {AKA Beastn} Premium User

    Joined:
    Nov 16, 2014
    Messages:
    1,177
    Should edit main paste with ninjas code as printers wont work with TFS 1.2 =)
     
  16. Jaed Le Raep

    Jaed Le Raep ★Gaeming★

    Joined:
    Sep 3, 2007
    Messages:
    988
    This is awesome
     
  17. Moj mistrz

    Moj mistrz Monster Creator

    Joined:
    Feb 1, 2008
    Messages:
    913
    Hi guys, this script is really nice, I tried to remake it for monster spell(so monster can go through players and other monsters, but no blocking objects like walls), but I failed. This is where I get so far. I wanted to make it for TFS 1.2.
    Code:
    function onCastSpell(creature, var) 
        local direction = creature:getDirection()
        local nextPosition = creature:getPosition()
        if (queryTileAddThing(creature, nextPosition) == RETURNVALUE_NOERROR) then
            nextPosition:getNextPosition(direction)
             
            creature:teleportTo(nextPosition, true)
        end
        return true
    end
    Actually it works only for players + it checks if item is blockable only when you are already teleported on it :/, it wouldn't be so bad, but it still don't work for monsters, dunno why. It only works when I remove queryTileAddThing line, but it gives monster opportunity to walk on walls etc. I am sorry if it's not good thread for that, but I didn't wanted to make new one just to fix some easy(I suppose :D) thing. Would be also good if it moves creatures on its way(just like giant spider pushes minotaur for example).
    Thanks for any help :).
     
    Last edited: Aug 31, 2015
  18. bertil430

    bertil430 Member

    Joined:
    Nov 25, 2015
    Messages:
    85
    Hello I want this ability on my server, but im using OThire 2.0 so how should my script look like and where should I put it? I dont have events on my OT since its not newer versions
     
  19. HeberPcL

    HeberPcL [PowerOT.com.br] Premium User

    Joined:
    Aug 21, 2007
    Messages:
    1,271
    Thanks!!
     
  20. Dyabl0

    Dyabl0 Just stop copying my outfit colours

    Joined:
    Sep 22, 2009
    Messages:
    1,791
    How do you do instead of moving with Ctrl+Arrows (direction look), just press arrows and moves on.
    Also, if this is possible it should be allowed only between players and in pz tiles, nothing else.
     

Share This Page