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 Sell item based on lore

Discussion in 'Skript' started by TheVedel1, Sep 5, 2017.

Tags:
Thread Status:
Not open for further replies.
  1. TheVedel1

    TheVedel1 Member

    Joined:
    Jul 28, 2017
    Messages:
    14
    Likes Received:
    0
    Hi guys, I'm trying to sell an item based on it's lore, yet it doesnt work. I only get error with the sell-all part "%number% %text% is not valid item data"

    Not sure what it means.

    Yet first sell script doesnt work, yet no errors. Any ideas why? Thank you.

    Skript:

    Code (Skript):
    1. on right click on player:
    2.     if name of clicked player is "&a&lTrader":#12
    3.         set {_lore::*} to lore of player's tool split by "||"
    4.         if "%{_lore::*}%" contains "Sell Price:":
    5.             loop {_lore::*}:
    6.                 set {_price::*} to uncolored loop-value parsed as "Sell Price: %number% Gold"
    7.                 play "BLOCK_NOTE_XYLOPHONE" to player at volume 1
    8.                 remove 1 of item from player's inventory
    9.                 add {_price::1} to player's balance
    10.                 send "&6You sold your item for: &e%{_price::1}% %{_price::*}% %{_lore::*}% Gold" to player
    11.                 send "&6You now have: &e%player's balance% Gold" to player
    12.                 exit loop
    13.                 stop
    14.         else:
    15.             send "&cYou cant sell this item" to player
    16.            
    17. command /sellall:
    18.     trigger:
    19.         loop all items in player's inventory:
    20.             set {_lore::*} to lore of loop-item split by "||"
    21.             loop {_lore::*}:
    22.                 set {_test::*} to uncolored loop-value parsed as "Sell Price: %number% %text%"
    23.                 play "BLOCK_NOTE_XYLOPHONE" to player at volume 1
    24.                 remove 1 of loop-item from player's inventory
    25.                 add {_test::1} to player's balance
    26.                 send "&6You sold your item for: &e%{_test::1}% Gold" to player
    27.                 send "&6You now have: &e%player's balance% Gold" to player
    28.                 exit loop
    29.                 stop
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Use the help request layout.

    Code (Skript):
    1. set {_lore::*} to lore of player's tool split at "||"
    2. loop {_lore::*}: #each loop is a different line of lore
    3.     loop-value contains "Sell Price:" #if the line of lore is the line that contains the sell price...
    4.     set {_price::*} to loop-value split at "Sell Price: " #then we get the values using split, the first one returns 'sell price:' and '10 gold' for example.
    5.     set {_price::*} to {_price::2} split at " Gold" #we want the '10 gold' part so {_price::2}. We split it into '10' and 'Gold'
    6.     set {_price} to {_price::1} parsed as number #we only want the number, so {_price::1}
    7.     message "the item sells for %{_price}%" #and there you have it
    8.     stop loop #we don't need to keep looping as we got what we wanted already.
    9. if {_price} is not set:
    10.     message "the item can't be sold"
    11.     stop
    Try this. I have not used split in a long time so maybe it doesn't work. You get the idea.
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Thanks for trying to help out, yet I get no errors and it doesnt work.
    --- Double Post Merged, Sep 6, 2017, Original Post Date: Sep 5, 2017 ---
    Is it possible to read the last line of an item's lore? Dont see anything in documentation.
    --- Double Post Merged, Sep 10, 2017 ---
    Anyone?
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Code (Skript):
    1. set {_L::*} to lore of player's tool split at "||"
    2. set {_imlastone} to {_L::%size of {_L::*}%}

    btw what do you mean "Doesn't work" its don't show send message from xUndefined code?
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    I tried debugging, and it's like the "loop-value" doesnt work. Btw, how does that code work?
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    I tryed... Uhm youre right. He forget to add

    "%loop-value%"

    so just change only one line:

    Code (Skript):
    1. "%loop-value%" contains "Sell Price:"
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Great, works uncolored. How do you parse it as uncolored text again?
    --- Double Post Merged, Sep 10, 2017, Original Post Date: Sep 10, 2017 ---
    And what about getting the quantity of the held item? I've never been able to do that.
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    The Number its already parsing (%{_price}%), and uncolored just this
    Code (Skript):
    1. set {_lore::*} to uncolored lore of player's tool split at "||"

    %amount of player's tool%
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    You have no idea how much you're helping us dude. Thank you very much.

    Would this work: loop amount of player's tool times:
    --- Double Post Merged, Sep 10, 2017, Original Post Date: Sep 10, 2017 ---
    I'm trying to write a sellall skript, with this too. Looping all players items, looping amount of loop-item etc.
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Im unsure with the loop player's inventory. i never did it.
    Code (Skript):
    1. loop all item in player's inventory:
    2.     loop-item is player's held item:
    3.         send "%amount of loop-item% More founds. Lets me do the jobs"
    4.         add amount of loop-item to {_sellall}
    5.     send "Alright. i found in player's inventory %{_sellall}% Items"

    #edit:

    i found my old skript... Easier way:
    Code (Skript):
    1. set {_amount} to number of player's tool in player's inventory
     
Thread Status:
Not open for further replies.

Share This Page

Loading...