Set player's reach to 4 if they wait 2x the attack cooldown

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

John119

Member
Jul 30, 2022
3
0
1
25
Code:
on left click:
    execute console command "/reach player %player% 3"
    clear {timer}
    set {timer} to 0
    set {atkspd} to player's attack speed final attribute
    set {chargetimer} to 2*(20/{atkspd})
    loop {chargetimer} times:
        add 1 to {timer}
        send "%{timer}%"
        wait 1 tick
    if {timer} >= {chargetimer}:
        execute console command "/reach player %player% 4"
        send "yes"


This is the code I currently have right now, however the final if statement still triggers even if I don't wait the full 2x and is very inconsistent. Could someone please help?
 
Last edited:
Code:
on left click:
    execute console command "/reach player %player% 3"
    clear {timer}
    set {timer} to 0
    set {atkspd} to player's attack speed final attribute
    set {chargetimer} to 2*(20/{atkspd})
    loop {chargetimer} times:
        add 1 to {timer}
        send "%{timer}%"
        wait 1 tick
    if {timer} >= {chargetimer}:
        execute console command "/reach player %player% 4"
        send "yes"


This is the code I currently have right now, however the final if statement still triggers even if I don't wait the full 2x and is very inconsistent. Could someone please help?

What does the /reach command do, and what is {atkspd} set to?
 
What does the /reach command do, and what is {atkspd} set to?
/reach modifys the distance a player can attack another from in blocks, with the default being 3 blocks. {atkspd} is set to the attack speed attribute of a player after modification, so basically it gets the attack speed of their held weapon. This is used to determine how long the attack cooldown is and multiply it by 2, which is the operation applied to {chargetimer}
 
Your code will definitely not work if there are multiple players due to the variables. Try using local variables or else lists with each player.

I'm not sure if this will work but you can give it a try.

Code:
on left click:
    execute console command "/reach player %player% 3"
    clear {timer::%player's uuid%}
    set {_atkspd} to player's attack speed final attribute
    set {_chargetimer} to 2*(20/{_atkspd})
    loop {_chargetimer} times:
        if {timer::%player's uuid%} is not set:
            stop
        add 1 to {timer::%player's uuid%}
        send "%{_timer}%"
        wait 1 tick
    if {timer::%player's uuid%} >= {_chargetimer}:
        execute console command "/reach player %player% 4"
        send "yes"
 
Status
Not open for further replies.