Solved Spawn Rates

Discussion in 'Plugin Development' started by x_Jake_s, Aug 6, 2016.

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

    x_Jake_s

    So I am currently in creation of a Pokémon plugin for all spigot/craftbukkit servers with no excess jar files needed. So far I have successfully created 5 Pokémon: 2 Normal, 1 Rare, 1 Epic, and 1 Legendary. Now I have kind of set up a method that takes a random and check its output numbers which in theory works. I haven't been able to test it but I'm hoping that a couple of you guys can look it over and tell me if there is a better method of doing it or if I have made a massive mistake.

    Extra Info (open)
    To go into further detail this method is called in my main class through a repeated runnable that every 2 minutes it runs the function and spawns a new Pokémon in a world of the owners choosing based on the spawn point of the world, so the world will need to be created based off the plugins needs. The spawn function y value is set to 50 so that when they are not spawned they are spawned inside of a mountain or hill.


    Code:
    package com.v0id.pokemon;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.EntityType;
    
    import com.v0id.pokemon.entities.pokemon.Pokemon;
    
    public class Rarity {
    
        public static ArrayList<EntityType> pokemonTypesNormal = new ArrayList<EntityType>();
        public static ArrayList<EntityType> pokemonTypesRare = new ArrayList<EntityType>();
        public static ArrayList<EntityType> pokemonTypesEpic = new ArrayList<EntityType>();
        public static ArrayList<EntityType> pokemonTypesLegendary = new ArrayList<EntityType>();
    
        static int xNormal = PokemonMain.getRandom(1, 50);
        static int zNormal = PokemonMain.getRandom(1, 50);
        static int xRare = PokemonMain.getRandom(25, 100);
        static int zRare = PokemonMain.getRandom(25, 100);
        static int xEpic = PokemonMain.getRandom(50, 150);
        static int zEpic = PokemonMain.getRandom(50, 150);
        static int xLegendary = PokemonMain.getRandom(75, 200);
        static int zLegendary = PokemonMain.getRandom(75, 200);
    
        public static Location locN = Bukkit.getServer().getWorld("World").getSpawnLocation().add(xNormal, 50, zNormal);
        public static Location locR = Bukkit.getServer().getWorld("World").getSpawnLocation().add(xRare, 50, zRare);
        public static Location locE = Bukkit.getServer().getWorld("World").getSpawnLocation().add(xEpic, 50, zEpic);
        public static Location locL = Bukkit.getServer().getWorld("World").getSpawnLocation().add(xLegendary, 50, zLegendary);
    
        public static void spawnPokemon() {
            // Spawning Normal/Common pokemon
            if (PokemonMain.getRandom(1, 1000) >= 300) {
                for (EntityType type : Rarity.pokemonTypesNormal) {
                    Pokemon.spawn(Bukkit.getServer().getWorld("World"), locN, type).setInvulnerable(true);
                }
                // Spawning Rare/Uncommon pokemon
            } else if ((PokemonMain.getRandom(1, 1000) >= 150) && (PokemonMain.getRandom(1, 1000) <= 299)) {
                for (EntityType type : Rarity.pokemonTypesRare) {
                    Pokemon.spawn(Bukkit.getServer().getWorld("World"), locR, type).setInvulnerable(true);
                }
                // Spawning Epic pokemon
            } else if ((PokemonMain.getRandom(1, 1000) >= 50) && (PokemonMain.getRandom(1, 1000) <= 149)) {
                for (EntityType type : Rarity.pokemonTypesEpic) {
                    Pokemon.spawn(Bukkit.getServer().getWorld("World"), locE, type).setInvulnerable(true);
                }
                // Spawning Legendary pokemon
            } else if ((PokemonMain.getRandom(1, 1000) > 0) && (PokemonMain.getRandom(1, 1000) <= 49)) {
                for (EntityType type : Rarity.pokemonTypesLegendary) {
                    Pokemon.spawn(Bukkit.getServer().getWorld("World"), locL, type).setInvulnerable(true);
                }
            }
        }
    }
    My onEnable() containing the function.

    Code:
        public void onEnable() {
            this.log.log(Level.INFO, "Enabled Pokemon v" + pdf.getVersion());
    
            registerCommands();
            registerConfig();
            registerEvents();
    
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    Rarity.spawnPokemon();
                }
            }, 0, 2400L);
    
        }
     
  2. Offline

    ArsenArsen

    Just use a mob spawn event, check if it's not from a spawner or egg, and if it's not, and a random int between 0 and 100 is less than some percent, cancel the event and spawn a Pikachu.
     
  3. Offline

    x_Jake_s

    could you show a brief example code of how I could use this to spawn multiple pokemon of different rarities you can use just basic names and stuff I just want to see an example of it being setup
     
  4. @x_Jake_s Omg.... Stop the static abuse!!! Please!!! Also use Map instead of tons of Lists, do you even need like any of these global variables? Seems to me they can easily be gotten in a method with no need to make them global. Also let Bukkit log onEnable, and why do you have a variable for getLogger?!? Why not just use getLogger?
     
Thread Status:
Not open for further replies.

Share This Page