Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.38 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 = {"Heal You", "Splittah", "Splitter", "Green Arrow", "Viruz", "Bacteria", "Idfkmanlul", "Idfklulman", "Ed Is Lyf"} -- list of friends
  9. local BELOW = true -- check for players below you
  10. local ABOVE = false -- check for player above you
  11. local LEVELS = 1 -- 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 LEVELSMonster = 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.
  13. local SAFE_POS = {32661, 32240, 9} -- safe position to step when player detected {x, y, z}
  14. local STEP_BACK = {enabled = true, pos = {32661, 32239, 9}, delay = 0.1} -- return to previus position when will safe, @eabled - true/false, @pos - {x, y, z}, @delay - minutes
  15. local OUTSIDE_POS = {32661, 32239, 9}
  16. local RECCONNECT = true -- reconnect to game when lost connection or game issue @true/false
  17.  
  18.  
  19. -- DON'T EDIT BELOW THIS LINE
  20.  
  21. -- convert table to lower strings.
  22. FRIENDS = table.lower(FRIENDS)
  23.  
  24. -- declare global vars
  25. stepTime, printfTime, stepDate, lastPlayer = 0, 0, "", ""
  26.  
  27.  
  28. ----------------------------------------------------------------------------------------------------------------------------------------------------------
  29. --> Function: getPlayer(pos)
  30. --> Description: Get player on multiple floors.
  31. --> Class: Self
  32. --> Params:
  33. --> @pos - an array returned by Self.Position()
  34. -->
  35. --> Return: table with creature or false when failed.
  36. ----------------------------------------------------------------------------------------------------------------------------------------------------------
  37. function getPlayer(pos)
  38.  
  39. -- load self id.
  40. local selfName = Self.Name()
  41.  
  42. -- inside loop for all found creatures on multiple floors do:
  43. for i, player in pairs(Creature.getCreatures()) do
  44.  
  45. -- when we can not find a friends and creature is player:
  46. if not table.find(FRIENDS, string.lower(player.name)) and Creature.isPlayer(player) and player.name ~= selfName then
  47.  
  48. -- load complicated var to check which players we searching, above, belowe or both and also amount of levels
  49. 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)
  50.  
  51. -- when var contains true a player was found
  52. if var then
  53.  
  54. -- return table with creature
  55. return player
  56.  
  57. end
  58.  
  59. end
  60.  
  61. end
  62.  
  63. -- return false noone player found.
  64. return false
  65.  
  66. end
  67.  
  68. function getMonster(pos)
  69.  
  70. -- load self id.
  71. local selfName = Self.Name()
  72.  
  73. -- inside loop for all found creatures on multiple floors do:
  74. for i, monster in pairs(Creature.getCreatures()) do
  75.  
  76. -- when we can not find a friends and creature is monster:
  77. if not table.find(FRIENDS, string.lower(monster.name)) and Creature.isMonster(monster) and monster.name ~= selfName then
  78.  
  79. -- load complicated var to check which players we searching, above, belowe or both and also amount of levels
  80. local var = (BELOW and (pos.z - monster.z) <= 0 and (pos.z - monster.z) >= (-LEVELSMonster)) or (ABOVE and (pos.z - monster.z) >= 0 and (pos.z - monster.z) <= LEVELSMonster)
  81.  
  82. -- when var contains true a monster was found
  83. if var then
  84.  
  85. -- return table with creature
  86. return monster
  87.  
  88. end
  89.  
  90. end
  91.  
  92. end
  93.  
  94. -- return false noone player found.
  95. return false
  96.  
  97. end
  98.  
  99.  
  100. -- Start with module loop 200ms
  101. Module.New("Multifloor Player Step", function (mod)
  102.  
  103. -- when my char is connected to game
  104. if Self.isConnected() then
  105.  
  106. -- load self position
  107. local selfpos = Self.Position()
  108.  
  109. -- call function to get player
  110. local player = getPlayer(selfpos)
  111. local monster = getMonster(selfpos)
  112.  
  113. -- when var: player is different than false we found a player.
  114. if player ~= false then
  115.  
  116. -- when creature is range x = {-7, 7} y = {-5, 5} to avoid stuck on step.
  117. if math.abs(player.x - selfpos.x) <= 7 and math.abs(player.y - selfpos.y) <= 5 then
  118.  
  119. -- load distance between safe position and your character.
  120. local distance = Self.DistanceFromPosition(SAFE_POS[1], SAFE_POS[2], SAFE_POS[3])
  121.  
  122. -- when distance will above 0:
  123. if distance > 0 then
  124.  
  125. -- load a direction to step.
  126. local dir = Self.getDirectionFromPosition(SAFE_POS[1], SAFE_POS[2], SAFE_POS[3], distance)
  127.  
  128. -- step to direction.
  129. Self.Step(dir)
  130.  
  131. -- show message about stepping.
  132. printf("Stepping to safe pos due a player: " .. player.name)
  133.  
  134. -- set player.name and date
  135. stepTime = os.time()
  136. lastPlayer = player.name
  137.  
  138. -- wait some time to avoid over dashing.
  139. wait(500, 1000)
  140.  
  141. -- we are on safe pos.
  142.  
  143. else
  144.  
  145. -- when stepDate is contains empty string set display params.
  146. if stepDate == "" then
  147.  
  148. -- set date
  149. stepDate = os.date("%X")
  150.  
  151. -- set massage about enabled stepBack.
  152. local back = "Step back is enabled and time count down will start when player leave detecing area."
  153.  
  154. -- when param STEP_BACK.enabled contains false we set back to false
  155. if not STEP_BACK.enabled then
  156.  
  157. -- back will now contains disabled
  158. back = "Step back is disabled."
  159.  
  160. end
  161.  
  162. -- display a message inside Rifbot.InformationBox
  163. printf("[" .. stepDate .. "] Successfully step due a player detected [" .. lastPlayer .. "] " .. back)
  164.  
  165. end
  166.  
  167. end
  168.  
  169. end
  170.  
  171. -- Searching for Monster in Area --
  172.  
  173. elseif monster ~= false then
  174.  
  175. -- when creature is range x = {-7, 7} y = {-5, 5} to avoid stuck on step.
  176. if math.abs(monster.x - selfpos.x) <= 7 and math.abs(monster.y - selfpos.y) <= 5 then
  177.  
  178. -- load distance between safe position and your character.
  179. local distance = Self.DistanceFromPosition(SAFE_POS[1], SAFE_POS[2], SAFE_POS[3])
  180.  
  181. -- when distance will above 0:
  182. if distance > 0 then
  183.  
  184. -- load a direction to step.
  185. local dir = Self.getDirectionFromPosition(SAFE_POS[1], SAFE_POS[2], SAFE_POS[3], distance)
  186.  
  187. -- step to direction.
  188. Self.Step(dir)
  189.  
  190. -- show message about stepping.
  191. printf("Stepping to safe pos due a monster: " .. monster.name)
  192.  
  193. -- set monster.name and date
  194. stepTime = os.time()
  195. lastPlayer = monster.name
  196.  
  197. -- wait some time to avoid over dashing.
  198. wait(500, 1000)
  199.  
  200. -- we are on safe pos.
  201.  
  202. else
  203.  
  204. -- when stepDate is contains empty string set display params.
  205. if stepDate == "" then
  206.  
  207. -- set date
  208. stepDate = os.date("%X")
  209.  
  210. -- set massage about enabled stepBack.
  211. local back = "Step back is enabled and time count down will start when player leave detecing area."
  212.  
  213. -- when param STEP_BACK.enabled contains false we set back to false
  214. if not STEP_BACK.enabled then
  215.  
  216. -- back will now contains disabled
  217. back = "Step back is disabled."
  218.  
  219. end
  220.  
  221. -- display a message inside Rifbot.InformationBox
  222. printf("[" .. stepDate .. "] Successfully step due a monster detected [" .. lastPlayer .. "] " .. back)
  223.  
  224. end
  225.  
  226. end
  227.  
  228. end
  229.  
  230.  
  231.  
  232. -- player & monster is not found on detecting area.
  233. else
  234.  
  235. -- when we have enabled step back.
  236. if STEP_BACK.enabled then
  237.  
  238. -- when time is valid.
  239. if os.time() - stepTime > (STEP_BACK.delay * 60) then
  240.  
  241. -- load distance between safe position and your character.
  242. local distance = Self.DistanceFromPosition(STEP_BACK.pos[1], STEP_BACK.pos[2], STEP_BACK.pos[3])
  243.  
  244. -- when our position is different than currentPos.
  245. if distance > 0 then
  246.  
  247. if(Self.Health() > 150) then
  248. -- load direction to step.
  249. Self.CastSpell("alana sio")
  250.  
  251. -- step to this direction.
  252. Self.Step(dir)
  253.  
  254. -- wait some time to avoid over dashing.
  255. wait(500, 1000)
  256. end
  257.  
  258. -- our position is this same as we stay before
  259. else
  260.  
  261. -- when stepDate is different than "" display message.
  262. if stepDate ~= "" then
  263.  
  264. -- set message to console.
  265. printf("[" .. os.date("%X") .. "] Successfully return to position due a previus player detected: " .. lastPlayer)
  266.  
  267. -- clear time var and stepDate
  268. stepTime = 0
  269. stepDate = ""
  270.  
  271. end
  272.  
  273. end
  274.  
  275. -- invalid time to step back
  276. else
  277.  
  278. -- when time of printing is ok
  279. if os.time() - printfTime > 1 then
  280.  
  281. -- display info about.
  282. printf("[" .. stepDate .. "] Successfully step due a player detected [" .. lastPlayer .. "] step back for " .. math.floor((STEP_BACK.delay * 60) - (os.time() - stepTime)) .. "s.")
  283.  
  284. -- load current time
  285. printfTime = os.time()
  286.  
  287. end
  288.  
  289. -- load distance between safe position and your character.
  290. local distance = Self.DistanceFromPosition(STEP_BACK.pos[1], STEP_BACK.pos[2], STEP_BACK.pos[3])
  291.  
  292. -- when our position is this same as currentPos.
  293. if distance <= 0 then
  294.  
  295. -- reset time and clear date
  296. stepTime = 0
  297. stepDate = ""
  298.  
  299. end
  300.  
  301. end
  302.  
  303. -- step back is disabled
  304. else
  305.  
  306. -- clear step date.
  307. stepDate = ""
  308.  
  309. end
  310.  
  311. end
  312.  
  313. -- we are offline
  314. else
  315.  
  316. -- when reconnect contains true.
  317. if RECCONNECT then
  318.  
  319. -- press enter key
  320. Rifbot.PressKey(13, 3000)
  321.  
  322. end
  323.  
  324. end
  325.  
  326. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement