This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
KingofGamesYami's profile picture

CommandsPlus

Started by KingofGamesYami, 31 May 2016 - 06:29 PM
KingofGamesYami #1
Posted 31 May 2016 - 08:29 PM
The objective of CommandsPlus is to extract data from the results of running various commands. For example, teleporting an armor stand to a player gives us the player's coordinates and which way he's facing.
pastebin get eZRj0fAD commandsPlus.
List of Functions
getPlayerPosition( playerName )
Retrieves the position (x, y, z) of the specified player. Specifying something other than an online player's name will result in an error.
getPlayerRotation( playerName )
Retrieves the rotation (about the vertical axis, about the horizantal axis) of the specified player. Again, specifying something other than an online player's name will result in an error.
getNearbyPlayers( nLimit )
Retrieves a list of players within nLimit blocks of the computer. If nLimit is not specified, no radius will be used.
getGameruleValue( gamerule )
Retrieves the value of a gamerule (eg "commandBlockOutput")
getDaysPassed()
Retrieves the number of (in game) days passed since the world's creation.
getGametime()
Retrieves the current gametime.
getDaytime()
Retrieves the (in game) time of day.
getWorldborder()
Retrieves the current radius of the world's border.
getFormattedBlockInfos( x1, y1, z1, x2, y2, z2 )
Retrieves information using commands.getBlockInfos, but formats it into a table indexed by coordinates.
getObservedBlock( playerName )
Retrieves the block currently being observed by playerName. Credit to moomoomoo3O9 for the original function
Note: this is sometimes inaccurate due to non-full blocks or entities.
getForgeTPS()
Retrieves information about ticks-per-second. The table is formatted like so:
Spoiler

{
[ dimension ] = { time = MEAN_TIME, tps = MEAN_TPS }
}
listScoreboardTeams()
Retrieves a table of teams with the number of players on each team, in the format t[ name ] = number_of_players
listScoreboardObjectives()
Retrieves a table of objectives and their display name and type, in the format t[ name ] = {displayName = "Hello", type = "World"}
listScoreboardPlayers()
Retrieves a table of players being tracked by scoreboard.
listScoreboardTeamPlayers( teamName )
Retrieves a list of players on team teamName
If there are any commands you'd like me to add, please comment below ;)/>/>
Updates:
1.1 - Added getObservedBlock and getFormattedBlockInfos, added second argument to getPlayerPosition, changed behavior of getNearbyPlayers when no limit specified.
1.2 - Added getForgeTPS()
1.25 - Removed second argument from getPlayerPosition, added caching. The data is only cached for 1 tick, so that if you use getObservedBlock and getPlayerPosition or getPlayerRotation, it won't teleport things more than it needs to.
1.3 - Added listScoreboardTeams, listScoreboardObjectives, listScoreboardPlayers, and listScoreboardTeamPlayers
Edited on 08 June 2016 - 02:01 PM
Bomb Bloke #2
Posted 01 June 2016 - 03:23 PM
Maybe you could look into implementing the "get block looked at" functionality discussed here? moomoomoo may perhaps be willing to share the code he ended up using… NBT editing capabilities would also be handy in an API! :)/>

If nLimit is not specified, the radius of the world border will be used instead.

Er, just to clarify, do you mean "the whole world will be checked", or do you really mean "a circular area sitting within the world bounds will be checked" (hence excluding the world's corners)?

getDaysPassed()
Retrieves the number of (in game) days passed since the world's creation.

getDaytime()
Retrieves the (in game) time of day.

Truth be told, we've already go os.time() and os.day() for these ones. I suppose by extension they'd cover getGametime() as well.
KingofGamesYami #3
Posted 01 June 2016 - 03:41 PM
Maybe you could look into implementing the "get block looked at" functionality discussed here? moomoomoo may perhaps be willing to share the code he ended up using… NBT editing capabilities would also be handy in an API! :)/>/>
I'll look into it.

Er, just to clarify, do you mean "the whole world will be checked", or do you really mean "a circular area sitting within the world bounds will be checked" (hence excluding the world's corners)?

I mean "a circular area sitting within the world bounds will be checked". In the future, I might just remove the range limit entirely for this case.

Truth be told, we've already go os.time() and os.day() for these ones. I suppose by extension they'd cover getGametime() as well.

Actually, I think some of them are different. /time uses ticks, not seconds. Anyhow, I'm not going to remove the functionality.
Wergat #4
Posted 01 June 2016 - 06:10 PM
You could add some Scroreboard-Features to count the player's Deaths, Kills and more!
Bomb Bloke #5
Posted 02 June 2016 - 02:50 AM
Furthermore, something to parse the TPS values returned by the /forge tps command (or whatever it is) could be handy.
KingofGamesYami #6
Posted 04 June 2016 - 09:02 PM
You could add some Scroreboard-Features to count the player's Deaths, Kills and more!
I think scoreboard deserves it's own API. I also don't understand it :(/>

Furthermore, something to parse the TPS values returned by the /forge tps command (or whatever it is) could be handy.
I can't find any documentation on this, unfortunately.

Updated to 1.1!
Emma #7
Posted 04 June 2016 - 09:44 PM
–snip–
Furthermore, something to parse the TPS values returned by the /forge tps command (or whatever it is) could be handy.
I can't find any documentation on this, unfortunately.
–snip–

The /tps command isn't a default command included with forge, but COFH-Core has it, which is in most modpacks.
http://teamcofh.com/...s/commands/#tps


Turns out I was mistaken, it is indeed /forge tps
Here is the output:
Spoiler
The format of the output is as follows. Each line denotes a different dimension that is being measured except for the last line which gives the overall tps (averaged tick over all dimensions)
Line format: Dim [dimension number] : Mean tick time: [time between processed ticks] ms. Mean TPS: [ticks per second]
Edited on 04 June 2016 - 07:55 PM
KingofGamesYami #8
Posted 04 June 2016 - 10:17 PM
Strangely, my minecraft client adds a \ before each :. I've compensated for both in my pattern, but I would like someone to try it before I publish.
Spoiler

function getForgeTPS()
  local ok, result = commands.forge( "tps" )
  local t = {}
  for k, v in pairs( result ) do
    local dim, time, tps = v:match( "D?i?m? ?(%S+).-time\\?: (%S+).-TPS\\?: (%S+)" )
    t[ tonumber( dim ) or dim ] = { time = tonumber( time ), tps = tonumber( tps ) }
  end
  return t
end
Edited on 04 June 2016 - 08:22 PM
Bomb Bloke #9
Posted 05 June 2016 - 01:09 PM
I guess the slash thing has something to do with later versions of Minecraft; I had to go back to one of my 1.7.10 installs to get rid of them.

I find the function works correctly with or without them, though I was thrown off for a moment when I didn't get data for dimension 1 (The End). Seems it isn't automatically chunk loaded in the older build.
KingofGamesYami #10
Posted 06 June 2016 - 02:09 PM
Thanks for testing BB! I've added getForgeTPS and caching now!

Updated to 1.25!
DannySMc #11
Posted 06 June 2016 - 03:35 PM
This is really cool and very useful, definitely add support for Scoreboard.
KingofGamesYami #12
Posted 08 June 2016 - 03:28 PM
Updated with support for scoreboard! If there are any scoreboard commands that I'm not supporting, please let me know!

Updated to 1.3
Reinified #13
Posted 17 June 2017 - 07:07 PM
Incredibly useful, thanks so much!
Especially listScoreboardTeamPlayers.

THANKS!