Advertisement
osmarks

CCSS Player Positions Agent

Mar 16th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 KB | None | 0 0
  1. local m = peripheral.find "modem"
  2. m.open(1103)
  3.  
  4. local pos = settings.get "ChorOS.position"
  5. if not pos then error "CCSS Player Positions Agent requires the position to be set." end
  6. pos = vector.new(unpack(pos))
  7.  
  8. while true do
  9.     local _, _, ch, rch, msg = os.pullEvent "modem_message"
  10.     if ch == 1103 and type(msg) == "table" then
  11.         local ldist = math.huge
  12.         for _, player in pairs(msg) do
  13.             local ppos = vector.new(unpack(player, 2))
  14.             local dist = (pos - ppos):length()
  15.             if dist < 16 and dist < ldist then
  16.                 local plr = player[1]
  17.                 ldist = dist
  18.                 print("Detected", plr)
  19.                 os.queueEvent("ccss_update", ("Welcome, %s!"):format(plr))
  20.             end
  21.         end
  22.     end
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement