#Dash Skript Regeneration Cooldown

1 messages · Page 1 of 1 (latest)

odd ledge
#

If you want ai's words instead of mine here it is ⬇️ It might help you understand what i am trying to do

My issue is that everything is functioning correctly except for one aspect that I am struggling to resolve. I am seeking assistance to address this matter. The problem lies in the fact that when you use the dash ability, it triggers a 5-second cooldown before allowing you to dash again. However, the issue arises when you dash three times consecutively in quick succession. This action initiates three separate 5-second timers, resulting in all three dashes being replenished simultaneously after 5 seconds. My goal is to modify this behavior so that each dash is replenished individually every 5 seconds, rather than all at once.

feral dew
#

whats the point in deleting the variable just beofre setting it??

#

also dont have 2 variables, just check if the counter one is set

#

and use timestamps (which would fix your issue)

#

You might also want to use metadata tags

#

also, you never check if the cooldown is actually expired before letting the player dash

odd ledge
#

Okay lets start from the top do i just remove the function dashcooldown and replace it with the timestamps

#

also how do i use timespans?

odd ledge
#
    if {dashes::%{_p}'s uuid%} >= 1:
        push {_p} up with speed 0.25
        push {_p} forward with speed 1
        set flight mode of {_p} to false
        subtract 1 from {dashes::%{_p}'s uuid%}

function dashcooldown(p: player):
    now > {dashcooldown::%{_p}'s uuid%}
    add 1 to {dashes::%{_p}'s uuid%}
    set {dashcooldown::%{_p}'s uuid%} to 5 seconds from now
    dash({_p})

on jump:
    set flight mode of player to true

on flight toggle:
    if {flymode::%player's uuid%} is false:
        cancel event
        dashcooldown(player)```
Just tried this and it doesnt work
plain plover
#

is your {dashcooldown::%{_p}'s uuid%} even set

#

do

    now > ({dashcooldown::%{_p}'s uuid%} ? 10 seconds before now)```
#

or

    now >= ({dashcooldown::%{_p}'s uuid%} ? now)```
odd ledge
#
    if {dashes::%{_p}'s uuid%} >= 1:
        push {_p} up with speed 0.25
        push {_p} forward with speed 1
        set flight mode of {_p} to false
        subtract 1 from {dashes::%{_p}'s uuid%}
        set {dashcooldown::%{_p}'s uuid%} to 5 seconds from now

function dashcooldown(p: player):
    now >= ({dashcooldown::%{_p}'s uuid%} ? now)
    dash({_p})```
So this?
plain plover
#

no keep the rest of ur dashcooldown function

#

just replace the condition

odd ledge
#

yeah but its not actuallty setting the dashcooldown var anywhere

plain plover
odd ledge
#

Yes but when i look at the skript it checks if now is less than or equal to the var but the var isnt actually set so it stop there and never goes down to settings the var

#

it checks the var and THEN sets it

plain plover
#

that's why I said to replace the if statement

#

it defaults to now when it's not set

#

and changes the operator from > to >=

#

which will pass since the dates are the same

odd ledge
#

Then the next 3 lines is whats broken bc i dont dash

plain plover
#

show what you have rn

odd ledge
#
    if {dashes::%{_p}'s uuid%} >= 1:
        push {_p} up with speed 0.25
        push {_p} forward with speed 1
        set flight mode of {_p} to false
        subtract 1 from {dashes::%{_p}'s uuid%}

function dashcooldown(p: player):
    now >= ({dashcooldown::%{_p}'s uuid%} ? now)
    add 1 to {dashes::%{_p}'s uuid%}
    set {dashcooldown::%{_p}'s uuid%} to 5 seconds from now
    dash({_p})

on join:
    if {flymode::%player's uuid%} isn't set:
        set {flymode::%player's uuid%} to false
    if {dashes::%player's uuid%} isn't set:
        set {dashes::%player's uuid%} to 1

on jump:
    set flight mode of player to true

on flight toggle:
    if {flymode::%player's uuid%} is false:
        cancel event
        dashcooldown(player)

command fly:
    trigger:
        if {flymode::%player's uuid%} is false:
            set flight mode of player to true
            set {flymode::%player's uuid%} to true
        else:
            set flight mode of player to false
            set {flymode::%player's uuid%} to false

every 1 seconds:
    loop all players:
        if {dashes1::%loop-player's uuid%} is less than 1:
            set {displaydashes::%loop-player's uuid%} to "&f⏺ &f⏺ &f⏺"
        if {dashes1::%loop-player's uuid%} is 1:
            set {displaydashes::%loop-player's uuid%} to "<##3AC7FF>⏺ &f⏺ &f⏺"
        if {dashes1::%loop-player's uuid%} is 2:
            set {displaydashes::%loop-player's uuid%} to "<##3AC7FF>⏺ <##3AC7FF>⏺ &f⏺"
        if {dashes1::%loop-player's uuid%} is 3:
            set {displaydashes::%loop-player's uuid%} to "<##3AC7FF>⏺ <##3AC7FF>⏺ <##3AC7FF>⏺"```
#

Entire skript

feral dew
#

do not loop all players every second

odd ledge
#

I need to change the dashes on the scoreboard?

#

do i add that to the function?

plain plover
#

and are you sure dashes >= 1?

odd ledge
#

so it changes when i dash

#

well currently the var "dashes" is 3

feral dew
#

just put it in the function

odd ledge
#

alright

feral dew
#

and then it can be local too

#

no need to have a separate variable just to display the value of another var

odd ledge
#

alright but let me fix the actual dash first

plain plover
#

try broadcasting some variables in functions

#

just to be sure

odd ledge
#

so i can see where it goes wrong alright

plain plover
#

yes

odd ledge
#

Okay so it doesnt say anything so it doesnt even activate the function

plain plover
#

so is your flight var even set?

odd ledge
#

yes

#

if i do /fly i can fly with gmc

#

and if i do it again i cant

plain plover
#

also why do you have that useless var

#

just check if their flight mode is true

odd ledge
#

Well without the /fly you cant fly in gmc

#

without dashing

#

Because thats what i am using for double jump

plain plover
#

well then do the same checking but use their flight mode

#

if flight mode is false
set it to true
else
set it to false

odd ledge
#

okay so it goes onto the dashcooldown function and the first line is broken

#

now >= ({dashcooldown::%{_p}'s uuid%} ? now)

#

doesnt work ^

plain plover
#

ok do now >= ({dashcooldown::%{_p}'s uuid%} ? 1 second before now)

#

try that

odd ledge
#

still doesnt work

plain plover
#

broadcast the var before the if

odd ledge
plain plover
#

does it broadcast anything about the var?

odd ledge
#

It says the passed line 0 in function 1 and then it stops there

plain plover
#

broadcast "%{var}%"

feral dew
#

then its the condition that fails

plain plover
#

we've known that for quite some time

feral dew
#

i skipped a bunch

odd ledge
#

Wait its because the var is true

#

and not a timestamp

plain plover
#

there we go

#

delete it

odd ledge
#

okay now stuff happends

#

and it broke

#

so right when i deleted it i dashed but when i tried to dash again it broke

#

first time

#

second time

feral dew
#

is the {dashes::%uuid%} still >= 1

odd ledge
#

yeah

feral dew
#

how come the "past line 0" isnt done

odd ledge
feral dew
#

ooh its before the "doing the funciton" yeah okay

odd ledge
#

yeah

#

to see if the function even activated

#

which it did and broke on the first condition

feral dew
#

seems the variable is broken again

odd ledge
#

yeah

#

i deleted it and it works but then i broke so something is breaking it

feral dew
#

does it work after 5 seconds?

odd ledge
#

no everything works untill it reaches the first line in the dashcooldown function the condition then i breaks and if i delete the dashcooldown var it works once and breaks

#
    if {dashes::%{_p}'s uuid%} >= 1:
        broadcast "passed line 1 in function 2"
        push {_p} up with speed 0.25
        broadcast "passed line 2 in function 2"
        push {_p} forward with speed 1
        broadcast "passed line 3 in function 2"
        set flight mode of {_p} to false
        broadcast "passed line 4 in function 2"
        subtract 1 from {dashes::%{_p}'s uuid%}
        broadcast "passed line 5 in function 2"

function dashcooldown(p: player):
    broadcast "passed line 0 in function 1"
    broadcast "%{dashcooldown::%{_P}'s uuid%}%"
    now >= ({dashcooldown::%{_p}'s uuid%} ? 1 second before now)
    broadcast "passed line 1 in function 1"
    add 1 to {dashes::%{_p}'s uuid%}
    broadcast "passed line 2 in function 1"
    set {dashcooldown::%{_p}'s uuid%} to 5 seconds from now
    broadcast "passed line 3 in function 1"
    dash({_p})
    broadcast "passed line 4 in function 1"

on join:
    if {flymode::%player's uuid%} isn't set:
        set {flymode::%player's uuid%} to false
    if {dashes::%player's uuid%} isn't set:
        set {dashes::%player's uuid%} to 1

on jump:
    set flight mode of player to true

on flight toggle:
    if {flymode::%player's uuid%} is false:
        broadcast "checking flymode"
        cancel event
        broadcast "canceling flight toggle event"
        dashcooldown(player)
        broadcast "doing the function"

command fly:
    trigger:
        if {flymode::%player's uuid%} is false:
            set flight mode of player to true
            set {flymode::%player's uuid%} to true
        else:
            set flight mode of player to false
            set {flymode::%player's uuid%} to false

every 1 seconds:
    loop all players:
        if {dashes1::%loop-player's uuid%} is less than 1:
            set {displaydashes::%loop-player's uuid%} to "&f⏺ &f⏺ &f⏺"
        if {dashes1::%loop-player's uuid%} is 1:
            set {displaydashes::%loop-player's uuid%} to "<##3AC7FF>⏺ &f⏺ &f⏺"
        if {dashes1::%loop-player's uuid%} is 2:
            set {displaydashes::%loop-player's uuid%} to "<##3AC7FF>⏺ <##3AC7FF>⏺ &f⏺"
        if {dashes1::%loop-player's uuid%} is 3:
            set {displaydashes::%loop-player's uuid%} to "<##3AC7FF>⏺ <##3AC7FF>⏺ <##3AC7FF>⏺"```
Entire Skript
#

when i reload the skript it works once

feral dew
#
    if {dashes::%{_p}'s uuid%} >= 1:
        broadcast "dashes: %{dashes::%{_p}'s uuid%}%"
        push {_p} up with speed 0.25
        push {_p} forward with speed 1
        set flight mode of {_p} to false
        subtract 1 from {dashes::%{_p}'s uuid%}

function dashcooldown(p: player):
    now >= ({dashcooldown::%{_p}'s uuid%} ? 1 second before now)
    add 1 to {dashes::%{_p}'s uuid%}
    set {dashcooldown::%{_p}'s uuid%} to 5 seconds from now
    broadcast "Cooldown passed."
    broadcast "dashes: %{dashes::%{_p}'s uuid%}%"
    broadcast "cooldown: %difference between now and {dashcooldown::%{_p}'s uuid%}%s"
    dash({_p})```what does this say
odd ledge
#

checking flymode
canceling flight toggle event
did the function

#

it goes onto the dashcooldown function and stop/fails and the first line

feral dew
#

try setting the cooldown to now

#

and then check if the time since {} >= 5 seconds

odd ledge
#

where do i add all that?

#

i added a delete infront of the condition

#

and it said

feral dew
#

Why are you deleting it??

#

That will prevent the cooldown

odd ledge
#

Yes but it kinda works now

#

I will remove it

#

Its just i am trying to give you as much information as possible to help me

feral dew
#

Can you send sk info

odd ledge
#

server version is 1.20.4

feral dew
#

Try loop 5 times: broadcast <difference> wait 1 second

#

See if it decreases

odd ledge
#

where do i put it?

feral dew
#

<difference> is the difference expression in the broadcast already there

#

Im just lazy

#

Do it there

odd ledge
#

like this?

#

after the 1.03 seconds it does the dash

#

If i remove the "delete" this only happends

feral dew
#

oh yeah, call the dash function first

odd ledge
#

wdym?

feral dew
#

dash() before the loop

odd ledge
#

doesnt work

#

if i delete the var dashcooldown it works but only once

feral dew
#

can you send the function

#

are you modifying the cooldown var anywhere else?

hearty wharf
odd ledge
#
    if {dashes::%{_p}'s uuid%} >= 1:
        push {_p} up with speed 0.25
        push {_p} forward with speed 1
        set flight mode of {_p} to false
        subtract 1 from {dashes::%{_p}'s uuid%}
        if {dashes1::%{_p}'s uuid%} is less than 1:
            set {displaydashes::%{_p}'s uuid%} to "&f⏺ &f⏺ &f⏺"
        if {dashes1::%{_p}'s uuid%} is 1:
            set {displaydashes::%{_p}'s uuid%} to "<##3AC7FF>⏺ &f⏺ &f⏺"
        if {dashes1::%{_p}'s uuid%} is 2:
            set {displaydashes::%{_p}'s uuid%} to "<##3AC7FF>⏺ <##3AC7FF>⏺ &f⏺"
        if {dashes1::%{_p}'s uuid%} is 3:
            set {displaydashes::%{_p}'s uuid%} to "<##3AC7FF>⏺ <##3AC7FF>⏺ <##3AC7FF>⏺"

function dashcooldown(p: player):
    now >= ({dashcooldown::%{_p}'s uuid%} ? 1 second before now)
    add 1 to {dashes::%{_p}'s uuid%}
    set {dashcooldown::%{_p}'s uuid%} to 5 seconds from now
    broadcast "Cooldown passed."
    broadcast "dashes: %{dashes::%{_p}'s uuid%}%"
    broadcast "cooldown: %difference between now and {dashcooldown::%{_p}'s uuid%}%"
    dash({_p})
    loop 5 times:
        broadcast "%difference between now and {dashcooldown::%{_p}'s uuid%}%"
        wait 1 second

on join:
    if {flymode::%player's uuid%} isn't set:
        set {flymode::%player's uuid%} to false
    if {dashes::%player's uuid%} isn't set:
        set {dashes::%player's uuid%} to 1

on jump:
    set flight mode of player to true

on flight toggle:
    if {flymode::%player's uuid%} is false:
        broadcast "checking flymode"
        cancel event
        broadcast "canceling flight toggle event"
        dashcooldown(player)
        broadcast "did the function"

command fly:
    trigger:
        if {flymode::%player's uuid%} is false:
            set flight mode of player to true
            set {flymode::%player's uuid%} to true
        else:
            set flight mode of player to false
            set {flymode::%player's uuid%} to false```
Current code
#

If i delete {dashcooldown::%player's uuid%} the dash works but once if i try to dash again something breaks

feral dew
#

add if now <= {dashcooldown::%{_p}'s uuid%}: set {_a} to "+" broadcast "%{_a| ? "-"%%seconds of (difference between now and {dashcooldown::%{_p}'s uuid%})%" to the start of the function

odd ledge
#

the dash or the dashcooldown?

#

I added it to the dashcooldown and there is a error

hearty wharf
#

side note, I dont see anywhere of dashes1 being set, added, or removed

odd ledge
feral dew
#

the | -> }

#

typo

feral dew
#

no

#

the indentation is wrong

#

and keep the rest of the function as is

#

dont nest it

odd ledge
odd ledge
#

if i move back the broadcast part 1 tab it does this

feral dew
#

the indentation is still wrong

#

the broadcast is not in the if statement

odd ledge
odd ledge
#

is that correct?

feral dew
#

yes

#

delete the variable, then try to spam the dash. see what happens

odd ledge
#

it says -<none>

#

and it doesnt dash

feral dew
#

but it should set the variable

#

are you still deleting it?

odd ledge
#

no

feral dew
#

...

hearty wharf
#

Why did you delete everything else?

feral dew
#

you still need the rest

#

for the cooldown to be applied

odd ledge
#

Like this?

#

okay now things happend

#

if i delete the var and dash once i get this

#

and this after

feral dew
#

remove all the broadcasts except for the first one

#

and the loop

odd ledge
#

When i delete the var and dash

#

Next dash

feral dew
#

so it was 13 seconds ago

odd ledge
#

yes

feral dew
#

so the now >= () should pass

odd ledge
#

So from my perspective and understanding when i delete the var and i dash it completes all the lines

hearty wharf
#

I would honestly just opt out for

if all:
  {dashcooldown::%{_p}'s uuid%} is set
  now < {dashcooldown::%{_p}'s uuid%}
then:
  send ...
odd ledge
#

But next dash it goes to the 3th line of the function and then stops

hearty wharf
#

"3th"?

odd ledge
#

yes the third line

#

in the function

hearty wharf
#

3rd*

odd ledge
#

oh

#

lol

#

so

1st
2nd
3rd
4th

feral dew
odd ledge
#

okay

#

So this is the function now

feral dew
#

bruh

odd ledge
#

oh wait

feral dew
#

add broadcast "cooldown passed" after the condition

odd ledge
#

so before dash({_p})

feral dew
#

yes

odd ledge
#

ighjjt

#

doesnt broadcast it

#

but if i delete the var it says -<none> and the cooldown passed

#

and then the next dash says -700 somethinng

#

wait no

#

it reset

#

its not -25

#

oh wait thats bc i deleted the var...

feral dew
odd ledge
#

no its because its 700 seconds since i last deleted the var

feral dew
#

send the function and where you call it

odd ledge
#

?

feral dew
#

the very bottom line is where you call it

odd ledge
#

Yeah

feral dew
#

change your function to this:if {dashcooldown::%{_p}'s UUID%} > now: broadcast "Cannot dash yet. (%difference between now and {dashcooldown::%{_p}'s UUID%}%) stop else if {dashcooldown::%{_p}'s UUID%} <= now: broadcast "Can dash. (%difference between now and {dashcooldown::%{_p}'s UUID%}%)" add 1 to {dashes::%{_p}'s UUID%} set {dashcooldown::%{_p}'s UUID%} to 5 seconds from now dash({_p}) else: broadcast "ERROR"

odd ledge
#

Can dash. (15 min and 0.21 seconds.)

feral dew
#

does it go to 0?

#

andlet you dash again?

odd ledge
#

yes

#

after the 5 seconds i can dash again

feral dew
#

so why tf does it work now...

odd ledge
#

Idk

feral dew
#

well there you go ig ¯_(ツ)_/¯

#

you can delete the last 2 lines

odd ledge
#

Weeell it doesnt really do what i needed it to do

feral dew
#

and also remove the else if, just have the main code out of the if statemtn

feral dew
odd ledge
#

Now there is a 5 seconds cooldown between each dash but i wanted it to be 5 seconds per dash regeneration

odd ledge
#

Okay let me explain what i am doing and whats has been the issue this entire time

#

I am making a dash skript where you have 3 dashes you can use at once but the problem is when you dashes you got 1 dash back after 5 seconds but if you dashes 3 times it made 3 different countsdowns and they would all end at the same time since you dash at the same time so when you ran out of your 3 dashes you got 3 dashes back after 5 seconds instead of 1 dash after 5 seconds and then another one after 5 seconds and then the last one

#

i want is so when you dash while a dash timer exist i want it to override the timer and reset it back to 5 seconds

#

so you dont get all your dashes at once

feral dew
#

so then just wait 5 seconds before adding back to {dashes::%uuid%}, no?

feral dew
#

wait

#

so you want them to be used all at once?

#

why make a cooldown then?

odd ledge
#

idk

#

i just trusted you...

#

Like a normal dash skript you have 1 dash and once you use it there is a cooldown to use it again

#

i want 3 dashes that you can charge and use all 3 at once if you want

#

and i want them to regen 1 each 5 seconds

feral dew
#

you had a cooldown function at the very beginning

#

I would just ```if {-dashes::%player's UUID%} < -3:
send "no more" to player
stop

remove 1 from {-dashes::%player's UUID%}
push...
wait 5 seconds
add 1 to {-dashes::%player's UUID%}
send "a dash has recharged" to player```

#

no need for a cooldown function or variable at all

#

(this variable can also be a metadata tag)

#

...

#

indentation matters

odd ledge
#

?

feral dew
#

dont just change it

odd ledge
#

alright

feral dew
#

also, instead of setting variables to false, delete them

odd ledge
#

Okay but it doesnt work

feral dew
#

...

#

better, but why the hell are those local variables now

#

the - was not a typo

odd ledge
#

uh

#

But still doesnt work it has the exact same issue as before

feral dew
#

wdym

odd ledge
#

It charges all at the same time

#

it doesnt override the cooldown

#

which is what i wanted

#

omg

#

let me make a video

feral dew
#

so you want 5 seconds after the last dash

odd ledge
#

yes

feral dew
#

so then set another memory variable to the time since the last dash, and check if that is >= 5 seconds before adding it back..

odd ledge
#

okay soo now we are on the right track

#

How....

feral dew
#

why are you bringing back the cooldown

#

name the variable dashLastUsed or something

#

.
so, 5 seconds after the last dash, they all come back,

or they then come back at 5s intervals

odd ledge
#

yes

feral dew
#

#

I asked you a or b

#

Pick one

odd ledge
#

b

#

second one

#

so when you dash it starts the 5 second counter but if you dash again it deletes the old counter and makes a new one for 5 seconds

#

so they come back 5 seconds after last dash 1 at a time per 5 seconds

feral dew
#

So then

  • wait 5s
  • check if time since last dash >= 5s
  • then while dashes < 3:
  • add 1
  • wait 5s
feral dew
#

what have you tried??

odd ledge
#

Yeah

feral dew
#

not in a separate function

#

thats a separate instance, and the function isnt affected by waits in the main code and vice versa

odd ledge
#

it says line 5 but not 6

feral dew
#

well

#

yeah

#

read the code

#

you just set it.. so its not 5 seconds ago

#

you forgot the wait..

odd ledge
#

Okay so now it does line 1 - 3 instantly then waits 5 seconds and then line 4 - 5

#

but still no line 6

feral dew
#

and you realise you only need to debug after a condition, not each line

#

yeah

#

you're comparing to a number

#

not a timespan

#

5 != 5 seconds

odd ledge
#

Works but still has the same problem

#

If i dash twice i get 2 dashes after 5 seconds

feral dew
#

why did you change it to != 5 seconds

#

thats not the condition

#

you still want >=...

#

the != was me explaining 5 and 5 seconds are not the same

odd ledge
#

>= doesnt work

#

is it !>=

#

<= works

feral dew
feral dew
odd ledge
#

Doesnt work

feral dew
#

wait a tick right after the 5 seconds

#

after the wait 5 seconds line

odd ledge
#

doesnt work

feral dew
#
  if {dashes::%{_p}'s uuid%} <= 3:
    remove 1 from {dashes::%{_p}'s uuid%}
    push {_p} forward at speed 1
    broadcast "used a dash. (%{dashes::%{_p}'s uuid%}% remaining)"
    set {lastDash::%{_p}'s uuid%} to now
    wait 5 seconds
    wait 1 tick
    if (time since {lastDash::%{_p}'s uuid%}) >= 5 seconds:
      while {dashes::%{_p}'s uuid%} < 3:
        add 1 to {dashes::%{_p}'s uuid%}
        broadcast "+1 dash (now %{dashes::%{_p}'s uuid%}%)"
        wait 5 seconds```see what this says
odd ledge
#

that works

#

okay everything works except 2 things

#

Also i can spam them like i dont need to be on the ground i can dash while dashing

feral dew
#

maybe disable the player's flight mode then

#

right after you call the function (or in the function)

odd ledge
#

?

feral dew
#

yes, but you have to set their flight mode to false so that they cant toggle it again, triggering another dash

odd ledge
#

Okay thanks

#

Now what about the -10 dashes like you have infinite dashes

feral dew
#

i mean

#

if {dashes::%{_p}'s uuid%} <= 3:

#

just check if it's > 0

odd ledge
#

Okay

odd ledge
#

OOOOH

#

it checks if its above 3 but not below 0

#

Works now

#

also another thing i want to try and fix