Everything has start. Even those old physics teachers who seem to have been around since the beginning of the universe. And, of course, the Maizuma Creative Server also had one.
The server, today powered by more than 2000 Command Blocks running multiple functions, from the very handy Return to a custom Fill and Clone, recreated to work for non opped players; was also a simple "build wherever you want" type of deal once.
After a while, we (Cass and I) decided to organize everything, and so it was born the Maizuma Creative Server 2!
I love these fancy names.
But now let's talk about what's fun, Command Blocks. Today will be a super simple explanation so we can start covering everything from the basics. There'll be some tricks I used in the end as well.
The Command Book [GFY]
One of the first things that were made was a Command Book so all the members could have access to teleport commands, without the need of giving them OP.
Currently, the Book has most the commands the server offers, together with all the teleports. It's also unique for everyone who has their own plot, allowing them manage it to their liking.
I will talk more about all the commands and the plot system in the future, by the way.
Well, the way you get the Book is by simply looking straight down and jumping once. Also, because we have new members from time to time being added to the Book, players who log into the server will always recieve a new one.
Making you recieve it is very simple.
We need a objective stat.jump, called book, to detect when a player jumps.
Firstly we only want the book to only be given once to a player, avoiding their inventory to be spammed, so if a player jumps and book goes to 1, we will reset it if the player has a written_book in their inventory titled "Command Book".
If the player's score hasn't been reset and they are looking down, all we need to do now is to give them the Command Book.
Now, to know a player has to receive it, I give them a score on a trigger objective. With that, not only they can get it by looking down and jumping, but also through the tellraw menu.
Oh, you can find the commands used here.
Some of the tricks used
Although this is a pretty simple system, I still wanted it to be as efficient as possible.
If you worked with Command Blocks before, you know lag can be a issue if you have multiple of them running at once, so having as little checks as you can will help avoid the problem.
For that, the only constant check we have is if a player has a score on book. Only then the rest of the checks will be executed.
The complication we find is when we want to execute the checks only when the clock finds a true result. We could, of course, use comparators, but it could break if two players would jump one right after the other, reseting the first and leaving the other with their score so the comparator would never turn off.
The solution? An Armour Stand (or an Effect Cloud).
We can execute at players with scores on book, who execute at an Armour Stand located at the command blocks a command to power them.
It's possible to power them on many ways, but the one I've been using a lot since 1.9 is to set an Impulse Command Block with the command /blockdata ~ ~ ~ {auto:0b} to {auto:1b}.
Setting an Impulse CB to auto:1b will power it like you'd to with a redstone signal. Setting it back to auto:0b will simply reset it. We can then link some Chain Command Blocks as we like to the Impulse one.
An Armour Stand used to mark the Command Blocks' position
The Tellraw Menu [GFY]
Going to a block, looking down and jumping, opening the Command Book and then using the command you want can sometimes be a little too much. So, for a faster access to some commands, I made the Tellraw Menu.
On MCS3.0, most of the commands from the Book will also be in the Menu, apart from the direct teleports to players and plots.
The way you access the Tellraw Menu is by looking straight down twice. Doing that will open a short list of commands that you can expand by clicking at [More Options].
The Tellraw Menu, expanded to show more options
Knowing when to show the Tellraw is also very straightfoward.
We will need a trigger objective, called menu. Then all we need is a series of events: the player looks down, menu gets set to 1; they look a little up, menu gets set to 2.
If they look down again, now with menu = 2, the Tellraw will be executed and the score will be set to 3 so the message doesn't repeat over and over.
To show more options, a trigger command will be in the Menu to set the score to 4. Another Tellraw will then be executed and the score will be reset back to 3.
Of course, we also set menu to 0 if the player looks back up.
Again, you can find the commands here.
Some of the tricks used
For the Tellraw Menu to work, the players need to have a score on the menu objective.
Normally, no player or entity starts with a score on any objective. We can use the command /scoreboard players add @a menu 0 to fix that easily.
Now that's pretty simple, but they key is actually when to use the command.
Having it on a clock is unecessary and it would only add lag. The best course of action is to use it only when a players joins the server. Nothing like a stat.leaveGame won't help.
We can detect when a player logs in or out of the game with a simple setup, having a clock testing for all players with a comparator to take its output. Because the comparator outputs a different signal depending of the command block's SuccessCount, it'll update everytime the amount of players online changes, even if it goes to more than 15.
Then all we need is to detect the comparator change, using a BUD, and we can use the command mentioned before.
This can also be used for many other functions, like an welcome message.
A clock testing for all players, connected to a BUD
The same system, now connected to an instant BUD to activate faster
Like the last time, thank you for reading and I hope you continue for the upcoming posts!
No comments:
Post a Comment