.

Discussion in 'Plugin Development' started by elementalgodz11, Nov 23, 2013.

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

    elementalgodz11

  2. Offline

    AoH_Ruthless

    elementalgodz11
    When a player uses /viper, add them to a HashMap. When they attack someone, if they are in the HashMap call the poison effect on the damaged entity.

    At the top of your code under your Arraylist, you want to use:

    Code:java
    1. HashMap<String, Boolean> viper = new HashMap<String, Boolean>();
    This will initialize your hashmap.

    Then, If a player uses /viper, use:
    This puts the player in your viper hashmap. You don't need to store it anywhere or any of that.

    Code:java
    1. viper.put(player.getName(), true);


    In the Event:

    Code:
    if(viper.containsKey(event.getPlayer().getName())) {
    // Poison Effect
    }
    It will check if a player is in the Viper HashMap and then if so, use your poison effect code.

    Then you can work out aesthetics and polish it to your liking.

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

    L33m4n123

    1. Check if the sender is instanceof Player.. Saves you alot of trouble if the command gets executed via IRC/Console for what ever reason
    2. I'd say use a List/Set rather than a Map but thats just my personal opinion
    3. http://lmgtfy.com/?q=hashset+java on how to use hashsets
    4. don't put the event within the onCommandMethod
     
  4. Offline

    AoH_Ruthless

    elementalgodz11
    Everything L33m4n123 said. But you pick whether you want to use a set or a hashmap, it's not too big of a difference.


    well the same way you check if a command sender is a player .. with an instanceof.

    elementalgodz11
    Fix your indentation so I can see the problem better. You should only need this:

    Code:java
    1. if(viper.containsKey(p.getName())) {


    I don't know why you are calling (Command)

    elementalgodz11
    My bad, use containsKey(d.getName());

    instead of getting a living entity, why not just use p.addPotionEffect ..... much, much easier.

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

    L33m4n123

    also please check first if the Entitys are instanceof Player. Because it will spam the console errors once a Player hits a Mob or vice versa or a mob hits a mob
     
  6. Offline

    AoH_Ruthless

    elementalgodz11
    Stacktrace?
    And are you sure you used /viper, first?

    elementalgodz11
    If it is a similar setup, I don't see why not. If it doesn't work you know where to ask for help :).

    elementalgodz11
    in a PlayerQuitEvent, get the player and use viper.remove(player.getName());

    elementalgodz11
    This tutorial may help you.


    elementalgodz11
    There shouldn't be a big difference.
    My mistake, I thought you wanted a random chance of adding the player to viper when they use the command.

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

    AoH_Ruthless

  8. Offline

    AoH_Ruthless

    elementalgodz11

    To call length (an integer), you have to use something like:
    Code:
    public void onViperHit(EntityDamageByEntityEvent e, int length) {
        //code goes here
        //somewhere in here you want use this.length = length;
    }
     
    
    That is just for length, you will have to do it for multiplier and chance as well, but call chance as a boolean instead of an integer.

    If viperhit is your only event of this nature (adding a random potion effect), then I think you are becoming way too involved with it. However this is a good way to go for multiple events of this nature.
     
  9. Offline

    SuperOmegaCow

  10. Offline

    Garris0n

    Almost every post in this section is either the same thing as 10 other posts before it or something so unique it's basically somebody asking how to code an entire plugin.
     
  11. Offline

    SuperOmegaCow

    Garris0n except for it was the same guy.
     
Thread Status:
Not open for further replies.

Share This Page