I Need Help! How To Make RPG Plugin Player Classes

Discussion in 'Spigot Plugin Development' started by ThestralMoon, Jun 29, 2018.

  1. Hello people on spigot,

    I'm in need of assistance and knowledge on how to make the player classes you find in RPG plugins such as Heroes and LegendQuest RPG.

    I know how to make all those cool skills those classes have and the levelling system, I just need to know how I will make classes for those skills, and create a value "mana" or magic the player has and how much mana the player consumes for using that skill.
     
    • Agree Agree x 1
  2. Create a new Java class and call it "ClassManager" or something like that.

    1. Start off by creating a few variables for the ClassManager class.

    Some basic variables that I thought of were mana amount, your mana bar, the player who is using the class, and the class type (the knight, healer, mage, whatever.

    Code (Text):
    private ClassType classType; // this is an enum, which will be at the bottom of my post
    private BossBar manaBar;
    private double mana;
    private Player player;
    2. Make the constructor.

    You need to define your variables here.
    Your mana bar should be a new boss bar, your player should be the player specified in the constructor arguments, and the mana should be 1.
    Your mana will range from 0 to 1, 1 being the highest and 0 being the lowest, then update your boss bar to show your mana amount and add the player to the boss bar, so they can see it.

    Code (Text):
    public ClassManager(Player player) {
        this.manaBar = Bukkit.createBossBar("Mana Bar", BarColor.BLUE, BarStyle.SEGMENTED_10);
        this.player = player;
        this.mana = 1;

        manaBar.setProgress(mana);
        manaBar.addPlayer(player);
    }
    3. Add some getters and setters to make it easier to use your variables.

    4. The ability method

    You now want to create your ability method.

    The basic ability which I have written below method is as simple as checking if you have over 0.5 mana, then if you do, taking 0.5 mana, updating the boss bar, then running your ability code.

    Code (Text):
    public void useAbility() {
        if (getMana() > 0.5) {
            setMana(getMana() - 0.5);
            getManaBar().setProgress(getMana());
            // do the ability stuff here
        }
    }
    5. You will also want to let the player's mana naturally regenerate, so create a task that repeats every few seconds that recovers, for example, 0.1 mana, every time it runs.

    6. Just create an enum at the bottom of your class that holds each RPG class, separating each of them with commas:
    Code (Text):
    enum ClassType {
    KNIGHT, MAGE, HEALER
    }
    7. Add different abilities for each class.

    Go back to that useAbility method, and make a switch case statement:

    Code (Text):
    public void useAbility() {
    if (getClassType() == null) return; // stop running the code if the player hasn't picked a class yet.
    switch (getClassType()) {
    case KNIGHT:
        if (getMana() > 0.5) {
            setMana(getMana() - 0.5);
            getManaBar().setProgress(getMana());
            // do the knight's ability stuff here
        }
    case HEALER:
        if (getMana() > 0.3) {
            setMana(getMana() - 0.3);
            getManaBar().setProgress(getMana());
            // do the healer's ability stuff here
        }
    case MAGE:
        if (getMana() > 0.6) {
            setMana(getMana() - 0.6);
            getManaBar().setProgress(getMana());
            // do the mage's ability stuff here
        }
    }
    8. Actually using this code.

    On the player join event, run the following code:
    Code (Text):
    ClassManager classManager = new ClassManager(event.getPlayer());
    Now you need to ask the player what class they want to be, through a command or GUI, it doesn't matter.
    You should then add the ClassManager instance to a HashMap or the plugin config using the player/player's UUID as the key, so you can retrieve it later.

    Once they have picked, retrieve the player's ClassManager instance from the HashMap and run
    Code (Text):
    classManager.setClass(ClassType.<whatever they chose>);

    I hope that helped, good luck with your plugin.
     
    #2 FloThePony, Jun 29, 2018
    Last edited: Jun 29, 2018
    • Winner Winner x 3
    • Informative Informative x 3
    • Agree Agree x 1
  3. OMG!
    THANK YOU SO SO MUCH! :D

    I'll try doing what you said, thanks for the quick reply and explaining me how it works, thank you :D You made my day :D
     
    • Friendly Friendly x 1
  4. @FloThePony

    Quick question if you don't mind.
    Is there another way to show a visual mana bar instead of using the bossbar route because I'm currently using the bossbar as a means of showing my server-related alerts and news on my server. So is there another way I can create the mana bar?
     
    • Funny Funny x 1
  5. There is.
    You can use the action bar.

    You use the action bar using
    Code (Text):
    player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder("message here").color(ChatColor).create());
    So you could replace the boss bar with a simple
    Code (Text):
    player.spigot().sendMessage(ChatMessageType.ACTION_BAR,
    new ComponentBuilder(String.valueOf(0.5 * 100) + "/100").color(net.md_5.bungee.api.ChatColor.AQUA).create());
    and put it in a loop or something to make sure it always stays on the screen of the player.

    (I multiplied it by 100 just because having 50/100 mana left looks nicer than 0.5/1 mana.
     
    #5 FloThePony, Jun 29, 2018
    Last edited: Jun 29, 2018
    • Like Like x 1
  6. OMG! Thank you so much once again :D Hope you have a great day! :D
     
  7. Same old flo ;) maybe you should write his plugin
     
    • Friendly Friendly x 1
  8. Just a heads up, you can have multiple boss bars
     
    • Agree Agree x 1
  9. I find that your screen always looks super cluttered with more than one boss bar, but that's just my opinion.
     
  10. ThestralMoon this will be a nice plugin of yours! (I meant FloThePony's plugin)
     
  11. Bravo, you're a big help, you're totally not being a douche.
     
    • Agree Agree x 3
    • Funny Funny x 1
  12. Probably learning Java, how inheritance and abstract classes work would do you wonders here.


    Sent from my iPhone using Tapatalk
     
    • Agree Agree x 1
    • Optimistic Optimistic x 1