• Hey! Register here to create your account, engage with the community, and talk about what is new!

Block ownership

pablogameing4000

New member
Joined
Apr 3, 2022
Messages
7
Reaction score
1
So im trying to make a block building system and I want to have each block owned by a player, how would I start with making that?
 
Solution
An alternative to the solution @JustSticky posted would be to use a dictionary. To tag a block as owned by a player, you'd convert the location of the block into text. Then you'd put in the dictionary that text as a key, with the player's name/UUID as a value (I'd recommend UUID so that blocks aren't lost on name changes). Then when you want to check the ownership of a block, you get the value from the dictionary at key (target block location converted to text). If it doesn't exist, the block is unlocked. If it does exist, you can check if the value matches the current player.

This will result in better CPU performance than the list method, however you may need to use multiple dictionaries as there is a size limit (I think it's...

JustSticky

Well-known member
Overlord
Joined
Mar 4, 2021
Messages
77
Reaction score
43
When a player places a block, you can set that location to a SAVE variable called %default blocks (%default changes to whatever the player's username is. It would be read to the game as "<player's name> blocks". Ex. "JustSticky blocks" would be the variable for my blocks)

If you want other players to not be able to break any other player's blocks, you could do:
(Each paragraph is a block of code. Lines that end with "{" are telling you that the code inside of it would go inside that code block's pistons.)

Player Action > On Break
If Variable
> Contains > (put your SAVE variable "%default blocks" inside the chest) Target Block (from location values) {
Game Action > Destroy Block > (inside of chest) Target Block (from location values)​
}
Else {
Game Action > Cancel Event
}
 
Last edited:

Jeremaster

Owner
Owner
Joined
Aug 16, 2020
Messages
89
Reaction score
128
An alternative to the solution @JustSticky posted would be to use a dictionary. To tag a block as owned by a player, you'd convert the location of the block into text. Then you'd put in the dictionary that text as a key, with the player's name/UUID as a value (I'd recommend UUID so that blocks aren't lost on name changes). Then when you want to check the ownership of a block, you get the value from the dictionary at key (target block location converted to text). If it doesn't exist, the block is unlocked. If it does exist, you can check if the value matches the current player.

This will result in better CPU performance than the list method, however you may need to use multiple dictionaries as there is a size limit (I think it's 5,000 entries?)
 
Solution
Top Bottom