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.

Stock

Discussion in 'Skript' started by Ter2FIc, Jan 28, 2021.

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

    Ter2FIc Member

    Joined:
    Dec 30, 2020
    Messages:
    20
    Likes Received:
    0
    Code (Text):
    1.  
    2. options:
    3.     c : &6[&eStock&6]&f
    4.     s : of current inventory of player to
    5.     s2 : of current inventory of loop-player to
    6.    
    7. #create stock /addstock [name] [amount] [price]
    8. command /addstock [<text>] [<number>] [<number>]:
    9.     trigger:
    10.         if player is op:
    11.             if arg 1 is set:
    12.                 if arg 2 is set:
    13.                     if size of {stock::list::*} < 7:
    14.                         delete {stock::list::%arg 1%::*}
    15.                         set {stock::list::%arg 1%} to paper
    16.                         set {stock::list::%arg 1%::listedprice} to arg 3
    17.                         set {stock::list::%arg 1%::sellingprice} to arg 3
    18.                         set {stock::list::%arg 1%::upperlimitprice} to arg 3
    19.                         set {stock::list::%arg 1%::lowerlimitprice} to arg 3
    20.                         set {stock::list::%arg 1%::maximumvariableprice} to arg 3
    21.                         set {stock::list::%arg 1%::maximumamount} to arg 2
    22.                         set {stock::list::%arg 1%::currentamount} to arg 2
    23.                         set {stock::list::%arg 1%::history::1} to "&fNo History"
    24.                         message "{@c} You created a stock."
    25.                         message "{@c} Name : &f%arg 1%"
    26.                         message "{@c} Listed Price : &f%arg 3%원"
    27.                         message "{@c} Amount : &f%arg 2%개"
    28.             else:
    29.                 message "{@c} &f - /addstock [name] [amount] [price]"
    30.  
    31. #remove stock /delstock [name]
    32. command /delstock [<text>]:
    33.     trigger:
    34.         if player is op:
    35.             delete {stock::list::%arg 1%}
    36.             delete {stock::list::%arg 1%::*}
    37.             message "{@c} Stock was removed."
    38.                
    39. #stock's price change time (min)              
    40. command /stocktime [<integer>]:
    41.     trigger:
    42.         if player is op:
    43.             if arg 1 is set:
    44.                 set {stock::time} to arg 1
    45.                 broadcast "{@c} You changed it to %arg 1%minutes."
    46.                 broadcast "{@c} It will apply at next price change."
    47.             else:
    48.                 message "&f - /stocktime [min]"
    49.  
    50. #open stock list
    51. command /stocklist:
    52.     trigger:
    53.         set {_a} to 0
    54.         set {_b} to 17
    55.         open chest with 3 rows named "&6Stock List" to player
    56.         while inventory name of current inventory of player is "&6Stock List":
    57.             set {_a} to 0
    58.             set {_b} to 17
    59.             loop 10 times:
    60.                 if {_a} is not 4:
    61.                     set slot {_a} {@s} white stained glass pane
    62.                 set slot {_b} {@s} white stained glass pane
    63.                 add 1 to {_a}
    64.                 add 1 to {_b}
    65.             set {_c} to 10
    66.             loop {stock::list::*}:
    67.                 if {_c} < 17:
    68.                     set slot {_c} {@s} loop-value named "&6%loop-index%" with lore " " and "&6[Remaining Shares]" and "&f▶ %{stock::list::%loop-index%::currentamount}%/%{stock::list::%loop-index%::maximumamount}%개" and " " and "&6[Price Info]" and "&e▶ Listed Price : %{stock::list::%loop-index%::listedprice}%" and "&f▶ sellingprice : %{stock::list::%loop-index%::sellingprice}%$" and "&a▶ Upper Limit Price : ▲%{stock::list::%loop-index%::upperlimitprice}%$" and "&c▶ Lower Limit Price : ▼%{stock::list::%loop-index%::lowerlimitprice}%$" and " " and "&6[history]" and {stock::list::%loop-index%::history::*}
    69.                     add 1 to {_c}
    70.             set slot 4 {@s} dark oak sign named "&6Next changes" with lore "&f%{stock::time::minute}%minute &f%{stock::time::second}%second"
    71.             wait 1 tick
    72.  
    73.  
    74. every 1 second:
    75.     if {stock::time} is set:
    76.         if {stock::time::minute} is set:
    77.             if {stock::time::second} is not set:
    78.                 subtract 1 from {stock::time::minute}
    79.                 set {stock::time::second} to 59
    80.             else:
    81.                 if {stock::time::second} > -1:
    82.                     subtract 1 from {stock::time::second}
    83.                 if {stock::time::second} = -1:
    84.                     if {stock::time::minute} >= 0:
    85.                         subtract 1 from {stock::time::minute}
    86.                         set {stock::time::second} to 59
    87.                     if {stock::time::minute} = -1:
    88.                         set {stock::time::minute} to {stock::time}-1
    89.                         set {stock::time::done} to true
    90.                         execute console command "stockprice"
    91.         else:
    92.             set {stock::time::min} to {stock::time}
    93.  
    94. #stock price change      
    95. command /stockprice:
    96.     trigger:
    97.         if {stock::time::done} is true:
    98.             delete {stock::time::done}
    99.             set {_a} to 1
    100.             loop {stock::list::*}:
    101.                 set {_maximumvariableprice} to {stock::list::%loop-index%::maximumvariableprice}
    102.                 chance of 50%:
    103.                     set {_variableprice} to random integer between 1 and {_maximumvariableprice}
    104.                     add {_variableprice} to {stock::list::%loop-index%::sellingprice}
    105.                     if {stock::list::%loop-index%::sellingprice} > {stock::list::%loop-index%::upperlimitprice}:
    106.                         set {stock::list::%loop-index%::upperlimitprice} to {stock::list::%loop-index%::sellingprice}
    107.                     set {_b} to 9
    108.                     if {stock::list::%loop-index%::history::1} is not "&fNo History":
    109.                         loop 9 times:
    110.                             set {_c} to {_b}+1
    111.                             set {stock::list::%loop-index%::history::%{_c}%} to {stock::list::%loop-index%::history::%{_b}%}
    112.                             subtract 1 from {_b}
    113.                         set {stock::list::%loop-index%::history::1} to "&a▲%{_variableprice}%$"
    114.                     else:
    115.                         set {stock::list::%loop-index%::history::1} to "&a▲%{_variableprice}%$"
    116.                 else:
    117.                     set {_variableprice} to random integer between 1 and {stock::list::%loop-index%::sellingprice}
    118.                     subtract {_variableprice} from {stock::list::%loop-index%::sellingprice}
    119.                     if {stock::list::%loop-index%::sellingprice} < {stock::list::%loop-index%::lowerlimitprice}:
    120.                         set {stock::list::%loop-index%::lowerlimitprice} to {stock::list::%loop-index%::sellingprice}
    121.                     set {_b} to 9
    122.                     if {stock::list::%loop-index%::history::1} is not "&fNo History":
    123.                         loop 9 times:
    124.                             set {_c} to {_b}+1
    125.                             set {stock::list::%loop-index%::history::%{_c}%} to {stock::list::%loop-index%::history::%{_b}%}
    126.                             subtract 1 from {_b}
    127.                         set {stock::list::%loop-index%::history::1} to "&c▼%{_variableprice}%$"
    128.                     else:
    129.                         set {stock::list::%loop-index%::history::1} to "&c▼%{_variableprice}%$"
    130.             broadcast "{@c} Stock Price Changed!"
    131.        
    132. #selling or buying stock
    133. on inventory click:
    134.     if iname contains "&6Stock List":
    135.         if clicked raw slot is between 10 and 16:
    136.             cancel event
    137.             loop {stock::list::*}:
    138.                 if name of clicked item contains loop-index:
    139.                     if click type is right mouse button:
    140.                         if {stock::list::%loop-index%::currentamount} >= 1:
    141.                             if player has space for 1 of loop-value named loop-index:
    142.                                 if {money.%uuid of player%} >= {stock::list::%loop-index%::sellingprice}:
    143.                                     subtract 1 from {stock::list::%loop-index%::currentamount}
    144.                                     subtract {stock::list::%loop-index%::sellingprice} from {money.%uuid of player%}
    145.                                     give player 1 of loop-value named "&6%loop-index%"
    146.                     if click type is right mouse button with shift:
    147.                         if {stock::list::%loop-index%::currentamount} >= 10:
    148.                             if player has space for 10 of loop-value named loop-index:
    149.                                 if {money.%uuid of player%} >= {stock::list::%loop-index%::}*10:
    150.                                     subtract 10 from {stock::list::%loop-index%::currentamount}
    151.                                     subtract {stock::list::%loop-index%::sellingprice}*10 from {money.%uuid of player%}
    152.                                     give player 10 of loop-value named "&6%loop-index%"
    153.                     if click type is left mouse button:
    154.                         if player has 1 of loop-value named "&6%loop-index%":
    155.                             add 1 to {stock::list::%loop-index%::currentamount}
    156.                             add {stock::list::%loop-index%::sellingprice} to {money.%uuid of player%}
    157.                             remove 1 of loop-value named "&6%loop-index%" from player's inventory
    158.                     if click type is left mouse button with shift:
    159.                         if player has 10 of loop-value named "&6%loop-index%":
    160.                             add 10 to {stock::list::%loop-index%::currentamount}
    161.                             add {stock::list::%loop-index%::sellingprice}*10 to {money.%uuid of player%}
    162.                             remove 10 of loop-value named "&6%loop-index%" from player's inventory
    163.         else:
    164.             cancel event
    165.            
    166. command /clearstock:
    167.     trigger:
    168.         delete {stock::*}
    169.        
    170.        
    171.  
    172.            
    173.            
    174.            
    175.        
    So I got this skript, but it doesn't work.
    What should I change.
    In 1.13+ you cannot get the title name of an inventory outside of an InventoryClickEvent. Only if this inventory has an InventoryHolder may it be used in this state.
     
  2. Marc

    Marc Active Member

    Joined:
    Nov 27, 2020
    Messages:
    94
    Likes Received:
    0
    What are you trying to do? we're not mind readers
     
  3. Ter2FIc

    Ter2FIc Member

    Joined:
    Dec 30, 2020
    Messages:
    20
    Likes Received:
    0
    I am trying to make stock system, and something was wrong there cuz the gui had nothing in there. It should display some items there. It was about line 134; which is the source of problem.
     
  4. Marc

    Marc Active Member

    Joined:
    Nov 27, 2020
    Messages:
    94
    Likes Received:
    0
    Im not qualified enough to attempt to even try making these so I cant help you

    good luck tho
    ~Marc
     
  5. FireRoz

    FireRoz Active Member

    Joined:
    May 28, 2020
    Messages:
    135
    Likes Received:
    6
    can you add a
    wait 3 ticks
    before doing like the open chest with 3 rows or somethingh...
    this code is really big so it requires to wait a little
     
  6. MinecraftMatthew

    MinecraftMatthew New Member

    Joined:
    Feb 3, 2021
    Messages:
    9
    Likes Received:
    2
    I am assuming the error is coming from line 56, "while inventory name of current inventory of player is "&6Stock List":"

    Unfortunately as the error says you can only get the current inventory's name when you're inside of an "on inventory click" trigger. If you want to continuously loop as long as the player has the inventory open, try setting a variable like {instockinventory.%player%}, defaulting to false, and set it to true when you open the inventory to the player. Then use "on inventory close: set {instockinventory.%player%} to false" to make it so that {instockinventory.%player%} is true if and only if the player is in the opened inventory.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...