Toggle flight

Discussion in 'Plugin Development' started by the_merciless, Mar 5, 2013.

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

    the_merciless

    How can I get if the player hits the space bar twice, as if you were trying to fly. The obvious answer is PlayerToggleFlightEvent, but that only fires if the player is in fly mode.
     
  2. Offline

    RainoBoy97

    You cant toggle flight by hitting spacebar twice without being in fly mode :p
     
  3. Offline

    the_merciless

    You just repeated what I already said!
     
  4. Try this

    Code:java
    1.  
    2. if(player.)//Do your if statement or what not.
    3. player.setFlying(true);
    4. [/syntax=java]
    5. Is that what you are looking for? :eek:
    6.  
    7. EDIT: Wait, I reread what you where asking... Woops. Lol
     
  5. Offline

    RainoBoy97

    I dont think you can check if the player hits space twice.
     
  6. Offline

    the_merciless

    To explain it a bit better, what im trying to do, is allow players to fly for a short period of time. then stop them flying for a certain amount of time, then allow again, and so on. I can achieve this if i have the player set as allowed to fly, but fall damage is disabled.

    So i either need to be able to toggle fly mode with a double tap on space bar, or enable fall damage whilst in fly mode.

    The second option may be easier, how could i toggle fall damage on/off
     
  7. Offline

    minoneer

    You can get this through the EntityDamageEvent. Just check if the entity is one of those players and if the damage cause ist FALL
     
  8. Offline

    RainoBoy97

    player.setAllowFlight(true);
    player.setFlying(true);

    and

    player.setAllowFlight(false);
    player.setFlying(false);
     
  9. Offline

    the_merciless

    I cant use player.setAllowFlight(true) if the event doesnt fire.
     
  10. Offline

    RainoBoy97

    It will make them able to doubletap space and make them fly.
     
  11. Offline

    ZeusAllMighty11 Retired Staff

  12. Offline

    the_merciless

    Yes, but they will not recieve fall damage whilst not flying. What im trying to do is:

    When player double taps, set them as allowed to fly.

    Nope. Im making a jet pack.

    I have it working perfectly except for fall damage wont work as i hope.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  13. Offline

    RainoBoy97

    Add them to a Map, if they are in map, cancel fall damage and remove them
     
    ZeusAllMighty11 likes this.
  14. Offline

    minoneer



    If so, just cancle the event
     
  15. Offline

    the_merciless


    You cant just cancel fall damage. (Or can you and i just couldnt find it?)

    minoneer
    My problem is they are not receiving damage, so why would entityDamageEvent fire?
     
  16. Offline

    minoneer

    you can cancle pretty much any event, so why not fall damage?

    I thought they were receiving fall damage which you wanted to stop? Or did I missinterpret that?
     
  17. Offline

    the_merciless

    Other way round. They are in fly mode so dont recieve fall, damage. i want to enable fall damage, (except when thier fly time runs out and they fall to the ground.)

    Ooh yeah i just found player.setNoDamageTicks, this could work!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  18. Offline

    ZeusAllMighty11 Retired Staff

    the_merciless

    What if they get shot or exploded in mid air ? INVINCIBILITY
     
  19. Offline

    the_merciless

    I think i can avoid that, let me quickly try this and see. I assume if i set ticks to 0 they will receive damage?
     
  20. Offline

    minoneer

    Oh, I see. Then I would do it this way:

    - setAllowFlight(true) for those player who are allowed to use your "jetpack".
    - Listen to the PlayerToggleFlyEvent. When someone enables fly
    - start a delayed task setting setFlying(false) and setAllowFlight(false)
    - start a cooldown and after that, setAllowFlight(true) again.
     
  21. Offline

    the_merciless

    That is exactly what i already have, problem is when the cooldown is over they will be in fly mode, hence recieve no damage from falling.
     
  22. Offline

    iWareWolf

  23. Offline

    chasechocolate

    XlegitXcrazymanX Off-topic, but end java code with:
    Code:
    [/syntax]
    (had to put it in code form, it will mess everything up if I don't... :p
     
  24. Offline

    the_merciless

    We have been over this. The players are not receiving damage so that event won't fire.

    I thought it was only fall damage they are protected from. But no, it's all types of damage. Looks like I need to use a playerMoveEvent which is what I was trying to avoid.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  25. Offline

    Digi

    I guess your delay is really short that it re-enables fly mid-air ? I'm kinda confused.

    What is your goal though, do you want to disable fall damage or not ? If yes, in what situations ?
     
  26. Offline

    the_merciless

    I want players to receive damage whilst in fly mode.

    Players should be allowed to fly for 3 seconds. Then fall to ground and not receive fall damage. Then there is a 20 second delay before they can fly again. Yet they should still receive damage as normal.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  27. Offline

    Digi

    the_merciless
    Then it should be simple...
    - allow fly true
    - monitor turning on flight and start the countdown of 3 seconds
    - optionally monitor turning off flight to cancel the countdown (the 3second one) prematurely
    - once the countdown cancels, set allow fly false and force disable fly on player and start the cooldown of 20 seconds
    - when the 20 second cooldown ends, go back to allow fly true :p

    Disabling allow flight in mid-air might give players a temporary fall damage immunity by default, but if it doesn't then you should be able to cancel it using EntityDamageEvent.

    Also remember to print messages with checked values so you are 100% sure that it triggers and it gives you what you need.

    If all fails post your current code and the behaviour you need to get rid of.
     
  28. Offline

    the_merciless

    This is how I have it. But when I re enable fly, they are able to run around without getting hurt. Also I want them to receive damage whilst actually flying.

    Like I said I have the jet pack working fine. It's just player damage is not taken

    This thread is getting confusing. I will post a new thread tonight showing my code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  29. Offline

    Digi

    Oh now I understand, yeah that's quite a dilema... I guess you'd have to use PlayerMoveEvent to monitor for jumping, like you said.
     
  30. Offline

    minoneer

    I have a maybe not so nice, but relatively easy suggestion: Don't use flymode at all. Instead, use the sneak key (which is easy to detect) and if they toggle that, set their speed and moving direction. That way you could even set it to only move them up when the button is pressed, and once released, they fall back to the ground (just like you would imagine a real jetpack). Maybe even have them sneak and then jump to launch from ground; that way regular sneak would still remain usefull.
     
Thread Status:
Not open for further replies.

Share This Page