Potion Effect Help!!!

Discussion in 'Plugin Development' started by bartboy8, Jun 10, 2012.

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

    bartboy8

    I want to basically replace the potion effect of a weakness potion. So when they drink it they get super jump. This is what I have so far:
    Code:
    if (player2.hasPotionEffect(PotionEffectType.WEAKNESS) == true)
        {
            player2.removePotionEffect(PotionEffectType.WEAKNESS);
            player2.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1200, 5));
        }
        }
     
  2. Offline

    apenaroks

    Alright, so... whats the problem here?? Are you running into an error or you just aren't sure how to go about this sort of thing? The more information you can post about what your question and problem actually is, the better the people in this forum can help you!
     
  3. Offline

    bartboy8

    Well, I need to know how to make it so when the player drinks a weakness potion it will remove the effect and replace it with Super jump.
    apenaroks
     
  4. Offline

    Suprem20

    This should remove the potion effect on the server side, afterwards on the client side by adding a 0 second effect and add the real effect.
     
  5. Offline

    bartboy8

    So how would I do that?
     
  6. Offline

    Suprem20

    Edited your code in the post above :p
     
  7. Offline

    bartboy8

    Ok, I will test!

    It didn't work... but I am not sure if I am using it right.
    Code:
        public void Potion(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
        if (player.hasPotionEffect(PotionEffectType.WEAKNESS))
        {
            //Remove potion effect on the server side
            player.removePotionEffect(PotionEffectType.WEAKNESS);
            //Remove it for the client
            player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 0, 0));
            //Add the new effect
            player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1200, 5));
        }
        }
    This is how I was using it

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

    Suprem20

  9. Offline

    bartboy8

    Sorry, I thought this was a support section for people that aren't great at coding.
     
  10. Offline

    Suprem20

    It is but you cannot simply post for help copy and paste... I could code the thing for you but you wouldn't learn anything.
     
  11. Offline

    bartboy8

    How am I supposed to learn if no-one can teach me. I am simply asking for help on this one thing. I already learn't how to do countless other things in coding. I just have no idea where to put this code.

    I know I could use it with a command but I don't want to.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
    ZeusAllMighty11 likes this.
  12. Offline

    Suprem20

    Well then, how do you want to use it? Player move event? Player damage event? Player join event?
     
  13. Offline

    bartboy8

    Player move event. I guess that would be most effective because usually after they take the potion they will move.
     
  14. Offline

    Suprem20

    Oh, sorry, I understand now... Well, you could create a new task which would run each "x" minutes, checking if the player has the weakness potion effect and if he does not, giving him a speed potion effect. (Correct me on this if I am wrong please)
     
  15. Offline

    bartboy8

    Almost correct, what I intend to do is basically take away the effects of a weakness potion when the player takes it. Then apply the jumping potion. I know I could check every second but would that lag the server?
     
  16. Offline

    Suprem20

    It would. I'm not too good at coding so perhaps someone else can guide you..
     
  17. Offline

    bartboy8

    Ok, thanks anyway.

    1 more question... Do you have any idea how to run a loop for checking the potion effects?

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

    Suprem20

    I don't really know how to get when the player consumes the potion... If you ran a command you change the weakness potion effect into a jump effect then you could run a task or loop.
     
  19. Offline

    bartboy8

    ok thanks!
     
  20. Offline

    ZeusAllMighty11 Retired Staff

    Suprem20


    Don't think that anyone in this post was really being too 'helpful' aside from the very first few posts. Neither is this post, but I'd like to get my word in.
    This is the Plugin Development Forum, where developers of all experiences are allowed to ask questions, elaborate on issues, and squash bugs. There is no need to call someone a 'COPYPASTA' or anything of the sort. Sometimes it's difficult for people to see what a true problem is. Even in reality, some people have more issues than others when solving problems. It all takes time, and just because this original poster didn't understand the basic concept of EventHandlers and Methods, doesn't mean he wanted you to literally and directly copy and paste some potential-plugin code.

    Back on topic, I think what you'll want to do is basically:
    -Run a scheduler to check every X ticks if a player drank a weakness potion
    -Remove the client AND server side effects of the potion
    -Add in the highjump potion or whatever effect you wanted.

    Make sure you know how to use schedulers. http://wiki.bukkit.org/Scheduler_Programming
     
    bartboy8 likes this.
  21. Offline

    bartboy8

    Thanks a ton! Also your top paragraph should be posted on the top of the Plugin Development Page.

    I did what you noted. But in order for it to recognize player I have to put CommandSender sender in somewhere. I have no idea where I could put it... any help?
    Code:
        plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
            public void run() {
                Player player = (Player) sender;
                if (player.hasPotionEffect(PotionEffectType.WEAKNESS))
                {
                   
                    //Remove potion effect on the server side
                    player.removePotionEffect(PotionEffectType.WEAKNESS);
                    //Remove it for the client
                    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 0, 0));
                    //Add the new effect
                    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1200, 5));
                }
            }
            }, 60L);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
    ZeusAllMighty11 likes this.
  22. Offline

    ZeusAllMighty11 Retired Staff

    Instead of getting a single player and using a Boolean CommandSender, try getting all online players and checking to see how has the effects
    bartboy8
     
    bartboy8 and Suprem20 like this.
  23. Offline

    bartboy8

    @r0306 Digi I was wondering if you could provide any advice for me. ZeusAllMighty11 told me your really smart :) So I was wondering if you could provide any help?
     
  24. Offline

    ZeusAllMighty11 Retired Staff

    Another thing I noticed, you didn't actually remove the effect from the client. You added the jump to the client, but didn't remove it.
     
  25. Offline

    bartboy8

    I did after I posted. I noticed that myself. That didn't change anything. Is there anyway I would activate it on a PlayerMoveEvent.
     
  26. Offline

    ZeusAllMighty11 Retired Staff

    Yes, but if you have many players in the server it can be really bad. It checks, like, every tick if a player is moving by gertting ALL ONLINE PLAYERS (too D; ), and everytime they move it will execute this.

    But something like:

    public void onPlayerMoveEvent(PlayerMoveEvent e){
    if player has potion effect X{
    remove effect from client;
    remove effect from server;
    add effect you want;
    }
    }
     
  27. Offline

    bartboy8

    Thanks!

    Still didn't work... do you have skype... or something like that (AIM) that I can talk to you on. That way I could get this problem fixed a lot faster lol

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

    hammale

    Hmm that would work but its gonna be killer on the server. Couldn't u just use a player interact event and listen for right clicking?
     
  29. Offline

    ZeusAllMighty11 Retired Staff

    Ask him, not me. lol he's the one who wants to use player move event. :p
     
  30. Offline

    bartboy8

    No, it doesn't really matter to me... More like whatever works.
     
Thread Status:
Not open for further replies.

Share This Page