Advertisement
Guest User

savePos.lua

a guest
Sep 12th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. file = fs.open("curPlayers","r")
  2. playerNames = {}
  3. i=0
  4.     repeat
  5.     i=i+1
  6.     line = file.readLine()
  7.     playerNames[i] = line
  8.     until line == nil
  9. playerNames[i] = nil
  10. file.close()
  11.  
  12.  
  13.  
  14. rednet.open("right")
  15.  
  16. playerPos = {}
  17.     for k,v in pairs(playerNames) do
  18.     rednet.send(939,k-1)
  19.     rednet.send(939,"start")
  20.     sleep(0.4)
  21.     playerPos[k] = {}
  22.     rednet.send(936,"start")
  23.     rednet.send(937,"start")
  24.     rednet.send(938,"start")
  25.     rednet.send(939,"stop")
  26.    
  27.     os.startTimer(0.05)
  28.         repeat
  29.         info1,info2,info3,info4 = os.pullEvent()
  30.             if info1 == "rednet_message" and type(info3) == "table" then
  31.                 if info3["action"] == "sendingX" then
  32.                 playerPos[k]["x"] = info3["x"]
  33.                 end
  34.                
  35.                 if info3["action"] == "sendingY" then
  36.                 playerPos[k]["y"] = info3["y"]
  37.                 end
  38.                
  39.                 if info3["action"] == "sendingZ" then
  40.                 playerPos[k]["z"] = info3["z"]
  41.                 end
  42.             end
  43.         until info1 == "timer"
  44.     rednet.send(939,"stop")
  45.     sleep(0.2)
  46.     end
  47.    
  48. rednet.send(939,0)
  49.  
  50.  
  51.  
  52.     for k,v in pairs(playerNames) do
  53.     print(playerNames[k])
  54.     file = fs.open("playerPos/" .. os.day("local") .. "/" .. (math.floor(os.time("local")*1000)/1000) .. "/" .. playerNames[k],"w")
  55.    
  56.     file.writeLine(playerPos[k]["x"])
  57.     file.writeLine(playerPos[k]["y"])
  58.     file.writeLine(playerPos[k]["z"])
  59.    
  60.     file.flush()
  61.     file.close()
  62.     end
  63.    
  64.    
  65. rednet.send(941,"ping")
  66. os.startTimer(0.1)
  67.     repeat
  68.     info1,info2,info3,info4 = os.pullEvent()
  69.     until info3 == "pong" or info1 == "timer"
  70.    
  71.    
  72.     if info3 == "pong" then
  73.    
  74.    
  75.    
  76.     end
  77.  
  78.    
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement