Advertisement
Rnen10

Computercraft Commandcomputer Playercount

Mar 20th, 2024 (edited)
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | Gaming | 0 0
  1. -- This scripts saves current playercount to a file ever 20 seconds. Must be a commandblock computer and chunkloaded.
  2. -- Made this to cirumvent the Rcon playerlist & /testfor bug returning 0 players at all times on MC 1.7.10, reading the file on the webserver
  3.  
  4. local function SaveFile(data)
  5.     local file = fs.open("playerCount","w")
  6.     sleep(0.1)
  7.     file.write(textutils.serialize(data))
  8.     sleep(0.1)
  9.     file.close()
  10. end
  11.  
  12. while true do
  13.     ok, result = commands.xp( "0 @a[r=" .. tostring( nLimit ) .. "]" )
  14.  
  15.     local int=0
  16.     for k,v in pairs(result) do
  17.         int=int+1
  18.     end
  19.  
  20.     SaveFile(int)
  21.     term.clear()
  22.     term.setCursorPos(1,1)
  23.     print("There are currently "..int.." player(s) online")
  24.     sleep(20)
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement