Check if sign breaks after being placed.

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

fafler

New Member
Jan 26, 2017
5
0
0
42
Hi. I have a plugin, CraftBook, where players a able to place various signs with special functions. I want to use Skript, to add a price for making those signs, and almost have it with this piece of code:

code_language.skript:
on sign change:
    if line 2 contains "[mc1421]":
        event-player has permission "craftbook.ic.mc1421"
        if event-player's balance is greater than or equal to 100:
            execute console command "money take %event-player% 100"
            message "Du har betalt 100 em for [mc1421]"
            stop
        set block to air
        message "Det koster 100 em at lave en [mc1421]"

This works, except for when players get the second line on the sign right, but other information on the sign wrong. In that case the player will still be charged, but the sign breaks after being placed. So, how would I make the above code wait a second and check if the sign is still there?
 
So i can't completly follow you, but try this code bellow. I changed some if statements and i changed that if you haven't the money that the sign would be cleared and not be deleted (same without permission).

Code:

code_language.skript:
on sign change:
    if line 2 is "[mc1421]":
        if player has permission "craftbook.ic.mc1421":
            if player's balance is greater than or equal to 100:
                execute console command "money take %event-player% 100"
                message "Du har betalt 100 em for [mc1421]"
                stop
            else:
                set line 1 to ""
                set line 2 to ""
                set line 3 to ""
                set line 4 to ""
                message "Det koster 100 em at lave en [mc1421]"
                stop
        else:
            set line 1 to ""
            set line 2 to ""
            set line 3 to ""
            set line 4 to ""
            message "&cNo Permission"
            stop
    else:
        stop
 
Let me try to explain it a little better. The player places the sign and both Skript and CraftBook checks the sign. If the player needs to put coordinates or a blocktype or whatever on the third line, CraftBook breaks the sign, but Skript has already charged the player for creating it. So a delay is needed between the on sign change event and checking the sign text. If I simply put a wait 1 second statement in there somewhere, it doesn't re-read the sign after waiting. That's basically what I need help with.
 
So you mean something like this?:

code_language.skript:
on sign change:
    if line 2 is "[mc1421]":
        wait 1 second
        if player has permission "craftbook.ic.mc1421":
            if balance of player is greater than or equal to 100:
                remove 100 from the player's balance
                message "Du har betalt 100 em for [mc1421]"
                stop
            else:
                set line 1 to ""
                set line 2 to ""
                set line 3 to ""
                set line 4 to ""
                message "Det koster 100 em at lave en [mc1421]"
                stop
        else:
            set line 1 to ""
            set line 2 to ""
            set line 3 to ""
            set line 4 to ""
            message "&cNo Permission"
            stop
    else:
        stop

But the problem is that Skript have the highest priority. So first Skript will run the on sign change event and afterwards CraftBook will run that event.
 
Just wait a moment and check if the block at the event-location is still a sign or if it's now air. If it's air, it means the sign was broken by CraftBook, if it's still the sign then they entered it correctly and you can take the balance then.
 
Just wait a moment and check if the block at the event-location is still a sign or if it's now air. If it's air, it means the sign was broken by CraftBook, if it's still the sign then they entered it correctly and you can take the balance then.

So @Mr_Simba, do you mean something like this?:

code_language.skript:
on sign change:
    if line 2 is "[mc1421]":
        set {_location} to location of event-block
        wait 1 second
        if block at {_location} is not air:
            clear {_location}
            if player has permission "craftbook.ic.mc1421":
                if balance of player is greater than or equal to 100:
                    remove 100 from the player's balance
                    message "Du har betalt 100 em for [mc1421]"
                    stop
                else:
                    set line 1 to ""
                    set line 2 to ""
                    set line 3 to ""
                    set line 4 to ""
                    message "Det koster 100 em at lave en [mc1421]"
                    stop
            else:
                set line 1 to ""
                set line 2 to ""
                set line 3 to ""
                set line 4 to ""
                message "&cNo Permission"
                stop
        else:
            clear {_location}
            stop
    else:
        stop
 
Yeah, you shouldn't need to wait a full second though, and you can just use 'event-locatin' instead of the whole {_location} thing you're doing.
 
Yeah, you shouldn't need to wait a full second though, and you can just use 'event-locatin' instead of the whole {_location} thing you're doing.

@Mr_Simba yeah i forgot that this works :emoji_slight_smile:. And yes a whole second is to long. I've shortened it to 5 ticks so the finally code looks like this:

code_language.skript:
on sign change:
    if line 2 is "[mc1421]":
        wait 5 ticks
        if block at event-location is not air:
            if player has permission "craftbook.ic.mc1421":
                if balance of player is greater than or equal to 100:
                    remove 100 from the player's balance
                    message "Du har betalt 100 em for [mc1421]"
                    stop
                else:
                    set line 1 to ""
                    set line 2 to ""
                    set line 3 to ""
                    set line 4 to ""
                    message "Det koster 100 em at lave en [mc1421]"
                    stop
            else:
                set line 1 to ""
                set line 2 to ""
                set line 3 to ""
                set line 4 to ""
                stop
        else:
            stop
    else:
        stop

@fafler you can test this code and then you can give feedback
 
Status
Not open for further replies.