Cancel Despawning

  • 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!

Aberforth

Member
Jun 14, 2019
40
2
8
Canada
Hello,
I need a script that would stop mobs from despawning, specifically I need it for Giants.

As far as I know, there's no "on despawn" event, so I don't know how to do this.

Any help appreciated.
 
I'm not sure if Giants are normally despawning. If so, just apply them nametags. It will prevent them from despawning.

For the event, there's no on despawn event even in java.
 
I tried giving them nametags or even the {PersistenceRequired:1} tag, but they still despawn.
That's why I was looking for a script. I don't know why do they despawn though, it seems to work fine with any other mob.
 
I'm not sure if this will work at all, you can get an error even while parsing, but I'm sure I can fix any problems about that. This is the first form of the script and it can be improved, that's the script:
Code:
variables:
    {giantid::1} = 1
every 5 seconds:
    loop all giants:
        set {_count} to 1
        loop (last element of {giantid::*}) times:
            if display name of loop-entity contains "Giant  %{_count}%":
                set location of loop-entity to {giant::%{_count}%}
                exit 1 loop
            add 1 to {_count}
    loop all giants:
        if display name of loop-entity doesn't contain "Giant":
            add ((last element of {giantid::*}) + 1)) to {giantid::*}
            set display name of loop-entity to "Giant %(last element of {giantid::*})%"
    set {_test} to 1
    loop all giants:
        set {_name} to display name of loop-entity
        replace all "Giant " with "" in {_name}
        set {_name} to ({_name} parsed as integer)
        add {_name} to {giants::*}
    loop {giantid::*}:
        if contains({giants::*}, loop-value) is false:
            spawn a giant at {giant::%loop-value%}
            set display name of last spawned giant to  "Giant %loop-value%"
This can cause TPS drop but giant despawning is a bug of Minecraft and only way to fix it is replacing them
 
I got 2 errors:
- the location of loop-entity can't be set to anything (line 8)
- functions cannot be used here (or there is a problem with your arguments) (line 22)

There was also an extra bracket in line 13 but I removed it.

Also, I need the Giants to keep their attributes, like name, rotation etc... I don't know if this would be a problem.
 
Code:
variables:
    {giantid::1} = 1
every 5 seconds:
    loop all giants:
        set {_count} to 1
        loop (last element of {giantid::*}) times:
            if display name of loop-entity contains "Giant  %{_count}%":
                set {giant::%{_count}%} location of loop-entity
                exit 1 loop
            add 1 to {_count}
    loop all giants:
        if display name of loop-entity doesn't contain "Giant":
            add ((last element of {giantid::*}) + 1)) to {giantid::*}
            set display name of loop-entity to "Giant %(last element of {giantid::*})%"
    set {_test} to 1
    loop all giants:
        set {_name} to display name of loop-entity
        replace all "Giant " with "" in {_name}
        set {_name} to ({_name} parsed as integer)
        add {_name} to {giants::*}
    loop {giantid::*}:
        set {_lv} to loop-value
        if contains({giants::*}, {_lv}) is false:
            spawn a giant at {giant::%loop-value%}
            set display name of last spawned giant to  "Giant %loop-value%"
For the attributes, you can store them like I did with location: "set {giant::%{_count}%} location of loop-entity" and then assign them to the spawned giants with that variable (line 23)
 
Hmm, there are still some problems with the code,
- loop-entity is neither an item stack nor an entity type (line 8)
- functions cannot be used here (line 23)

And that extra bracket in line 13 but I removed it again.
 
Code:
variables:
    {giantid::1} = 1
every 5 seconds:
    loop all giants:
        set {_count} to 1
        loop (last element of {giantid::*}) times:
            if display name of loop-entity contains "Giant  %{_count}%":
                set {giant::%{_count}%} to location of loop-entity
                exit 1 loop
            add 1 to {_count}
    loop all giants:
        if display name of loop-entity doesn't contain "Giant":
            add ((last element of {giantid::*}) + 1)) to {giantid::*}
            set display name of loop-entity to "Giant %(last element of {giantid::*})%"
    set {_test} to 1
    loop all giants:
        set {_name} to display name of loop-entity
        replace all "Giant " with "" in {_name}
        set {_name} to ({_name} parsed as integer)
        add {_name} to {giants::*}
    loop {giantid::*}:
        set {_lv} to loop-value
        set {_boo} to contains({giants::*}, {_lv})
        if {_boo} is false:
            spawn a giant at {giant::%loop-value%}
            set display name of last spawned giant to  "Giant %loop-value%"
[doublepost=1591036300,1591036267][/doublepost]again forgot to remove that bracket thing