Solved XP Teleport Delay

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

Mar 29, 2019
15
1
0
20
Category: \_(-_-)_/

Suggested name: XP-Delay Commands

Spigot/Skript Version: Spigot 1.8.8

What I want:
I desire a script that when you type a command for example: /delayspawn, it will check your xp levels and if you have 0 XP levels, it the script will wait 7 seconds and then run a player command: /spawn. However, the more the XP goes up, the less the delay between teleportation should be. I was hoping something like 400 levels would be the minimum delay at 1 second.
(If you ever played CosmicPVP, its very similar to that)
Ideas for commands:
just a /delayspawn command would work

Ideas for permissions:
permission to use the command I guess

When I'd like it by: Idk maybe by two weeks...
 
Well, sorry, but two weeks is way too short. Anyways, this was a really tricky idea. I tried many mechanisms to do it, but what pulled it off was this:

I made a list from highest to lowest of the highest amount of time you can wait to the lowest amount of time, or 1. Then it'll divide the maximum level amount by the highest amount of time you can wait, and then divide the player's level by that new number and round it for the final result. Might seem a bit complicated.

Anyways, the good thing about what I did is it allows you to do any numbers.

max-level is the maximum level a player needs to have before it'll make them wait only 1 second. They can be a bit under though, the mechanism isn't exactly perfect.

max-wait-delay is the maximum amount of time a player has to wait, like if they have 0 levels they wait this amount of time.

Code:
options:
    max-level: 500 #max xp level
    max-wait-delay: 5 #in seconds
command /spawn:
    trigger:
        set {_count} to 0
        loop {@max-wait-delay} times:
            add {@max-wait-delay} - {_count} to {_wow::*}
            increase {_count} by 1
        set {_this} to {@max-level} / {@max-wait-delay}
        set {_that} to round(player's level / {_this})
        if {_that} isn't set:
            set {_that} to 0
        if {_that} is 0:
            set {_that} to 1
        set {_final} to {_wow::%{_that}%}
        message "&6Waiting &c%{_final}% &6seconds until you can go to spawn..."

Have fun!