Player currently holding?

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

Status
Not open for further replies.

kasper227232

Member
Feb 25, 2017
14
0
0
Hello SkUnity Forum,

I'm currently doing the following
code_language.skript:
while amount of string in player's inventory is bigger than 0:
            remove 1 string from player's inventory
            add 5 to {pointsell::%player%}
but I want to check if the player is currently holding string, and then sell it + selling all the string in the rest of his inventory, but I can't find any method that does this.
 
Here you go, I hope this is what you were after:
Code:
every 1 second:
    loop all players:
        loop-player is holding 1 string
        Send "You sold %number of string in loop-player's inventory% string to the shop." to loop-player
        set {_StringCount.%loop-player%} to number of string in loop-player's inventory
        add {_StringCount.%loop-player%} * 5 to {pointsell::%loop-player%}
        remove all string from the loop-player
       
command /points:
    trigger:
        send "You have %{pointsell::%player%}% points."

If you just want 1 point to be added per string then change
Code:
add {_StringCount.%loop-player%} * 5 to {pointsell::%loop-player%}

to

Code:
add {_StringCount.%loop-player%} to {pointsell::%loop-player%}
 
  • Like
Reactions: Dylan The Beast
Here you go, I hope this is what you were after:
Code:
every 1 second:
    loop all players:
        loop-player is holding 1 string
        Send "You sold %number of string in loop-player's inventory% string to the shop." to loop-player
        set {_StringCount.%loop-player%} to number of string in loop-player's inventory
        add {_StringCount.%loop-player%} * 5 to {pointsell::%loop-player%}
        remove all string from the loop-player
      
command /points:
    trigger:
        send "You have %{pointsell::%player%}% points."

If you just want 1 point to be added per string then change
Code:
add {_StringCount.%loop-player%} * 5 to {pointsell::%loop-player%}

to

Code:
add {_StringCount.%loop-player%} to {pointsell::%loop-player%}


This is kinda what I am looking for, but it has to be ran via a command, so let's say that the player is holding 64 string and has 128 string in his inventory, when he types /sell it removes all the string and adds the points to him.

That's my fault sorry :emoji_stuck_out_tongue: I didn't add enough information.
 
This is kinda what I am looking for, but it has to be ran via a command, so let's say that the player is holding 64 string and has 128 string in his inventory, when he types /sell it removes all the string and adds the points to him.

That's my fault sorry :emoji_stuck_out_tongue: I didn't add enough information.

Thats an easy fix. Ill do that now.
[doublepost=1488585577,1488585505][/doublepost]Here you go:

Code:
command /sell:
    trigger:
        loop all players:
            loop-player is holding 1 string
            Send "You sold %number of string in loop-player's inventory% string to the shop." to loop-player
            set {_StringCount.%loop-player%} to number of string in loop-player's inventory
            add {_StringCount.%loop-player%} to {pointsell::%loop-player%}
            remove all string from the loop-player
 
  • Like
Reactions: Dylan The Beast
Thats an easy fix. Ill do that now.
[doublepost=1488585577,1488585505][/doublepost]Here you go:

Code:
command /sell:
    trigger:
        loop all players:
            loop-player is holding 1 string
            Send "You sold %number of string in loop-player's inventory% string to the shop." to loop-player
            set {_StringCount.%loop-player%} to number of string in loop-player's inventory
            add {_StringCount.%loop-player%} to {pointsell::%loop-player%}
            remove all string from the loop-player


Perfect, that works :emoji_grinning:
Now, I knew how to do this before hand, but I havn't touched Skript in a while, but I want to store all the item names and prices in a variable, and depending on the item he is currently holding, he will sell that item for the set price.
Is that something you can help me with aswell? :emoji_grinning:
 
If you want you could do something like this:

Code:
options:
    String Price: 2
    Dirt Price: 1


command /sell:
    trigger:
        loop all players:
            if loop-player is holding 1 string:
                Send "You sold %number of string in loop-player's inventory% string to the shop for {@String Price} point each." to loop-player
                set {_StringCount.%loop-player%} to number of string in loop-player's inventory
                add {_StringCount.%loop-player%} * {@String Price} to {pointsell::%loop-player%}
                remove all string from the loop-player
            if loop-player is holding 1 dirt:
                Send "You sold %number of dirt in loop-player's inventory% dirt to the shop for {@Dirt Price} point each." to loop-player
                set {_DirtCount.%loop-player%} to number of dirt in loop-player's inventory
                add {_DirtCount.%loop-player%} * {@Dirt Price} to {pointsell::%loop-player%}
                remove all dirt from the loop-player
 
  • Like
Reactions: Dylan The Beast
If you want you could do something like this:

Code:
options:
    String Price: 2
    Dirt Price: 1


command /sell:
    trigger:
        loop all players:
            if loop-player is holding 1 string:
                Send "You sold %number of string in loop-player's inventory% string to the shop for {@String Price} point each." to loop-player
                set {_StringCount.%loop-player%} to number of string in loop-player's inventory
                add {_StringCount.%loop-player%} * {@String Price} to {pointsell::%loop-player%}
                remove all string from the loop-player
            if loop-player is holding 1 dirt:
                Send "You sold %number of dirt in loop-player's inventory% dirt to the shop for {@Dirt Price} point each." to loop-player
                set {_DirtCount.%loop-player%} to number of dirt in loop-player's inventory
                add {_DirtCount.%loop-player%} * {@Dirt Price} to {pointsell::%loop-player%}
                remove all dirt from the loop-player


I know, that's just a pain in the ass way to do it, and a lot of unessecary lines.
 
Ill work on another way if i can find out how to. Also please change the code to:
Code:
command /sell:
    trigger:
        if player is holding 1 string:
            Send "You sold %number of string in player's inventory% string to the shop." to player
            set {_StringCount.%player%} to number of string in player's inventory
            add {_StringCount.%player%} to {pointsell::%player%}
            remove all string from the player

The other code is looping all the players and selling for all of them.
 
  • Like
Reactions: Dylan The Beast
Status
Not open for further replies.