Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.84 KB | None | 0 0
  1. --[[
  2.     Script Name:        Multifloor Player Step
  3.     Description:        Step to safe position when character detected on multiple floors.
  4.     Required:           Valid position of safe pos example house door and pos to return sqm front of house. To get this position go to Rifbot -> Options -> GetCurrentPos
  5.     Author:             Ascer - example
  6. ]]
  7.  
  8. local FRIENDS = {"friend1", "friend2"}                                      -- list of friends
  9. local BELOW = true                                                          -- check for players below you
  10. local ABOVE = false                                                         -- check for player above you
  11. local LEVELS = 0                                                            -- search for one floor above or below / limit is 2 / do not check floors below on level 7. To search only on your floor put 0.
  12. local SAFE_POS = {32664, 31642, 5}                                          -- safe position to step when player detected {x, y, z}
  13. local STEP_BACK = {enabled = true, pos = {32662, 31642, 5}, delay = 0.1}    -- return to previus position when will safe, @eabled - true/false, @pos - {x, y, z}, @delay - minutes
  14. local RECCONNECT = true                                                     -- reconnect to game when lost connection or game issue @true/false
  15.  
  16.  
  17. -- DON'T EDIT BELOW THIS LINE
  18.  
  19. -- convert table to lower strings.
  20. FRIENDS = table.lower(FRIENDS)
  21.  
  22. -- declare global vars
  23. stepTime, printfTime, stepDate, lastPlayer = 0, 0, "", ""
  24.  
  25.  
  26. ----------------------------------------------------------------------------------------------------------------------------------------------------------
  27. --> Function:       getPlayer(pos)
  28. --> Description:    Get player on multiple floors.
  29. --> Class:          Self
  30. --> Params:        
  31. -->                 @pos - an array returned by Self.Position()
  32. -->                
  33. --> Return:         table with creature or false when failed.
  34. ----------------------------------------------------------------------------------------------------------------------------------------------------------
  35. function getPlayer(pos)
  36.  
  37.     -- load self id.
  38.     local selfName = Self.Name()
  39.  
  40.     -- inside loop for all found creatures on multiple floors do:
  41.     for i, player in pairs(Creature.getCreatures()) do
  42.  
  43.         -- when we can not find a friends and creature is player:
  44.         if not table.find(FRIENDS, string.lower(player.name)) and Creature.isPlayer(player) and player.name ~= selfName then
  45.            
  46.             -- load complicated var to check which players we searching, above, belowe or both and also amount of levels
  47.             local var = (BELOW and (pos.z - player.z) <= 0 and (pos.z - player.z) >= (-LEVELS)) or (ABOVE and (pos.z - player.z) >= 0 and (pos.z - player.z) <= LEVELS)
  48.            
  49.             -- when var contains true a player was found
  50.             if var then
  51.  
  52.                 -- return table with creature
  53.                 return player
  54.  
  55.             end
  56.  
  57.         end
  58.  
  59.     end
  60.  
  61.     -- return false noone player found.
  62.     return false
  63.  
  64. end
  65.  
  66.  
  67. -- Start with module loop 200ms
  68. Module.New("Multifloor Player Step", function (mod)
  69.  
  70.     -- when my char is connected to game
  71.     if Self.isConnected() then
  72.  
  73.         -- load self position
  74.         local selfpos = Self.Position()
  75.  
  76.         -- call function to get player
  77.         local player = getPlayer(selfpos)
  78.  
  79.         -- when var: player is different than false we found a player.
  80.         if player ~= false then
  81.  
  82.             -- when creature is range x = {-7, 7} y = {-5, 5} to avoid stuck on step.
  83.             if math.abs(player.x - selfpos.x) <= 7 and math.abs(player.y - selfpos.y) <= 5 then
  84.  
  85.                 -- load distance between safe position and your character.
  86.                 local distance = Self.DistanceFromPosition(SAFE_POS[1], SAFE_POS[2], SAFE_POS[3])
  87.  
  88.                 -- when distance will above 0:
  89.                 if distance > 0 then
  90.  
  91.                     -- load a direction to step.
  92.                     local dir = Self.getDirectionFromPosition(SAFE_POS[1], SAFE_POS[2], SAFE_POS[3], distance)
  93.  
  94.                     -- step to direction.
  95.                     Self.Step(dir)
  96.  
  97.                     -- show message about stepping.
  98.                     printf("Stepping to safe pos due a player: " .. player.name)
  99.  
  100.                     -- set player.name and date
  101.                     stepTime = os.time()
  102.                     lastPlayer = player.name
  103.  
  104.                     -- wait some time to avoid over dashing.
  105.                     wait(500, 1000)
  106.  
  107.                 -- we are on safe pos.
  108.                 else   
  109.  
  110.                     -- when stepDate is contains empty string set display params.
  111.                     if stepDate == "" then
  112.  
  113.                         -- set date
  114.                         stepDate = os.date("%X")
  115.                    
  116.                         -- set massage about enabled stepBack.
  117.                         local back = "Step back is enabled and time count down will start when player leave detecing area."
  118.  
  119.                         -- when param STEP_BACK.enabled contains false we set back to false
  120.                         if not STEP_BACK.enabled then
  121.  
  122.                             -- back will now contains disabled
  123.                             back = "Step back is disabled."
  124.  
  125.                         end
  126.  
  127.                         -- display a message inside Rifbot.InformationBox
  128.                         printf("[" .. stepDate .. "] Successfully step due a player detected [" .. lastPlayer .. "] " .. back)
  129.                    
  130.                     end
  131.                    
  132.                 end
  133.  
  134.             end
  135.  
  136.         -- player is not found on detecting area.
  137.         else       
  138.            
  139.             -- when we have enabled step back.
  140.             if STEP_BACK.enabled then
  141.  
  142.                 -- when time is valid.
  143.                 if os.time() - stepTime > (STEP_BACK.delay * 60) then
  144.  
  145.                     -- load distance between safe position and your character.
  146.                     local distance = Self.DistanceFromPosition(STEP_BACK.pos[1], STEP_BACK.pos[2], STEP_BACK.pos[3])
  147.  
  148.                     -- when our position is different than currentPos.
  149.                     if distance > 0 then
  150.  
  151.                         -- load direction to step.
  152.                         local dir = Self.getDirectionFromPosition(STEP_BACK.pos[1], STEP_BACK.pos[2], STEP_BACK.pos[3], distance)
  153.  
  154.                         -- step to this direction.
  155.                         Self.Say("Alana Sio")
  156.  
  157.                         -- wait some time to avoid over dashing.
  158.                         wait(500, 1000)
  159.  
  160.                     -- our position is this same as we stay before
  161.                     else
  162.                        
  163.                         -- when stepDate is different than "" display message.
  164.                         if stepDate ~= "" then
  165.  
  166.                             -- set message to console.
  167.                             printf("[" .. os.date("%X") .. "] Successfully return to position due a previus player detected: " .. lastPlayer)
  168.  
  169.                             -- clear time var and stepDate
  170.                             stepTime = 0
  171.                             stepDate = ""
  172.  
  173.                         end
  174.  
  175.                     end
  176.                
  177.                 -- invalid time to step back
  178.                 else           
  179.  
  180.                     -- when time of printing is ok
  181.                     if os.time() - printfTime > 1 then
  182.  
  183.                         -- display info about.
  184.                         printf("[" .. stepDate .. "] Successfully step due a player detected [" .. lastPlayer .. "] step back for " .. math.floor((STEP_BACK.delay * 60) - (os.time() - stepTime)) .. "s.")
  185.  
  186.                         -- load current time
  187.                         printfTime = os.time()
  188.  
  189.                     end
  190.  
  191.                     -- load distance between safe position and your character.
  192.                     local distance = Self.DistanceFromPosition(STEP_BACK.pos[1], STEP_BACK.pos[2], STEP_BACK.pos[3])
  193.  
  194.                     -- when our position is this same as currentPos.
  195.                     if distance <= 0 then
  196.  
  197.                         -- reset time and clear date
  198.                         stepTime = 0
  199.                         stepDate = ""
  200.  
  201.                     end
  202.                        
  203.                 end
  204.                
  205.             -- step back is disabled   
  206.             else       
  207.  
  208.                 -- clear step date.
  209.                 stepDate = ""
  210.  
  211.             end
  212.        
  213.         end
  214.  
  215.     -- we are offline  
  216.     else       
  217.  
  218.         -- when reconnect contains true.
  219.         if RECCONNECT then
  220.  
  221.             -- press enter key
  222.             Rifbot.PressKey(13, 3000)
  223.  
  224.         end
  225.            
  226.     end
  227.        
  228. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement