Sell Function Help

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

Squidddle

Member
Jun 12, 2018
1
0
0
22
I've been skripting for about a year now and im just now trying to start with functions in skript. Im trying to get a hold of it without asking a whole lot of questions but can't seem to find what im looking for when i look it up on google. Just creating little functions just to get a hang of them and this im just confused with what im trying currently... it seems like it should work but doesn't work right.

code_language.skript:
options:
    ShopNotEnough: Not Enough
    NB: New Balance
    prefix: prefix
        
function Buy(p: player, bal: number, item: item, bv: number , amount: integer):
    if {_p}'s balance is less than {_bal}:
        send "{@ShopNotEnough}" to {_p}
    else:
        remove ({_bv} * {_amount}) from {_p}'s balance
        give {_p} {_amount} of {_item}
        send "{@prefix} &aYou have purchased %{_amount}% %{_item}%. {@NB}" to {_p}

function Sell(p: player, item: item, sv: number, amount: integer):
    if {_p} has {_amount} of {_item}:
        remove {_amount} of {_item} from {_p}
        add ({_sv} * {_amount}) to {_p}'s balance
        send "{@prefix} &aYou have sold %{_amount}% %{_item}%. {@NB}" to {_p}
    else:
        send "{@prefix} &cYou do not have %{_amount}% %{_item}% to sell." to {_p}
    
on script load:
    create a gui with id "TM" with virtual chest with 3 rows named "&eTest":
        make gui slot 0 with wheat item  named "&aWheat" with lore "&eThis is buyable":
            if gui-click-action is left mouse button:
                Buy(player, 100, wheat item, 10.00, 8)
            if gui-click-action is right mouse button:
                Sell(player, wheat item, 1.25, 8)
        
command /testmenu:
    trigger:
        open gui "TM" to player

I get no errors from any of it. there's probably parts of it i could do better, but that's what i'm here trying to do.

The Buy function works fine, but the Sell Function not so much. i'm probably over looking something hardcore but i can have the specified item in my inventory and even held it to see if that'd help, it just keeps saying i don't have any of that item in my inventory(in this example, wheat). Help is much appreciated, i'm sorry if it was something simple and i wasted you time.

If you have any suggestions how i should do it better, please say them, im am always up to improving how i can do things.

Skript Version : 2.2-dev37c
Skript Addons :
Tuske v1.8.2(a pikachu fork i believe, i dont remember)
skRayFall v1.9.14
SharpSk v1.6.3
 
Change
code_language.skript:
if {_p} has {_amount} of {_item}:
to
code_language.skript:
if {_p}'s inventory has {_amount} of {_item}:
 
Status
Not open for further replies.