Stock

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

Ter2FIc

Member
Dec 30, 2020
20
0
1
24
Code:
options:
    c : &6[&eStock&6]&f
    s : of current inventory of player to
    s2 : of current inventory of loop-player to
    
#create stock /addstock [name] [amount] [price]
command /addstock [<text>] [<number>] [<number>]:
    trigger:
        if player is op:
            if arg 1 is set:
                if arg 2 is set:
                    if size of {stock::list::*} < 7:
                        delete {stock::list::%arg 1%::*}
                        set {stock::list::%arg 1%} to paper
                        set {stock::list::%arg 1%::listedprice} to arg 3
                        set {stock::list::%arg 1%::sellingprice} to arg 3
                        set {stock::list::%arg 1%::upperlimitprice} to arg 3
                        set {stock::list::%arg 1%::lowerlimitprice} to arg 3
                        set {stock::list::%arg 1%::maximumvariableprice} to arg 3
                        set {stock::list::%arg 1%::maximumamount} to arg 2
                        set {stock::list::%arg 1%::currentamount} to arg 2
                        set {stock::list::%arg 1%::history::1} to "&fNo History"
                        message "{@c} You created a stock."
                        message "{@c} Name : &f%arg 1%"
                        message "{@c} Listed Price : &f%arg 3%원"
                        message "{@c} Amount : &f%arg 2%개"
            else:
                message "{@c} &f - /addstock [name] [amount] [price]"

#remove stock /delstock [name]
command /delstock [<text>]:
    trigger:
        if player is op:
            delete {stock::list::%arg 1%}
            delete {stock::list::%arg 1%::*}
            message "{@c} Stock was removed."
                
#stock's price change time (min)               
command /stocktime [<integer>]:
    trigger:
        if player is op:
            if arg 1 is set:
                set {stock::time} to arg 1
                broadcast "{@c} You changed it to %arg 1%minutes."
                broadcast "{@c} It will apply at next price change."
            else:
                message "&f - /stocktime [min]"

#open stock list
command /stocklist:
    trigger:
        set {_a} to 0
        set {_b} to 17
        open chest with 3 rows named "&6Stock List" to player
        while inventory name of current inventory of player is "&6Stock List":
            set {_a} to 0
            set {_b} to 17
            loop 10 times:
                if {_a} is not 4:
                    set slot {_a} {@s} white stained glass pane
                set slot {_b} {@s} white stained glass pane
                add 1 to {_a}
                add 1 to {_b}
            set {_c} to 10
            loop {stock::list::*}:
                if {_c} < 17:
                    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::*}
                    add 1 to {_c}
            set slot 4 {@s} dark oak sign named "&6Next changes" with lore "&f%{stock::time::minute}%minute &f%{stock::time::second}%second"
            wait 1 tick


every 1 second:
    if {stock::time} is set:
        if {stock::time::minute} is set:
            if {stock::time::second} is not set:
                subtract 1 from {stock::time::minute}
                set {stock::time::second} to 59
            else:
                if {stock::time::second} > -1:
                    subtract 1 from {stock::time::second}
                if {stock::time::second} = -1:
                    if {stock::time::minute} >= 0:
                        subtract 1 from {stock::time::minute}
                        set {stock::time::second} to 59
                    if {stock::time::minute} = -1:
                        set {stock::time::minute} to {stock::time}-1
                        set {stock::time::done} to true
                        execute console command "stockprice"
        else:
            set {stock::time::min} to {stock::time}

#stock price change       
command /stockprice:
    trigger:
        if {stock::time::done} is true:
            delete {stock::time::done}
            set {_a} to 1
            loop {stock::list::*}:
                set {_maximumvariableprice} to {stock::list::%loop-index%::maximumvariableprice}
                chance of 50%:
                    set {_variableprice} to random integer between 1 and {_maximumvariableprice}
                    add {_variableprice} to {stock::list::%loop-index%::sellingprice}
                    if {stock::list::%loop-index%::sellingprice} > {stock::list::%loop-index%::upperlimitprice}:
                        set {stock::list::%loop-index%::upperlimitprice} to {stock::list::%loop-index%::sellingprice}
                    set {_b} to 9
                    if {stock::list::%loop-index%::history::1} is not "&fNo History":
                        loop 9 times:
                            set {_c} to {_b}+1
                            set {stock::list::%loop-index%::history::%{_c}%} to {stock::list::%loop-index%::history::%{_b}%}
                            subtract 1 from {_b}
                        set {stock::list::%loop-index%::history::1} to "&a▲%{_variableprice}%$"
                    else:
                        set {stock::list::%loop-index%::history::1} to "&a▲%{_variableprice}%$"
                else:
                    set {_variableprice} to random integer between 1 and {stock::list::%loop-index%::sellingprice}
                    subtract {_variableprice} from {stock::list::%loop-index%::sellingprice}
                    if {stock::list::%loop-index%::sellingprice} < {stock::list::%loop-index%::lowerlimitprice}:
                        set {stock::list::%loop-index%::lowerlimitprice} to {stock::list::%loop-index%::sellingprice}
                    set {_b} to 9
                    if {stock::list::%loop-index%::history::1} is not "&fNo History":
                        loop 9 times:
                            set {_c} to {_b}+1
                            set {stock::list::%loop-index%::history::%{_c}%} to {stock::list::%loop-index%::history::%{_b}%}
                            subtract 1 from {_b}
                        set {stock::list::%loop-index%::history::1} to "&c▼%{_variableprice}%$"
                    else:
                        set {stock::list::%loop-index%::history::1} to "&c▼%{_variableprice}%$"
            broadcast "{@c} Stock Price Changed!"
        
#selling or buying stock
on inventory click:
    if iname contains "&6Stock List":
        if clicked raw slot is between 10 and 16:
            cancel event
            loop {stock::list::*}:
                if name of clicked item contains loop-index:
                    if click type is right mouse button:
                        if {stock::list::%loop-index%::currentamount} >= 1:
                            if player has space for 1 of loop-value named loop-index:
                                if {money.%uuid of player%} >= {stock::list::%loop-index%::sellingprice}:
                                    subtract 1 from {stock::list::%loop-index%::currentamount}
                                    subtract {stock::list::%loop-index%::sellingprice} from {money.%uuid of player%}
                                    give player 1 of loop-value named "&6%loop-index%"
                    if click type is right mouse button with shift:
                        if {stock::list::%loop-index%::currentamount} >= 10:
                            if player has space for 10 of loop-value named loop-index:
                                if {money.%uuid of player%} >= {stock::list::%loop-index%::}*10:
                                    subtract 10 from {stock::list::%loop-index%::currentamount}
                                    subtract {stock::list::%loop-index%::sellingprice}*10 from {money.%uuid of player%}
                                    give player 10 of loop-value named "&6%loop-index%"
                    if click type is left mouse button:
                        if player has 1 of loop-value named "&6%loop-index%":
                            add 1 to {stock::list::%loop-index%::currentamount}
                            add {stock::list::%loop-index%::sellingprice} to {money.%uuid of player%}
                            remove 1 of loop-value named "&6%loop-index%" from player's inventory
                    if click type is left mouse button with shift:
                        if player has 10 of loop-value named "&6%loop-index%":
                            add 10 to {stock::list::%loop-index%::currentamount}
                            add {stock::list::%loop-index%::sellingprice}*10 to {money.%uuid of player%}
                            remove 10 of loop-value named "&6%loop-index%" from player's inventory
        else:
            cancel event
            
command /clearstock:
    trigger:
        delete {stock::*}
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.
 
What are you trying to do? we're not mind readers
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.
 
Im not qualified enough to attempt to even try making these so I cant help you

good luck tho
~Marc
 
Code:
options:
    c : &6[&eStock&6]&f
    s : of current inventory of player to
    s2 : of current inventory of loop-player to
   
#create stock /addstock [name] [amount] [price]
command /addstock [<text>] [<number>] [<number>]:
    trigger:
        if player is op:
            if arg 1 is set:
                if arg 2 is set:
                    if size of {stock::list::*} < 7:
                        delete {stock::list::%arg 1%::*}
                        set {stock::list::%arg 1%} to paper
                        set {stock::list::%arg 1%::listedprice} to arg 3
                        set {stock::list::%arg 1%::sellingprice} to arg 3
                        set {stock::list::%arg 1%::upperlimitprice} to arg 3
                        set {stock::list::%arg 1%::lowerlimitprice} to arg 3
                        set {stock::list::%arg 1%::maximumvariableprice} to arg 3
                        set {stock::list::%arg 1%::maximumamount} to arg 2
                        set {stock::list::%arg 1%::currentamount} to arg 2
                        set {stock::list::%arg 1%::history::1} to "&fNo History"
                        message "{@c} You created a stock."
                        message "{@c} Name : &f%arg 1%"
                        message "{@c} Listed Price : &f%arg 3%원"
                        message "{@c} Amount : &f%arg 2%개"
            else:
                message "{@c} &f - /addstock [name] [amount] [price]"

#remove stock /delstock [name]
command /delstock [<text>]:
    trigger:
        if player is op:
            delete {stock::list::%arg 1%}
            delete {stock::list::%arg 1%::*}
            message "{@c} Stock was removed."
               
#stock's price change time (min)              
command /stocktime [<integer>]:
    trigger:
        if player is op:
            if arg 1 is set:
                set {stock::time} to arg 1
                broadcast "{@c} You changed it to %arg 1%minutes."
                broadcast "{@c} It will apply at next price change."
            else:
                message "&f - /stocktime [min]"

#open stock list
command /stocklist:
    trigger:
        set {_a} to 0
        set {_b} to 17
        open chest with 3 rows named "&6Stock List" to player
        while inventory name of current inventory of player is "&6Stock List":
            set {_a} to 0
            set {_b} to 17
            loop 10 times:
                if {_a} is not 4:
                    set slot {_a} {@s} white stained glass pane
                set slot {_b} {@s} white stained glass pane
                add 1 to {_a}
                add 1 to {_b}
            set {_c} to 10
            loop {stock::list::*}:
                if {_c} < 17:
                    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::*}
                    add 1 to {_c}
            set slot 4 {@s} dark oak sign named "&6Next changes" with lore "&f%{stock::time::minute}%minute &f%{stock::time::second}%second"
            wait 1 tick


every 1 second:
    if {stock::time} is set:
        if {stock::time::minute} is set:
            if {stock::time::second} is not set:
                subtract 1 from {stock::time::minute}
                set {stock::time::second} to 59
            else:
                if {stock::time::second} > -1:
                    subtract 1 from {stock::time::second}
                if {stock::time::second} = -1:
                    if {stock::time::minute} >= 0:
                        subtract 1 from {stock::time::minute}
                        set {stock::time::second} to 59
                    if {stock::time::minute} = -1:
                        set {stock::time::minute} to {stock::time}-1
                        set {stock::time::done} to true
                        execute console command "stockprice"
        else:
            set {stock::time::min} to {stock::time}

#stock price change      
command /stockprice:
    trigger:
        if {stock::time::done} is true:
            delete {stock::time::done}
            set {_a} to 1
            loop {stock::list::*}:
                set {_maximumvariableprice} to {stock::list::%loop-index%::maximumvariableprice}
                chance of 50%:
                    set {_variableprice} to random integer between 1 and {_maximumvariableprice}
                    add {_variableprice} to {stock::list::%loop-index%::sellingprice}
                    if {stock::list::%loop-index%::sellingprice} > {stock::list::%loop-index%::upperlimitprice}:
                        set {stock::list::%loop-index%::upperlimitprice} to {stock::list::%loop-index%::sellingprice}
                    set {_b} to 9
                    if {stock::list::%loop-index%::history::1} is not "&fNo History":
                        loop 9 times:
                            set {_c} to {_b}+1
                            set {stock::list::%loop-index%::history::%{_c}%} to {stock::list::%loop-index%::history::%{_b}%}
                            subtract 1 from {_b}
                        set {stock::list::%loop-index%::history::1} to "&a▲%{_variableprice}%$"
                    else:
                        set {stock::list::%loop-index%::history::1} to "&a▲%{_variableprice}%$"
                else:
                    set {_variableprice} to random integer between 1 and {stock::list::%loop-index%::sellingprice}
                    subtract {_variableprice} from {stock::list::%loop-index%::sellingprice}
                    if {stock::list::%loop-index%::sellingprice} < {stock::list::%loop-index%::lowerlimitprice}:
                        set {stock::list::%loop-index%::lowerlimitprice} to {stock::list::%loop-index%::sellingprice}
                    set {_b} to 9
                    if {stock::list::%loop-index%::history::1} is not "&fNo History":
                        loop 9 times:
                            set {_c} to {_b}+1
                            set {stock::list::%loop-index%::history::%{_c}%} to {stock::list::%loop-index%::history::%{_b}%}
                            subtract 1 from {_b}
                        set {stock::list::%loop-index%::history::1} to "&c▼%{_variableprice}%$"
                    else:
                        set {stock::list::%loop-index%::history::1} to "&c▼%{_variableprice}%$"
            broadcast "{@c} Stock Price Changed!"
       
#selling or buying stock
on inventory click:
    if iname contains "&6Stock List":
        if clicked raw slot is between 10 and 16:
            cancel event
            loop {stock::list::*}:
                if name of clicked item contains loop-index:
                    if click type is right mouse button:
                        if {stock::list::%loop-index%::currentamount} >= 1:
                            if player has space for 1 of loop-value named loop-index:
                                if {money.%uuid of player%} >= {stock::list::%loop-index%::sellingprice}:
                                    subtract 1 from {stock::list::%loop-index%::currentamount}
                                    subtract {stock::list::%loop-index%::sellingprice} from {money.%uuid of player%}
                                    give player 1 of loop-value named "&6%loop-index%"
                    if click type is right mouse button with shift:
                        if {stock::list::%loop-index%::currentamount} >= 10:
                            if player has space for 10 of loop-value named loop-index:
                                if {money.%uuid of player%} >= {stock::list::%loop-index%::}*10:
                                    subtract 10 from {stock::list::%loop-index%::currentamount}
                                    subtract {stock::list::%loop-index%::sellingprice}*10 from {money.%uuid of player%}
                                    give player 10 of loop-value named "&6%loop-index%"
                    if click type is left mouse button:
                        if player has 1 of loop-value named "&6%loop-index%":
                            add 1 to {stock::list::%loop-index%::currentamount}
                            add {stock::list::%loop-index%::sellingprice} to {money.%uuid of player%}
                            remove 1 of loop-value named "&6%loop-index%" from player's inventory
                    if click type is left mouse button with shift:
                        if player has 10 of loop-value named "&6%loop-index%":
                            add 10 to {stock::list::%loop-index%::currentamount}
                            add {stock::list::%loop-index%::sellingprice}*10 to {money.%uuid of player%}
                            remove 10 of loop-value named "&6%loop-index%" from player's inventory
        else:
            cancel event
           
command /clearstock:
    trigger:
        delete {stock::*}
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.
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
 
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.
 
Status
Not open for further replies.