1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Skript' started by John119, Jul 30, 2022.

Thread Status:
Not open for further replies.
  1. John119

    John119 Member

    Joined:
    Jul 30, 2022
    Messages:
    3
    Likes Received:
    0
    Code (Text):
    1. on left click:
    2.     execute console command "/reach player %player% 3"
    3.     clear {timer}
    4.     set {timer} to 0
    5.     set {atkspd} to player's attack speed final attribute
    6.     set {chargetimer} to 2*(20/{atkspd})
    7.     loop {chargetimer} times:
    8.         add 1 to {timer}
    9.         send "%{timer}%"
    10.         wait 1 tick
    11.     if {timer} >= {chargetimer}:
    12.         execute console command "/reach player %player% 4"
    13.         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?
     
    #1 John119, Jul 30, 2022
    Last edited: Jul 31, 2022
  2. Sabified

    Sabified Member

    Joined:
    Jun 5, 2022
    Messages:
    28
    Likes Received:
    2
    Could you please indent your code or use code blocks with
    Code (Text):
    1. [CODE]
    [/CODE]
     
  3. John119

    John119 Member

    Joined:
    Jul 30, 2022
    Messages:
    3
    Likes Received:
    0
    yeah sure sorry. done it now
     
  4. Sabified

    Sabified Member

    Joined:
    Jun 5, 2022
    Messages:
    28
    Likes Received:
    2
    What does the /reach command do, and what is {atkspd} set to?
     
  5. John119

    John119 Member

    Joined:
    Jul 30, 2022
    Messages:
    3
    Likes Received:
    0
    /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}
     
  6. mordrowned

    mordrowned Member

    Joined:
    Apr 22, 2021
    Messages:
    40
    Likes Received:
    2
    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 (Text):
    1. on left click:
    2.     execute console command "/reach player %player% 3"
    3.     clear {timer::%player's uuid%}
    4.     set {_atkspd} to player's attack speed final attribute
    5.     set {_chargetimer} to 2*(20/{_atkspd})
    6.     loop {_chargetimer} times:
    7.         if {timer::%player's uuid%} is not set:
    8.             stop
    9.         add 1 to {timer::%player's uuid%}
    10.         send "%{_timer}%"
    11.         wait 1 tick
    12.     if {timer::%player's uuid%} >= {_chargetimer}:
    13.         execute console command "/reach player %player% 4"
    14.         send "yes"
     
Thread Status:
Not open for further replies.

Share This Page

Loading...