Custom Mobspawning

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

synccoin

Member
Mar 13, 2022
4
0
1
24
So uh, I wanted to do custom mobs using the on-spawn event and then modifying them with leather armor and stuff and the mobspawning is ABSURD. There are like 50-100 mobs in every chunk when using that skript, does anyone know how to fix that? (skript 2.6.1, skquery 4.1.5, 1.17.1)


Code:
function setarmor(e: entity, wh: text):
    if {_wh} is "leather":
        set {_e}'s helmet to leather helmet
        set {_e}'s chestplate to leather chestplate
        set {_e}'s leggings to leather leggings
        set {_e}'s boots to leather boots


on spawn:
    if "%entity%" is "zombie":
        set {mobname} to "Zombie"
    if "%entity%" is "skeleton":
        set {mobname} to "Skeleton"
    if "%entity%" is "spider":
        set {mobname} to "Spider"
    if "%entity%" is "creeper":
        set {mobname} to "Creeper"
    if {mobname} is set:
        chance of 80%:
            set event-entity's name to "&7%{mobname}%"
            set event-entity's tool to wooden axe of sharpness 1
            chance of 80%:
                set event-entity's tool to iron shovel
            chance of 50%:
                set event-entity's tool to iron pickaxe
            chance of 20%:
                set event-entity's tool to stone axe
            setarmor(event-entity, "leather")
            delete {mobname}
            stop
        chance of 50%:
            set event-entity's name to "&2%{mobname}%"
            set event-entity's tool to wooden axe of sharpness 1
            chance of 80%:
                set event-entity's tool to iron shovel
            chance of 50%:
                set event-entity's tool to iron pickaxe
            chance of 20%:
                set event-entity's tool to stone axe
            setarmor(event-entity, "leather")
            delete {mobname}
            stop
        chance of 40%:
            setarmor(event-entity, "leather")
            set event-entity's tool to stone axe of sharpness 1
            set event-entity's name to "&9%{mobname}%"
            delete {mobname}
            stop
        chance of 10%:
            {mobname} is zombie or skeleton
            apply glowing of tier 255 without any particles to entity for 100000 seconds
            set event-entity's name to "&5%{mobname}%"
            set event-entity's tool to iron sword of sharpness 1
            set event-entity's helmet to chain helmet of protection 1
            set event-entity's chestplate to iron chestplate of protection 1
            set event-entity's leggings to chain leggings of protection 1
            set event-entity's boots to iron boots of protection 1
            delete {mobname}
            stop
        chance of 5%:
            {mobname} is zombie or skeleton
            set event-entity's name to "&6%{mobname}%"
            apply glowing of tier 255 without any particles to entity for 100000 seconds
            set event-entity's tool to diamond sword of sharpness 1
            set event-entity's helmet to iron helmet of protection 1
            set event-entity's chestplate to iron chestplate of protection 1
            set event-entity's leggings to iron leggings of protection 1
            set event-entity's boots to iron boots of protection 1
            set event-entity's max health to 20
            heal event-entity
            apply swiftness of tier 2 without any particles to event-entity for 999 days
            delete {mobname}
            stop
        set event-entity's tool to wooden axe of sharpness 1
        set event-entity's name to "&7%{mobname}%"
        delete {mobname}
    else:
        set event-entity's name to "&7%entity%"
        delete {mobname}

unknown.png
unknown.png
 
First of all I'd add another chance condition before running the dices to select which kind of mob should be spawned. Having percentages like 80% is a very high number that can make regular mobs rarer to spawn than your custom mobs.

Second of all don't use
Code:
if "%entity%" is "creeper":
but use:
Code:
if event-entity is a creeper: #don't leave out the 'a' because it can cause errors, I know because I've had the same issue creating a skript that spawns custom mobs on my server.

Third of all, after setting the name of your custom entity. Don't forget to add this line to your code which uses SkBee:
Code:
set event-entity's nbt to "{PersistenceRequired:false}"

After setting the name of a mob in minecraft, this nbt tag will be automatically set to true. This is just the way Minecraft works, this mechanic ensures that mobs that you give a custom name don't despawn. But in the case of your custom mobs, you probably do want them to despawn, because not only will these mobs take large amounts of data in the world files, but it will cause a massive amount of custom mobs to be piled up in chunks where you stay too long, because they'll never despawn, so they only way for them to go away is by killing them.

Here is a part of my custom mob spawn skript to give you an example to go by, as to how I do it.
Code:
on spawn of a monster or a phantom:
    spawn reason is natural #don't forget th is line if u don't want mobs from spawners for example to use the custom variants
    if event-world is "world": #ensures that custom mobs are not spawned within a certain range you could've potentially set up, if you created a spawn protection skript instead of another plugin
        if distance between event-location and world's spawn is less than {spawnprotection}:
            cancel event
            stop
    if "%biome at event-location%" contains "forest": #this allows uncommon humanlike mobs to spawn in the (dark) forests, which I feel like should be a bit more magical and have those mobs there with all the mushrooms and stuff
        set {_n} to (15-light level at event-location)
        chance of {_n}%:
            spawn pillager or illusioner or evoker or vindicator at event-location
            cancel event
            stop
    if event-entity is a skeleton:
        chance of 30%: #CHANCE OF BEING A CUSTOM MOB IN GENERAL, MEANING THE OTHER 70% OF MOBS WILL JUST BE REGULAR MOBS WITHOUT CUSTOM STUFF, WHICH IS MORE SURVIVAL BEGINNER FRIENDLY
            cancel event
            if y-coordinate of event-location is not less than 50:
                chance of 20%: #THIS CHANCE DECIDES WHETHER TO PICK ONE OF THE FOLLOWING VARIANTS OR TO JUST PICK THE MOST COMMON SIMPLE VARIANT TO SPAWN
                    chance of 30%: #CHANCE TO SPAWN A CERTAIN OTHER CUSTOM MOB VARIANT, WHICH IS NOT THE MOST COMMON SIMPLE ONE.
                        spawn skeleton at event-location
                        set the last spawned skeleton's name to "<##093a0a>&lT<##083409>&la<##072e08>&ln<##062807>&lk"
                        equip the last spawned skeleton with all netherite armor of protection 2
                        set the last spawned skeleton's tool to stone sword of knockback
                        set the last spawned skeleton's generic knockback resistance attribute to 10
                        set the last spawned skeleton's generic movement speed attribute to 0.15
                        set the last spawned skeleton's max health to 50
                        set the last spawned skeleton's health to 50
                        set the last spawned skeleton's nbt to "{CustomNameVisible:1b}"
                        set the last spawned skeleton's nbt to "{Tags:[""Tank""]}"
                        set last spawned skeleton's nbt to "{PersistenceRequired:false}"
                        stop
                    chance of 30%: #DO ANOTHER VARIANT OR SOMETHING
                        stop
                    else: #DO THE LAST FINAL VARIANT, IN CASE ANOTHER VARIANT HASNT BEEN PICKED YET AND THE CODE IS RAN UP TILL HERE
                        stop
I hope this will help you out a bit, buddy. Feel free to PM if you're still having issues or need further help. :emoji_slight_smile:
 
Last edited:
Status
Not open for further replies.