I'm trying to prevent players from getting in boats. I'm thinking of a /testfor
command attached with a clock that triggers a kill command. The thing is that I don't know how to write that /testfor
command. I have searched google, but nothing relevant appears. Help me please!
2 Answers
One thing you could do is make an invisible armour stand ride any boats in the world, this would stop players being able to get in them. (Don't necessarily need to be armour stands, but armour stands don't emit particles when invisible and cannot be interacted with.)
Another thing you can do is set a scoreboard for riding a boat as so:
/scoreboard objectives add Riding dummy
Clock:
/scoreboard players set @a[type=Player] Riding 1
/scoreboard players set @a[type=Player] Riding 0 {Riding:{id:Boat}}
/kill @a[score_Riding=0]
This will kill all Players with Riding score of 0, which will only happen if they are riding a boat. The commands that need to be clocked must be clocked in that order. They can be activated at once, but ensure that they run in that order. Command blocks that are activated on the same tick are executed in the order lowest x to highest x, lowest y to highest y, lowest z to highest z.
Note: In 1.9, the Riding
tag was removed in favor of Passengers
. For players, RootVehicle:{Entity:{id:Boat}}
should work. You will have to clock the second command in the clock section 5 more times for each of the boat types. You can look up entity ID's for these on Google, you should find them.
Note 2:
/scoreboard players remove @a[type=Player] Riding 1
This also works for first clock command if you set last clock command to
/kill @a[score_Riding_min=0]
-
-
Regarding 1.9:
Riding
doesn't work any more, but IIRC, a newRootVehicle
tag was added to players instead. Also, there are 6 boats, not 5– MrLemonOct 23, 2015 at 16:15 -
There is a mistake in the commands as well. The score is either -1 or 0,
score_riding=0
will be true for everyone! I suggest replacingremove
withset
.– MrLemonOct 23, 2015 at 16:20 -
@MrLemon Although, because remove 1 is being executed first, no one will have a score of 0 when killing, unless they are riding a boat. Also, edited to make the number of boats 5 more. Oct 23, 2015 at 18:01
-
ok so will anything need to be changed if i have like 60 boats with 2 players spam-right-click them?– Cụ RùaOct 26, 2015 at 13:16
testfor
, you wantexecute
. Otherwise, you'll have no way to act on or even near the specific player triggering the testfor. Secondly, is there a reason not to just kill every boat?