Solved Command cooldown and inventory items

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

Ariuw

Member
Sep 6, 2017
42
1
8
30
Skript Version: Skript 2.4-beta10
Addons using (including versions): Skellett (1.9.8) - SkQuery (4.1.1) - skRayFall (1.9.18) - skUtilities (0.9.2)
Minecraft Version: 1.14.4

I've been trying to do something like that when a player right clicks on a sign, it opens a menu and on the menu there will be a mission to collect coal, if the player completes the mission a cooldown of 24 hours should start and the player has to wait until the next day to do the mission again.

My problem is that I can't get the "You have to wait" message to work and Cooldown is not working properly :emoji_frowning:

Code:
on rightclick on sign:
    1st line of clicked block is "Test":
        open chest with 3 rows named "&3Misiones diarias" to player
        format slot 12 of the player with a Coal named "&aMisión diaria" with lore "Colecciona 2 stacks de Carbón" to close then run [make player execute command "mission1"]
           
command /mission1:
    trigger:
        if {mission1.%player%} is not 1:
            set {mission1.%player%} to 1   
            if number of all coal in player's inventory is less than 128:
                message "Mine all the coal that is needed"
                stop
            else:
                if player's inventory contains 128 coal:
                    wait 5 ticks
                    message ""
                    message "&2Mission complete!"
                    message ""
                    remove 128 coal from player's inventory
                    give player 1 diamond
        else:
            set {mission1.%player%.lastused} to now
            set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
            if {_cooldown1.%player%} is less than 24 hours:
                message ""
                message "&7 - Ya completaste esta misión hoy! -"
                message "&7You have to wait &c%difference between 24 hours and {_cooldown1.%player%}% &7before you do this mission again"
                message ""
 
You are doing it wrong. When you set '{mission1.%player%.lastused} to now' it is resetting the cooldown. You want to set the cooldown after the condition to check it or else it will always be on cooldown.

Example:
code_language.skript:
set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
if {_cooldown1.%player%} is less than 24 hours:
    #you have to wait etc (on cooldown code)
    stop
set {mission1.%player%.lastused} to now # (this line puts it on cooldown)
#do stuff (not on cooldown code)
 
You are doing it wrong. When you set '{mission1.%player%.lastused} to now' it is resetting the cooldown. You want to set the cooldown after the condition to check it or else it will always be on cooldown.

Example:
code_language.skript:
set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
if {_cooldown1.%player%} is less than 24 hours:
    #you have to wait etc (on cooldown code)
    stop
set {mission1.%player%.lastused} to now # (this line puts it on cooldown)
#do stuff (not on cooldown code)

But what if I can't get the "Mine all the coal that is needed" message to work? because I just want the cooldown to work when the player has the 128 of coal in the inventory and if not, then it just sends a message
 
If you want to set the cooldown when they complete the mission, then use the 'set {mission1.%player%.lastused} to now' in the reward code for completing the mission. As for checking for a certain amount of items, you can use this syntax: https://skripthub.net/docs/?id=965

Example:
code_language.skript:
# [the] (amount|number) of %itemtypes% (in|of) %inventories%
if amount of coal in player's inventory is less than 128:

I am assuming after the 24 hour period, you want to reset the mission so they can do it again. Then you can do what I said before, except you remove the "setting the cooldown" part.

code_language.skript:
set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
if {_cooldown1.%player%} is less than 24 hours:
    # you have to wait etc (on cooldown code)
    stop
# This section is for after the cooldown period is over (resetting the mission)
set {mission1.%player%} to 0
make player execute command "mission1"
 
Last edited:
If you want to set the cooldown when they complete the mission, then use the 'set {mission1.%player%.lastused} to now' in the reward code for completing the mission. As for checking for a certain amount of items, you can use this syntax: https://skripthub.net/docs/?id=965

Example:
code_language.skript:
# [the] (amount|number) of %itemtypes% (in|of) %inventories%
if amount of coal in player's inventory is less than 128:

I am assuming after the 24 hour period, you want to reset the mission so they can do it again. Then you can do what I said before, except you remove the "setting the cooldown" part.

code_language.skript:
set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
if {_cooldown1.%player%} is less than 24 hours:
    # you have to wait etc (on cooldown code)
    stop
# This section is for after the cooldown period is over (resetting the mission)
set {mission1.%player%} to 0
make player execute command "mission1"

I did this:

Code:
command /mission1:
    trigger:
        if number of all coal in player's inventory is less than 128:
            message "Mission not completed."
            stop
        else:
            if player's inventory contains 128 coal:
                wait 5 ticks
                message ""
                message "&2Misión completada! &7entregaste con exito los 2 stacks de Carbón!"
                message ""
                remove 128 coal from player's inventory
                give player 1 diamond
                set {mission1.%player%.lastused} to now
                set {mission1.%player%.completed} to 1
                set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
            else:
                if {_cooldown1.%player%} is less than 5 seconds:
                    message ""
                    message "&7 - You already completed this mission! -"
                    message "&7You have to wait &c%difference between 24 hours and {_cooldown1.%player%}% &7to do this mission again!"
                    message ""

and the cooldown is not working now, is it because of the "else" if so.. how can I fix that?
 
I did this:

Code:
command /mission1:
    trigger:
        if number of all coal in player's inventory is less than 128:
            message "Mission not completed."
            stop
        else:
            if player's inventory contains 128 coal:
                wait 5 ticks
                message ""
                message "&2Misión completada! &7entregaste con exito los 2 stacks de Carbón!"
                message ""
                remove 128 coal from player's inventory
                give player 1 diamond
                set {mission1.%player%.lastused} to now
                set {mission1.%player%.completed} to 1
                set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
            else:
                if {_cooldown1.%player%} is less than 5 seconds:
                    message ""
                    message "&7 - You already completed this mission! -"
                    message "&7You have to wait &c%difference between 24 hours and {_cooldown1.%player%}% &7to do this mission again!"
                    message ""

and the cooldown is not working now, is it because of the "else" if so.. how can I fix that?
I would just revert the code back to the way it was and do what I said, then I think it will all work fine for you.

EDIT: Now that I think about it, you should actually make a separate command or something to check if the player has the amount of coal they need. Having it all in that one command is not going to work properly the way you made it.

Something like this would probably be better (untested):
code_language.skript:
on rightclick on sign:
    1st line of clicked block is "Test":
        open chest with 3 rows named "&3Misiones diarias" to player
        format slot 12 of the player with a Coal named "&aMisión diaria" with lore "Colecciona 2 stacks de Carbón" to close then run [make player execute command "mission1"]
        
command /mission1:
    trigger:
        set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
        if {_cooldown1.%player%} is less than 24 hours:
            message ""
            message "&7 - Ya completaste esta misión hoy! -"
            message "&7You have to wait &c%difference between 24 hours and {_cooldown1.%player%}% &7before you do this mission again"
            message ""
            stop
        {mission1.%player%} is not 1
        set {mission1.%player%} to 1
        message "You started mission1 example."

command /checkmission1:
    trigger:
        if {mission1.%player%} is 1:
            if amount of coal in player's inventory is greater than or equal to 128:
                set {mission1.%player%.lastused} to now
                remove 128 coal from player's inventory
                give player 1 diamond
                message ""
                message "&2Mission complete!"
                message ""
            else:
                message "Mine all the coal that is needed"
 
Last edited:
I would just revert the code back to the way it was and do what I said, then I think it will all work fine for you.

EDIT: Now that I think about it, you should actually make a separate command or something to check if the player has the amount of coal they need. Having it all in that one command is not going to work properly the way you made it.

Something like this would probably be better (untested):
code_language.skript:
on rightclick on sign:
    1st line of clicked block is "Test":
        open chest with 3 rows named "&3Misiones diarias" to player
        format slot 12 of the player with a Coal named "&aMisión diaria" with lore "Colecciona 2 stacks de Carbón" to close then run [make player execute command "mission1"]
        
command /mission1:
    trigger:
        set {_cooldown1.%player%} to difference between {mission1.%player%.lastused} and now
        if {_cooldown1.%player%} is less than 24 hours:
            message ""
            message "&7 - Ya completaste esta misión hoy! -"
            message "&7You have to wait &c%difference between 24 hours and {_cooldown1.%player%}% &7before you do this mission again"
            message ""
            stop
        {mission1.%player%} is not 1
        set {mission1.%player%} to 1
        message "You started mission1 example."

command /checkmission1:
    trigger:
        if {mission1.%player%} is 1:
            if amount of coal in player's inventory is greater than 128:
                set {mission1.%player%.lastused} to now
                remove 128 coal from player's inventory
                give player 1 diamond
                message ""
                message "&2Mission complete!"
                message ""
            else:
                message "Mine all the coal that is needed"

I've tested your skript, it almost works D: it just doesn't check the player inventory and doesn't remove the coal. I'll keep trying but since I am bad at this I don't think I'll get somewhere lol
 
I've tested your skript, it almost works D: it just doesn't check the player inventory and doesn't remove the coal. I'll keep trying but since I am bad at this I don't think I'll get somewhere lol
I made a slight adjustment:
code_language.skript:
if amount of coal in player's inventory is greater than or equal to 128:
This should work out fine. Forgot to add the "equal' part.
 
I made a slight adjustment:
code_language.skript:
if amount of coal in player's inventory is greater than or equal to 128:
This should work out fine. Forgot to add the "equal' part.
That may work, is it possible to cancel the cooldown using a different command?
 
You can reset a player's cooldown by doing "delete {mission1.%player%.lastused}"
That's what I used but now when trying to use the sign, it won't work at all. I didn't get any message or Cooldown message
 
That's what I used but now when trying to use the sign, it won't work at all. I didn't get any message or Cooldown message
If a player already has the mission, the command /mission1 will do absolutely nothing. If they are not on cooldown or have the mission, it will give them the mission according to the code I sent you. If you want to reset the mission for the player too, do "set {mission1.%player%} to 0" in the reset section.
 
If a player already has the mission, the command /mission1 will do absolutely nothing. If they are not on cooldown or have the mission, it will give them the mission according to the code I sent you. If you want to reset the mission for the player too, do "set {mission1.%player%} to 0" in the reset section.
That worked, but I forgot to add that I only get the Mission Started message but I am not getting my items removed
 
That worked, but I forgot to add that I only get the Mission Started message but I am not getting my items removed
To check and remove the items, you have to use the /checkmission1 that I put. If you want to check it right when they start the mission, add 'make player execute command "checkmission1"' right after they start the mission. If the player doesn't have the required material, you can keep using /checkmission1 to check if they completed it or not.
 
Status
Not open for further replies.