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.

Solved Compare question

Discussion in 'Skript' started by _PAPER_PLANE_, Jan 6, 2023.

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

    _PAPER_PLANE_ Member

    Joined:
    Jan 21, 2022
    Messages:
    16
    Likes Received:
    0
    I want to confirm on the second line that the player has the item and I have enough items on me, but it still judges it as not having it

    I have confirmed that the contents of {_item} and the items in my backpack are "cobblestone block"


    Code (Text):
    1. function money(p: player, n: number, item: item, price: number):
    2.     {_p} has {_n} of {_item}:  ←here
    3.         remove {_n} of {_item} from {_p}
    4.         add {_price} to money of {_p}
    5.     else:
    6.         send "you don't have enough items" to {_p}
    7.         play sound "block.note_block.pling" with volume 2 and pitch 0.5 to {_p}
    8. on inventory click:
    9.     name of event-inventory is "menu":
    10.         cancel event
    11.         set {_item1} to type of event-item
    12.         index of event-slot = 0:
    13.             money(player, 1, {_item1}, 0.5)


     
    #1 _PAPER_PLANE_, Jan 6, 2023
    Last edited: Jan 8, 2023
  2. Best Answer:
    Post #9 by xdh, Jan 17, 2023
  3. xdh

    xdh Active Member

    Joined:
    Apr 15, 2020
    Messages:
    78
    Likes Received:
    4
    you're calling a different function when the player clicks the item?
     
  4. _PAPER_PLANE_

    _PAPER_PLANE_ Member

    Joined:
    Jan 21, 2022
    Messages:
    16
    Likes Received:
    0
    Sorry, I forgot to change it, because I will change the code to be easier to read before publishing, now I edited it
     
  5. xdh

    xdh Active Member

    Joined:
    Apr 15, 2020
    Messages:
    78
    Likes Received:
    4
    I tested out this code, and it works, so your issue might be with detecting the inventory itself, you might want to switch to metadata instead of name of the inventory here is a tutorial about metadata.
    However if you still choose to use the name, send the code of the inventory as well, because skript also recognizes and compares colors
     
    _PAPER_PLANE_ likes this.
  6. yea rite

    yea rite Active Member

    Joined:
    Jul 11, 2021
    Messages:
    82
    Likes Received:
    8
    adding on to what @xdh said, you can also fix color checking in names by making skript read the gui name as uncolored. I dont recommend this though, because if you have multiple menus with the same name but different colors it will trigger both.
    Code (Text):
    1. if uncolored name of event-inventory is "name":
     
    _PAPER_PLANE_ and xdh like this.
  7. _PAPER_PLANE_

    _PAPER_PLANE_ Member

    Joined:
    Jan 21, 2022
    Messages:
    16
    Likes Received:
    0
    Oh, it turns out that there are three ways, I read this to know, I have been using variables + inventory name, let me change my code to try
    --- Double Post Merged, Jan 14, 2023, Original Post Date: Jan 14, 2023 ---
    I replaced the GUI with metadata, but it still doesn't work.
    Still output "you don't have enough items"
    Or do you need the full .sk file?
     

    Attached Files:

  8. xdh

    xdh Active Member

    Joined:
    Apr 15, 2020
    Messages:
    78
    Likes Received:
    4
    I'll test it out tomorrow and I will let you know.
     
  9. _PAPER_PLANE_

    _PAPER_PLANE_ Member

    Joined:
    Jan 21, 2022
    Messages:
    16
    Likes Received:
    0
    I also changed a little to make it easier for you to read, thank you very much!
     
  10. xdh

    xdh Active Member

    Joined:
    Apr 15, 2020
    Messages:
    78
    Likes Received:
    4
    I apologize for the late reply, I completely forgot! I have great news! I have found your issue

    Code (Text):
    1. function moneyoptionclick(p: player, n: number, item: text, price: number):
    2.  
    Your issue is in the item variable, because you're trying to compare an itemtype with text, now if you were to change it to an itemtype like this:
    Code (Text):
    1. function moneyoptionclick(p: player, n: number, item: itemtype, price: number):
    2.  
    it should work.
     
    Merrical likes this.
  11. _PAPER_PLANE_

    _PAPER_PLANE_ Member

    Joined:
    Jan 21, 2022
    Messages:
    16
    Likes Received:
    0
    That's okay, but you solved this problem that has been bothering me for a long time, thank you very much for your help! (* >ω<)
     
Thread Status:
Not open for further replies.

Share This Page

Loading...