Forumskeyboard_arrow_right Help keyboard_arrow_right Java Edition

Create Forum Thread
2

How do you make only one player allowed in a boat?

2 emeralds8 replies70 views
created 11/09/2019 2:11 pm by commander321
last reply 11/10/2019 8:32 am
So the other day I decided to add cars into my minecraft server that im working on. My idea was to retexture boats to look like cars. I have the cars but im having a problem. I dont want other players to get into other players cars. I tried to use some tag and scoreboard commands to make it so when someone buys a car it tags them and the car, then in a repeating command I test for if someone is in a car that isnt theirs. The problem is that you cant set a tag to a scoreboard vaue! Im on 1.14.4. Can someone help!
Posted by avatar
commander321
Level 1 : New Crafter
0

comment Login or register to post a reply.

8 replies

3
11/09/2019 3:08 pm
Level 41 : Master Robot
Bertiecrafter
You could use a hidden player on the scoreboard (simply a name starting with #, like #currentId). Then check for all players without an "init" tag and run a function. Make the function dish out an id using the scoreboard operation sub command, increase #currentId by one and give the player the "init" tag.

This way each player will get a unique id.

When a player purchases a "car" you could use the scoreboard operation command again to copy this value into the car entity. Then you could create a secondary dummy objective (e.g. id_diff) where you repeatedly store the players id and then subtract the boats id. If the result is not 0, the ids do not match up and somebody entered a boat that's not theirs.

Once you detected players being in wrong boats you could spawn a new boat, transfer the nbt using the data command and kill the old one, all at the players position. This would simulate the effect of being kicked out. You probably want to tp the old boat to the void instead of killing it, since it would create a boat item otherwise. The disadvantage of that is that anyone could click a boat that a player already is in to make the other player pop out.
It's more like a correction strategy instead of a prevention strategy, which usually results in side effects like these.

Now, for how to save the ids while placing/picking up the boat.... you have to figure that one out yourself.
1
11/09/2019 3:35 pmhistory
Level 1 : New Miner
commander321
Thanks, but im not the best at commands so could I have the commands I would need to do this please.
3
11/09/2019 3:53 pmhistory
Level 41 : Master Robot
Bertiecrafter
I'm sure you can figure them out yourself if you really want to :)

This certainly isn't something for beginners and if I would spend time creating all the commands I'm pretty sure you're going to be stuck at the next problem of storing information about the owner of a boat when it's broken/placed. Spend some time on it and if you really can't figure it out, maybe you should try something different in the meanwhile. It sucks, but from experience it's nice if that idea from ages ago pops back into your head one day and you are actually able to do it.

In my previous response I used quite technical terms, to make sure you understand the goal I set up for your own journey to the solution, let me summarize:

1. Give every player a unique id.
2. Copy that id to the boat the player owns.
3. Subtract the IDs. If the result is not 0 kick them out.
2
11/09/2019 7:03 pm
Level 1 : New Miner
commander321
Sooo, I got a little stuck on part 3. I used this command /execute if entity @a[nbt={RootVehicle:{Entity:{id:"minecraft:boat"}}}] unless score @e[type=boat,limit=1,sort=nearest] BoatId = @s Id run tp @s ~ ~1 ~2 and it dosent seem to work. I think something is wrong in the BoatId = @s Id because Im not quite sure if it is doing it as equal to or something else. Can you help me!
2
11/10/2019 3:49 amhistory
Level 41 : Master Robot
Bertiecrafter
Awesome, I completely forgot about the equality operator in the execute if score command. Way easier than what I would have done. I'm glad you decided to stick to your plan and figure this one out yourself.

In the command above, you forgot to set the executioner and the position.

Turn the "if entity" into "as" and put "at @s" right after the first statement. This way the @s selector will contain the player and sort=nearest actually makes sense. It should work after that assuming your nbt and tp command is correct.

Try to minimise the tp command though. Try to make it possible to be kicked out in a 1x1x2 space without taking damage. Maybe ~ ~0.1 ~ is enough?

Good job on being able to find alternative solutions after you got a focus for one. It's sometimes difficult to see other solutions and not bash your head against the wall until you get that one solution working.

If you're curious, @s currently has the Server as value and I think worldspawn as location if the command gets executed in a tick function.
1
11/10/2019 8:32 am
Level 1 : New Miner
commander321
YES! IT WORKED! Thank you so much! I do have to fix the first step because when my friend tested it he din't get an Id. Other than that everything is working! Can't wait until the next time that player Id comes handy!
1
11/09/2019 5:39 pm
Level 1 : New Miner
commander321
Ok step 2 is done now and all working! Btw the player will not have to destroy or place the cars, there just going to stay where they are until the player comes back and uses it again. Anyway time for step 3!
1
11/09/2019 4:30 pm
Level 1 : New Miner
commander321
Alright, just finished step 1! just waiting fir my friend to come on to test it. Then im gona work on step 2!

Planet Minecraft

Browse

Website

© 2010 - 2019
www.planetminecraft.com

Welcome