Solved If (blank) give item, else do not give item

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

RadFelix2005

New Member
Jul 9, 2020
7
1
3
18
Im currently working on a gamemode for my server that me and my friends run however I have run into a little problem. I want players to right click a lime dye and get given an item from a list of random chances. for example 5% diamonds etc. However i dont want this to be overpowered so i want to add a delay to that amount of times you right click the lime dye. For example you right click the dye and get a cobblestone then right click it again and it says: you must wait five seconds before you do that again. My code has no problems when i do /sk reload however it doesn't have the delay (people can still spam click it and bypass the delay entirely along with that if they click with any other item they get sent wait five seconds to use that again (which is the part of my code from the bottom.

Heres my code. If someone could help me that would be great:

on right click:
if player's held item is lime dye named "&aGenerator":
set {Spawn::%player%} to 5
send "Wait 5 Seconds before doing that again"
chance of 40%:
add 1 cobblestone to player
chance of 5%:
add 1 dirt to player
chance of 3%:
add 1 sand to player
chance of 2%:
add 1 coal to player
chance of 1%:
add 1 iron ore to player
chance of 0.2%:
add 1 oak sapling to player
chance of 0.1%:
add 1 grass block to player
chance of 0.2%:
add 1 sugar cane to player
chance of 0.06%:
add 1 water bucket to player
chance of 0.04%:
add 1 lava bucket to player
chance of 0.08%:
add 1 diamond to player
chance of 0.02%:
add 1 netherite ingot to player
chance of 2%:
add 1 oak log to player
chance of 4%:
add 1 stick to player
chance of 1%:
add 1 wheat seeds to player
chance of 0.5%:
add 1 gold ore to player
chance of 0.01%:
add 1 wither rose to player
chance of 0.01%:
add 1 soul sand to player
chance of 0.001%:
add 1 wither skeleton skull to player
chance of 0.005%:
add 1 gunpowder to player
chance of 2%:
add 1 hay block to player
chance of 1%:
add 1 leather to player
chance of 0.5%:
add 1 bone to player
while {Spawn::%player%} is not 0:
wait a seconds
subtract 1 from {Spawn::%player%}
else if {Spawn::%player%} is not 0:
send "wait five seconds to use that again"
[doublepost=1610872094,1610872052][/doublepost]Ignore all of the chance of's just wanted to include the whole thing just in case
 
You could either use:
Code:
on right click:
  if player's held item is lime dye named "&aGenerator":
    set {_waited} to difference between {generator::%player's uuid%::lastuse} and now
    if {_waited} is less than 5 seconds:
      send "no"
    else:
      #your code (the chances)
      set {generator::%player's uuid%::lastuse} to now

The {generator::%player's uuid%::lastuse} variable is just an example, this can be any variable, as long as it's linked to the player so the cooldown is only for that specific player.

Or you could use:
Code:
on right click:
  if player's held item is lime dye named "&aGenerator":
    if unix date of (metadata tag "cooldown" of player) was less than 3 seconds ago:
      send "no"
    else:
      #your code (the chances)
      set metadata "cooldown" of player to unix timestamp of now

I hope I didn't make any mistakes while typing this, hope it helped.
 
Status
Not open for further replies.