Set message as a number then add it into a function

  • 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 community!

    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!

wrymain

Member
Feb 20, 2025
37
0
6
So i want to make a buy feature where the player type their own numbers via message, the function work properly but i cant make the message part work. i'm stuck with this code:

Python:
#Buy Function
function buy(p: player, amount: number, price: number, item: item):

    if {_price} > balance of {_p}:
        send "&cYou don't have enough money!" to {_p}
        stop
        
    else:
        remove {_price} * {_amount} from balance of {_p}
        give {_amount} of {_item} to {_p}
        send "&7You bought %{_amount}% %{_item}% for $%{_price}%" to {_p}

#Defining {_message}
on chat:
    set {_message} to message

#Creating the GUI
on load:
    create a new gui with id "reworkshop" with virtual chest inventory with 2 rows named "reworkedshop" and shape "xxxabcxxx" and "xxxdefxxx":
        make gui slot "a" with dirt named "Blocks":
            open gui with id "blocks" for player

    create a new gui with id "blocks" with virtual chest inventory with 2 rows named "Blocks" and shape "xxxabcxxx" and "xxxdefxxx":
        make gui slot "a" with dirt named "Dirt":
            create a new gui with virtual chest inventory with 1 row named "Buy or Sell" and shape "xxxaxbxxx":
                make gui slot "a" with dirt named "Buy":
                    create a new gui with virtual chest inventory with 1 row named "Buy" and shape "xaxxbxxcx":


                        #The Button for 1 stack
                        make gui slot "a" with dirt named "Buy 1 Stack":
                            buy(player, 64, 1, (Dirt))

                        #The Button for 1 item
                        make gui slot "b" with dirt named "Buy 1":
                            buy(player, 1, 1, (Dirt))

                        #The Button for custom to type the amount
                        make gui slot "c" with oak sign named "Custom":
                            close player's inventory
                            send "&7Type the amount of items you want to buy."
                            if {_message} is a number:
                                cancel event
                                add {_message} parsed as number to {_amount}
                                buy(player, {_amount}, 1, (Dirt))

                    open the last gui for player
            open the last gui for player

#The Command to open the GUI
command /reworkshop:
    trigger:
        open gui with id "reworkshop" for player

i was going to make it via sign but too much work.
 
I was reading thru it, and why do you not have definitions for some of the item slots? also you already have parsed as number in your code