about attack speed

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

zide

Member
Aug 23, 2017
42
1
0
20
How can I read/set the attack speed of an item?
How can I read the attack cooldown for a player(as a percentage)?
Someone told me to use nbt,but I don't know how to do.
My minecraft version is 1.12.1.
My english may be not very good,hope you understand.
Thanks very much.
 
How can I read/set the attack speed of an item?
How can I read the attack cooldown for a player(as a percentage)?
Someone told me to use nbt,but I don't know how to do.
My minecraft version is 1.12.1.
My english may be not very good,hope you understand.
Thanks very much.
i will look in to it wenn i am home
[doublepost=1505412214,1505398111][/doublepost]
How can I read/set the attack speed of an item?
How can I read the attack cooldown for a player(as a percentage)?
Someone told me to use nbt,but I don't know how to do.
My minecraft version is 1.12.1.
My english may be not very good,hope you understand.
Thanks very much.

This requires skstuff. Skstuff isn't origginally updated to 1.12.1 but Tuke-Nuke made a mirror: https://github.com/Tuke-Nuke/SkStuff

The function and the command apply to the item the player is holding

I don't know if reading the cooldown is possible but the read/set part for attack speed is down below here.

Hope this helps a bit.

code_language.skript:
function attackspeed(p: player) :: number:
    set {_data} to tag "AttributeModifiers" of nbt of {_p}'s tool
    set {_data} to "%{_data}%"
    set {_data2::*} to {_data} split at ","
    loop {_data2::*}:
        if "%loop-value%" contains "Amount:":
            set {_data3} to loop-value
            replace every "amount:" with "" in {_data3}
            set {_data3} to "%{_data3}%" parsed as a number
            return {_data3}
            stop
    
command /attackspeed <number>:
    trigger:
        add "{AttributeModifiers:[{AttributeName:""generic.attackSpeed"",Name:""generic.attackSpeed"",Amount:%arg 1%,Operation:0,UUIDLeast:224541,UUIDMost:331232}]}" to nbt of player's tool
        
command /getspeed:
    trigger:
        set {_speed} to attackspeed(player)
        message "%{_speed}%"
 
You can get the cooldown with skript mirror.

Heres how you do it in java so you or someone else can convert it into skript with skript-mirror (ive never used skript-mirror so idk how to)
Java:
import net.minecraft.server.v1_12_R1.EntityPlayer;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;

EntityPlayer entityPlayer = ((CraftPlayer)somePlayer).getHandle();
Float currentToolCharge = entityPlayer.n(0);
 
Status
Not open for further replies.