'Electrocuting' player when interacting with activated redstone

Discussion in 'Plugin Development' started by AppleMen, Jul 3, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    AppleMen

    Hello all,

    I want to make a plugin that electrocutes you when interacting with activated redstone. So when you interact with it, it should 'hit' you every 1 second. Interacting should not mean that you left or right click it.

    My question is, how can I check if a player stands in the redstone item 'block'. And how can I 'hit' the player just once every second?

    Thanks!
     
  2. Offline

    bennie3211

    get the location, and check if the block at that location is redstone
     
  3. Offline

    AoH_Ruthless

    AppleMen
    Get the block at players location, use BlockFace to find the relative block under it. Or you could just subtract one from the player's y on Player#getLocation().

    Then, use BukkitRunnable scheduling to run a timer every second (20 ticks) which damages the player. But also in the timer you will want to keep checking if the player is on the redstone, and if not, cancel the timer.
     
  4. Offline

    AppleMen

    How would I 'hit' a player then?
     
  5. Offline

    AoH_Ruthless

    AppleMen
    You could change their velocity to produce a knockback effect, if I am understanding you correctly.
     
  6. Offline

    AppleMen

    Which velocity should I change then? Like X, Y, Z? What I just want is like a hit exactly like you get if a player hits you.
     
  7. Offline

    AoH_Ruthless

    AppleMen
    You could get the player's velocity (their #getLocation()#getDirection()) and multiply it by a negative float/int value. You might also want to normalize the y value of their vector so you produce a knockback. Toy around with it.
     
  8. Offline

    AppleMen

    I'm a little bit confused. What I just did what this just to try:

    Code:java
    1. @EventHandler
    2. public void Interact(PlayerInteractEvent e) {
    3. Player player = e.getPlayer();
    4. Block getBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
    5.  
    6. if (getBlock.equals(Material.REDSTONE_TORCH_ON)) {
    7. player.sendMessage(ChatColor.RED + "AAHHHH JE STAAT ONDER STROOM GEK!");
    8. }
    9.  
    10. }


    But that didn't work obviously.
     
  9. Offline

    AoH_Ruthless

    AppleMen
    First you would want to get the player's vector.
    Code:
    Vector dir = player.getLocation().getDirection();
    Then, perhaps you could set the player's velocity to a negative rendition of this.
    Code:
    Vector newDirection = dir.multiply(-1);
    You might want to normalize it to produce a knockback effect. I use 0.3 to emulate regular player hits
    Code:
    player.setVelocity(newDirection.normalize().setY(0.3);
    I don't know if you actually want to produce a knockback effect or not; you never really clarified what you mean by "hit" a player.
     
  10. Offline

    AppleMen

    Well exactly like you said a knockback. When you hit someone with a sword, you hear a hit sound and lose 0.5 of your heart.

    But I still can't get the interaction itself working :/
     
  11. Offline

    ulsa

    if you want to knock him back from where he is facing "so on stepping redstone he will get knocked back of it" you can use @AoH_Ruthless 's way
    else you can just detect the block and get player name and damage him or even use lightnings
     
Thread Status:
Not open for further replies.

Share This Page