Advertisement
Guest User

safespace.lua

a guest
Oct 15th, 2022
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. _addon.name = 'Safe Space'
  2. _addon.version = '0.1.2'
  3. _addon.author = 'Kastra (Lili - original code)'
  4.  
  5. require('logger')
  6. local packets = require("packets")
  7.  
  8. local so = {
  9.     player = false,
  10.     partymembers = {},
  11.     zone = false,
  12. }
  13.  
  14. local blocked = {}
  15.  
  16.  
  17. -- Manually created collection of things to block.
  18. -- "r" is the radius within which NO PLAYER CHARACTERS WILL APPEAR
  19. local oboro   = {x = -180.00, y =   86.00, z =   11.00, r =  5, zone = 246}
  20. local odyssey = {x =    0.60, y =  120.00, z =    8.00, r = 10, zone = 247}
  21. local ruspix = {x =    -36.00, y =  0.00, z =    0.00, r = 10, zone = 281}
  22. local sortie = {x =    -250.00, y =  360.00, z =    3.00, r = 5, zone = 267}
  23. local ambu    = {x =  -27.10, y =   52.56, z =  -16.00, r =  8, zone = 249}
  24. local oseem   = {x =   13.89, y =   24.25, z =    0.24, r =  5, zone = 252}
  25. local dragonA = {x =   -1.47, y =   39.04, z =    0.00, r = 30, zone = 288} -- Zi'tah dragon
  26. local dragonB = {x =   -0.17, y = -210.26, z =  -43.60, r = 30, zone = 289} -- Ru'aun dragon
  27. local dragonC = {x =  623.53, y = -934.87, z = -371.58, r = 30, zone = 291} -- Reisenjima dragon
  28.  
  29. -- List of those things to block. Used to automatically detech which one to block based on player current zone.
  30. local things = {}
  31. things[246] = oboro
  32. things[247] = odyssey
  33. things[281] = ruspix
  34. things[267] = sortie
  35. things[249] = ambu
  36. things[252] = oseem
  37. things[288] = dragonA
  38. things[289] = dragonB
  39. things[291] = dragonC
  40.  
  41. windower.register_event('load','login',function()
  42.     so.player = windower.ffxi.get_player()
  43.     so.zone = windower.ffxi.get_info().zone
  44.     so.partymembers = windower.ffxi.get_party()
  45.  
  46.     thing = things[so.zone] or oboro  -- When the add-on is loaded, thing == oboro by default
  47. end)
  48.  
  49. function thing_is_near(t)
  50.     local t = t or windower.ffxi.get_mob_by_target('me')
  51.     if t.x then t.X = t.x t.Y = t.y end
  52.  
  53.     local dist = math.sqrt((thing.x - t.X)^2 + (thing.y - t.Y)^2)
  54.     return thing.r > dist and dist
  55. end
  56.  
  57.  
  58. windower.register_event('zone change',function(id)
  59.     -- If zoning, change the thing to block based on which zone
  60.     -- Keeps old value if zoning into an area without something to block.
  61.     so.zone = id
  62.     thing = things[so.zone] or thing
  63.     -- print(thing.zone)
  64. end)
  65.  
  66. windower.register_event('unload','logout', function()
  67.     so.player = false
  68.     so.zone = false
  69. end)
  70.  
  71. windower.register_event('incoming chunk', function (id, org, mod, inj)
  72.     if so.zone ~= thing.zone or not so.player or inj then
  73.         return
  74.     end
  75.  
  76.     if id == 0x00D and string.sub(org, 5,8):unpack("I") ~= so.player.id then
  77.  
  78.         local p = packets.parse('incoming', org)
  79.  
  80.         if thing_is_near(p) then -- oboro.r > math.sqrt((oboro.x - p.X)^2 + (oboro.y - p.Y)^2) then
  81.            p.Despawn = true
  82.            return packets.build(p)
  83.         end
  84.     end
  85. end)
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement