3

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
  • 4
    First off, you don't want testfor, you want execute. 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?
    – MrLemon
    Oct 22, 2015 at 14:59
  • No, i don't kill boat, but the people who sit there!
    – Cụ Rùa
    Oct 23, 2015 at 1:57

2 Answers 2

-2

try this command:
/testfor @p {Riding:{id:Boat}}

3

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]
8
  • I'm not using 1.9 yet as i need Optifine. Ths a lot for your care
    – Cụ Rùa
    Oct 23, 2015 at 1:58
  • Regarding 1.9: Riding doesn't work any more, but IIRC, a new RootVehicle tag was added to players instead. Also, there are 6 boats, not 5
    – MrLemon
    Oct 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 replacing remove with set.
    – MrLemon
    Oct 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.
    – SchoolBoy
    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ùa
    Oct 26, 2015 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .