Solved function not working

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

HYPExMon5ter

Member
Jan 26, 2017
15
10
3
23
United States
code_language.skript:
command /shop:
    trigger:
        if player has permission "os.shop":
            wait 3 ticks
            open chest with 1 row named "                 &aShop" to player
            format slot 4 of player with grass named "&d&lBlocks" to close then run [invoke "blockshop" from player]
        else:
            send "under construction."

sub "blockshop":
    set {_p} to parameter 1
    wait 3 ticks
    open chest with 1 row named "             &d&lBlock shop" to {_p}
    format slot 0 of {_p} with grass named "&dGrass" to run [buyFromShop(player, grass, 64, 1)]#be unstealable #run [make player execute command "/"]

function buyFromShop(fp: player, b: block, a: integer, price: integer):
    set {_fp} to {_fp} parsed as a player
    if {_fp} has {_price} diamonds:
        remove {_price} diamonds from {_fp}'s inventory
        give {_fp} {_a} {_block}
        send "Success" to {_fp}
    else:
        send "Nah" to {_fp}
Why wont this work? Please help!
Error:
b42abef3b3431576b007804f0c215922.png

[doublepost=1485655881,1485652453][/doublepost]
code_language.skript:
command /shop:
    trigger:
        if player has permission "os.shop":
            wait 3 ticks
            open chest with 1 row named "                 &aShop" to player
            format slot 4 of player with grass named "&d&lBlocks" to close then run [invoke "blockshop" from player]
        else:
            send "under construction."

sub "blockshop":
    set {_p} to parameter 1
    wait 3 ticks
    open chest with 1 row named "             &d&lBlock shop" to {_p}
    format slot 0 of {_p} with grass named "&dGrass" to run [buyFromShop(player, grass, 64, 1)]#be unstealable #run [make player execute command "/"]

function buyFromShop(fp: player, b: block, a: integer, price: integer):
    set {_fp} to {_fp} parsed as a player
    if {_fp} has {_price} diamonds:
        remove {_price} diamonds from {_fp}'s inventory
        give {_fp} {_a} {_block}
        send "Success" to {_fp}
    else:
        send "Nah" to {_fp}
Why wont this work? Please help!
Error:
b42abef3b3431576b007804f0c215922.png
Anyone?
 
You've waited an hour, give it some time and someone will answer. If someone doesn't answer within 24 hours, then you can "bumb" your thread.
 
code_language.skript:
remove {_price} of diamonds from {_fp}'s inventory
        give {_fp} {_a} of {_block}

Try this, for some reason giving item and removing item thru variables require you to add "of" between the amount and the item.
 
code_language.skript:
remove {_price} of diamonds from {_fp}'s inventory
        give {_fp} {_a} of {_block}

Try this, for some reason giving item and removing item thru variables require you to add "of" between the amount and the item.
well no errors now but it doesn't work :emoji_astonished:
[doublepost=1485663602,1485663142][/doublepost]new code:
code_language.skript:
command /shop:
    trigger:
        if player has permission "os.shop":
            wait 3 ticks
            open chest with 1 row named "                 &aShop" to player
            format slot 4 of player with grass named "&d&lBlocks" to close then run [invoke "blockshop" from player]
        else:
            send "under construction."

sub "blockshop":
    set {_p} to parameter 1
    wait 3 ticks
    open chest with 1 row named "             &d&lBlock shop" to {_p}
    format slot 0 of {_p} with grass named "&dGrass" to run [buyFromShop(player, grass, 64, 1)]#be unstealable #run [make player execute command "/"]

function buyFromShop(fp: player, b: block, a: integer, price: integer):
    set {_fp} to {_fp} parsed as a player
    if {_fp} has {_price} of diamonds:
        remove {_price} of diamonds from {_fp}'s inventory
        give {_fp} {_a} of {_block}
        send "Success" to {_fp}
    else:
        send "Nah" to {_fp}
 
well no errors now but it doesn't work :emoji_astonished:
[doublepost=1485663602,1485663142][/doublepost]new code:
code_language.skript:
command /shop:
    trigger:
        if player has permission "os.shop":
            wait 3 ticks
            open chest with 1 row named "                 &aShop" to player
            format slot 4 of player with grass named "&d&lBlocks" to close then run [invoke "blockshop" from player]
        else:
            send "under construction."

sub "blockshop":
    set {_p} to parameter 1
    wait 3 ticks
    open chest with 1 row named "             &d&lBlock shop" to {_p}
    format slot 0 of {_p} with grass named "&dGrass" to run [buyFromShop(player, grass, 64, 1)]#be unstealable #run [make player execute command "/"]

function buyFromShop(fp: player, b: block, a: integer, price: integer):
    set {_fp} to {_fp} parsed as a player
    if {_fp} has {_price} of diamonds:
        remove {_price} of diamonds from {_fp}'s inventory
        give {_fp} {_a} of {_block}
        send "Success" to {_fp}
    else:
        send "Nah" to {_fp}

Seems to be problem of trying to call the function directly through the format slot effect. I have never called a function directly like that so I'm not sure if that even works.
 
Well, how else would I go about doing this?
What I normally do is to make player run a hidden command through the chest GUI so let's say, "/buyfromshop <item> <amount>" and the command will be given OP permission so no one will be able to access it whenever they want. The chest GUI will execute console command "/sudo %player% buyfromshop <item> <amount>" which it will give override access to the command and let the user use it. Hope I explained well.
 
What I normally do is to make player run a hidden command through the chest GUI so let's say, "/buyfromshop <item> <amount>" and the command will be given OP permission so no one will be able to access it whenever they want. The chest GUI will execute console command "/sudo %player% buyfromshop <item> <amount>" which it will give override access to the command and let the user use it. Hope I explained well.
Ah okay, I'll test it.. thanks :emoji_slight_smile:
[doublepost=1485707939,1485704343][/doublepost]
What I normally do is to make player run a hidden command through the chest GUI so let's say, "/buyfromshop <item> <amount>" and the command will be given OP permission so no one will be able to access it whenever they want. The chest GUI will execute console command "/sudo %player% buyfromshop <item> <amount>" which it will give override access to the command and let the user use it. Hope I explained well.
It works, thank you!
 
Ah okay, I'll test it.. thanks :emoji_slight_smile:
[doublepost=1485707939,1485704343][/doublepost]
It works, thank you!
I understand that you have found a solution to your problem, but that isn't the best way to do it, as that allows for unnecessary commands and the use of format slot, which isn't the best option for GUIs.

I would suggest using set slot to format your GUIs. For example, something like:
code_language.skript:
set slot 5 of player's current inventory to stone named "&7Hey" with lore "Heyyyy"

Then, you would use the on inventory click event to trigger certain functions.
For example:
code_language.skript:
on inventory click:
    if inventory name of player's current inventory is " "
    # Check the name of the player's inventory against a value.
    # Replace the spaces with the name of your inventory. For example, "&9Shop."
        if clicked slot is 44:
        # Check the slot the player clicked against a value.
            doStuff(player)
Will this, you can also check against and grab the name and lore of the item that the player clicked. You could also build your function directly into the inventory click event.
 
  • Like
Reactions: HYPExMon5ter
I understand that you have found a solution to your problem, but that isn't the best way to do it, as that allows for unnecessary commands and the use of format slot, which isn't the best option for GUIs.

I would suggest using set slot to format your GUIs. For example, something like:
code_language.skript:
set slot 5 of player's current inventory to stone named "&7Hey" with lore "Heyyyy"

Then, you would use the on inventory click event to trigger certain functions.
For example:
code_language.skript:
on inventory click:
    if inventory name of player's current inventory is " "
    # Check the name of the player's inventory against a value.
    # Replace the spaces with the name of your inventory. For example, "&9Shop."
        if clicked slot is 44:
        # Check the slot the player clicked against a value.
            doStuff(player)
Will this, you can also check against and grab the name and lore of the item that the player clicked. You could also build your function directly into the inventory click event.
Hmm, thank you for that information :emoji_grinning:
 
Status
Not open for further replies.