how to make it if a variable reaches a number give them effect

Discussion in 'Skript' started by Tekkabyte, Feb 22, 2020.

  1. this is the skript i have RN this one thanks to gavidos
    on walking on dark prismarine:
    add 1 to {speed}
    teleport player to location 2 meters south of player

    variables:
    {speed} = 0

    this is the skript that wont work
    if player's {speed} is 500:
    give player effect speed 1 10
     
  2. gavidos? :(
    there is no need to use variables in this situation, use
    set walking speed of player to %number%

    and there's no such thing as "player's variable"
     
    • Funny Funny x 1
  3. if some player's speed was 500 im pretty sure your server would suffer a stroke
     
  4. the speed 500 is the amount i want them to reach which is a variable and if they reach that number they get speed 1 i just dont know how to make that work
     
    #4 Tekkabyte, Feb 22, 2020
    Last edited: Feb 22, 2020
  5. Try this:
    on walking on dark prismarine:
    add 1 to {speed.%player%}
    teleport player to location 2 meters south of player

    variables:
    {speed} = 0

    if {speed.%player%} is 500:
    give player effect speed 1 10
     
    • Funny Funny x 1
  6. thats giving me 9 errors saying the code has to be put into triggers but it already is
     
  7. ok i fixed alot of them and now i got this one error

    cant understand line: if {speed.%player%} is 500:
     
  8. I really recommend to just use what I said in my first post in this thread, but if you're going to use variables:

    there are some things wrong about the way how you use variables - it is highly inefficient
    in skript community we have agreed that we use the variable format of {<name>::<uuid>} for example, {speed::%uuid of player%}
    not {speed.%player%}

    why?

    list variables can be looped and dot variables cannot, making list variables absolutely superior to use and just better in every situation.

    uuids make sure that data is not lost on name change

    if you do not need the data to persist, you should prefix the variable with "-", it makes sure that it doesn't get saved to database and is lost on restart, it is much better for performance since it does not need to write it to disk, but note that "-" variables do not function that way by default, you have to configure them in your config.sk

    also you do not need
    variables:
    {speed} = 0

    part, if you ever want to display a variable and that being the reason you want it to default to 0 so people see a fancy 0 instead of <none>, you should use {speed} ? 0
    which will show 0 if {speed} is unset, without defaulting it to 0
     
  9. gavidos i dont get what your trying to say on the first one because i need it so if they reach that number from touching the dark prismarine it gives them the effect speed
     
  10. .

    Code (Text):
    variables:
        {speed.%player%} = 0

    on walking on dark prismarine:
        add 1 to {speed.%player%}
        teleport player to location 2 meters south of player
        if {speed.%player%} = 500:
            apply potion of speed of tier 1 to player for x(e.g 5) seconds
            # If you want to clear it then do:
            clear {speed.%player%}
    I recomend using the player's uuid, for example:

    Code (Text):
    on join:
        if {speed.%uuid of player%} is not set:
            set {speed.%uuid of player%} to 0

    on walking on dark prismarine:
        add 1 to {speed.%uuid of player%}
        teleport player to location 2 meters south of player
        if {speed.%uuid of player%} = 500:
            apply potion of speed of tier 1 to player for 5 seconds
            clear {speed.%uuid of player%}
    If you want {spead.%uuid of player%} to remain 500 and that the player has the effect continuously:

    Code (Text):
    on walking on dark prismarine:
        if {speed.%uuid of player%} = 500:
            apply potion of speed of tier 1 to player for 5 seconds
            stop
        else:
            teleport player to location 2 meters south of player
     
  11. the on join exampe is not good, it is useless data saving to database and for continuous effect, you should also remove the effect and only then apply, so it doesn't stack up to infinity