Player Set health event?

Discussion in 'Plugin Development' started by Insidiea, Jul 31, 2011.

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

    Insidiea

    Hey, I'm tired of some of my users just killing them selves to get full health, I've thought about making it where you loose money on death, but thats a little too hardcore for me, what I want is when you respawn, your health is at 1 or half a heart. Could anyone write up a small plugin that does that, or can help me write it, I did some LUA coding in garrysmod, heres a small little sketch of what I worked up, It's my first attempt at coding so be lenient :p.

    Code:
    import org.bukkit.event.player.PlayerRespawnEvent;
    public class PlayerRespawnEvent; //I have aboslutley no idea what this does, but I think i need it
    Respawn respawn = PlayerRespawnEvent; //For simplicity?
    if(Respawn)
    {Player.sethealth(1)}; //Now i couldn't find the health set event So i just used a made up one , anyone can help on that?
    //I realize the code is lacking alot, but this is my first time.
    
     
  2. Offline

    wwsean08

    Gimme a couple hours and I can write something up for you (mostly because i gotta step away for a little bit). Once it's done i'll send you the source and the jar itself so you can see what's happening.
     
  3. Offline

    kaiser_czar

    I'd help ya out, but I'm a hair busy. Here's the path you want to take:
    Register a respawn event with a player listener.
    Overwrite the onPlayerRespawn method to do this:
    On the respawn event, do event.getPlayer();
    Once you get the player object, simply do player.setHealth(1);

    You were really close, actually.
     
  4. Offline

    Insidiea

    Thanks so much, if its not too much trouble, could you put a few comments explaining what does what.

    Even though hes making the plugin, I still want to learn.
    Could you give me a example of a player listener?

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

    wwsean08

    yeah, no problem, it's not quite as straight forward as i assumed because for some reason it is not letting me set the health, or damage the user in the player respawn event.
     
  6. Offline

    Insidiea

    Okay, thanks so much, just PM me the plugin with source once you got it all sorted out, once again thanks.
     
  7. Offline

    DrBowe

    Maybe place the action in a delayed scheduler task? It's possible that there's a direct protection for x ticks whenever a player spawns.
     
  8. Offline

    wwsean08

    thats a good idea, i'm going to look into that (i've never been good with threads lol).

    Ok I just finished thanks to the suggestion by @DrBoweNur heres a link to the plugin itself (you can adjust how much health they spawn with in the config.yml, between 1 and 20 because of the half hearts), it only accepts integers, which is why it's 1 to 20, you could set it to 0 but then they would just be in a death loop...i digress). I will post the source in about 20-30 minutes once I comment it.

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

    Insidiea

    Thanks so much, and DrBoweNur too!
     
  10. Offline

    wwsean08

  11. Offline

    DrBowe

    @wwsean08
    Glad that worked!
    I was still kind of shocked that no plugins like this has been made before, and I guess that that was the reason why. Oh well. :p
     
  12. Offline

    wwsean08

    i just updated it (putting in the checks that i thought of while putting in the comments), so if you'd like to download the new version it's the same link

    and @DrBoweNur a friend of mine reminded me that MultiInv did a similar thing (except it saves your health in each individual world), so i had that to go off of at least
     
Thread Status:
Not open for further replies.

Share This Page