Advertisement
tdy2012

CC Mekanism Radiation Warning

Jun 14th, 2023 (edited)
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | Source Code | 0 0
  1. PLAYER_DETECTOR_SIDE = "RIGHT"
  2. CHAT_BOX_SIDE = "LEFT"
  3. INCIDENT_DIMENSION = "minecraft:overworld"
  4. INCIDENT_POS = {x=0, y=0, z=0}
  5. INCIDENT_RADIUS = 10
  6.  
  7. function euclideanDistance(pos1, pos2)
  8.     return math.sqrt((pos2.x - pos1.x)^2 + (pos2.y - pos1.y)^2 + (pos2.z - pos1.z)^2)
  9. end
  10.  
  11. playerDetector = peripheral.wrap(PLAYER_DETECTOR_SIDE)
  12. chatBox = peripheral.wrap(CHAT_BOX_SIDE)
  13.  
  14. if playerDetector == nil or chatBox == nil then
  15.     error('ERROR - Invalid peripheral sides.')
  16. end
  17.  
  18. while(true)
  19. do
  20.     onlinePlayers = playerDetector.getOnlinePlayers()
  21.     for playerIndex = 1, #onlinePlayers do
  22.         local playerName = onlinePlayers[playerIndex]
  23.         local playerPos = playerDetector.getPlayerPos(playerName)
  24.         if playerPos ~= nil and playerPos.dimension == INCIDENT_DIMENSION then
  25.             if euclideanDistance(playerPos, INCIDENT_POS) <= INCIDENT_RADIUS then
  26.                 chatBox.sendMessageToPlayer("You are now entering a radiation area. Please put on a Hazmat suit.", playerName, "WARNING")
  27.             end
  28.         end
  29.     end
  30.     sleep(5)
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement