4

I have a system where flipping a lever in a room will teleport the player, but I need a scoreboard to test who's actually flipped a lever to run the commands on. If the triggered commands after it only affected '@p' then the person standing closest to the lever would be affected even if they weren't the one who activated it. I tried to use a scoreboard for minecraft.use:minecraft.lever, but that's only for placing levers, not actually activating them. I need some other way to detect which player actually activated the lever.

4
  • 1
    There is no scoreboard type for this. I'm not sure if you can completely reliably track it. Apr 22 '19 at 16:24
  • 1
    I guess you could use click detection and then raytracing to determine if there is a lever in the direction the player looked, but that's overkill, you would basically have to reprogram the entire "flick lever" mechanic with command blocks. Are there other ways that you could make the player do something, instead of a lever? Could you make them stand on a pressure plate, drop an item, throw a snowball, equip a helmet, etc.? Those are all much easier to track. Apr 22 '19 at 16:35
  • 1
    I guess I could use armor stands holding items to form a switch-like figure and then have a detector stand that's punched as an activation, but it seems like a 'using levers' criteria would be a basic criteria... Apr 22 '19 at 17:15
  • 1
    I agree, that would be a good feature and you can suggest it by pressing the "leave feedback" button in the game's menu. But for now you probably want to find a different solution, right? Apr 22 '19 at 20:54
1

You don't need a scoreboard in order to actually do it.
1. Place the lever on a block.
2. Place a command block under or behind that block.
3. Set the command to /tp @p <destination>

Personally, I'd use a button, so that you can just press the button and not have to worry about the next person who comes into the room, but it's up to you. Of course, there is the off-chance that someone will be in front of you when you press the lever or button, but if that ever happens, you can just press the button again.

Unfortunately, /tp @a[scores={lever=1..}] <destination> will not work because there are no criteria for flipping a lever or pushing a button, which means that in order to make it work you'd have to do /scoreboard players add @p lever 1 and /tp @a[scores={lever=1..}] <destination>, but then it's the exact same as the /tp @p command and is ultimately just more complex and is not needed.

Edit: The only problem is that the closest person will be teleported even if they didn't flip the lever, however, there is no workaround for that. You'll just have to make sure that the second room is at least 4 blocks away, and hope that no one is standing closer to the lever than the person who flips it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.