1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to set a text to a variable?

Discussion in 'Skript' started by aescraft, Mar 17, 2017.

Thread Status:
Not open for further replies.
  1. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    238
    Likes Received:
    13
    Code (Skript):
    1. command /XYZ :
    2.   executable by: player
    3.   trigger:
    4.     set {_text.%player%.broadcast} to "Text: "
    5.     add "HELLO WORD," to {_text.%player%.broadcast}
    6.     add " I LOVE ICE CREAM" to {_text.%player%.broadcast}
    7.     broadcast "%{_text.%player%.broadcast}%"
    When I broadcast, the only thing broadcasted is the "Text: ", instead of "Text: HELLO WORLD, I LOVE ICE CREAM"

    What is wrong? :emoji_cold_sweat:
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    @aescraft You need to use variable list
    Code (Skript):
    1. command /xyz:
    2.     trigger:
    3.         add "HELLO WORD," to {_text.%player%.broadcast::*}
    4.         add "I LOVE ICE CREAM" to {_text.%player%.broadcast::*}
    5.         broadcast "Text: %{_text.%player%.broadcast::1}%%{_text.%player%.broadcast::2}%"
     
    #2 ShaneBee, Mar 17, 2017
    Last edited by a moderator: Mar 17, 2017
    • Winner Winner x 1
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    Thank you!

    But when I run it multiple times, it repeats the variables.
    I try to set the variable to "", but i got alot of commas.
    Is it possible to delete the variable?

    Check out the skript I am making:

    Code (Skript):
    1.  
    2. command /rolldice <integer>:
    3.   executable by: player
    4.   trigger:
    5.     set {rolldice.%player%.total} to 0
    6.     set {rolldice.%player%.count} to 0
    7.     if arg 1 isn't 1 or 2 or 3 or 4 or 5 or 6:
    8.       message "You have to roll a number between 1 and 6!"
    9.       stop
    10.     set {waited.rolldice} to difference between {rolldice.%player%.lastused} and now
    11.     if {waited.rolldice} is less than 15 minutes:
    12.       message "You have to wait"
    13.       stop
    14.     broadcast ""    
    15.     broadcast "%player% is rolling some dices:"  
    16.     loop arg 1 times:
    17.       set {random.%player%.rolldicenumber} to random integer from 1 to 6
    18.       if {random.%player%.rolldicenumber} is 1:
    19.         add "⚀" to {rolldice.%player%.dices::*}
    20.         #⚀
    21.         add 1 to {rolldice.%player%.total}
    22.         add 1 to {rolldice.%player%.count}
    23.       if {random.%player%.rolldicenumber} is 2:
    24.         add "⚁" to {rolldice.%player%.dices::*}
    25.         #⚁
    26.         add 2 to {rolldice.%player%.total}
    27.         add 1 to {rolldice.%player%.count}
    28.       if {random.%player%.rolldicenumber} is 3:
    29.         add "⚂" to {rolldice.%player%.dices::*}
    30.         #⚂
    31.         add 3 to {rolldice.%player%.total}
    32.         add 1 to {rolldice.%player%.count}
    33.       if {random.%player%.rolldicenumber} is 4:
    34.         add "⚃" to {rolldice.%player%.dices::*}
    35.         #⚃
    36.         add 4 to {rolldice.%player%.total}
    37.         add 1 to {rolldice.%player%.count}
    38.       if {random.%player%.rolldicenumber} is 5:
    39.         add "⚄" to {rolldice.%player%.dices::*}
    40.         #⚄
    41.         add 5 to {rolldice.%player%.total}
    42.         add 1 to {rolldice.%player%.count}
    43.       if {random.%player%.rolldicenumber} is 6:
    44.         add "⚅" to {rolldice.%player%.dices::*}
    45.         #⚅
    46.         add 6 to {rolldice.%player%.total}
    47.         add 1 to {rolldice.%player%.count}
    48.     broadcast "%{rolldice.%player%.dices::*}%"
    49.     broadcast "%player% rolled %arg 1% dices and got %{rolldice.%player%.total}% in total"
    50.     broadcast ""
    51.     set {rolldice.%player%.dices::*} to ""
    52.     set {rolldice.%player%.dices::1} to ""
    53.     set {rolldice.%player%.dices::2} to ""
    54.     set {rolldice.%player%.dices::3} to ""
    55.     set {rolldice.%player%.dices::4} to ""
    56.     set {rolldice.%player%.dices::5} to ""
    57.     set {rolldice.%player%.dices::6} to ""
    58.     set {rolldice.%player%.total} to "0"
    59.     set {rolldice.%player%.count} to "0"
    60.     set {list::broadcast.%player%.dice} to ""
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    @aescraft didn't understand your problem here , can you explain it better?

    EDIT:

    Fixed your problem
    Code (Skript):
    1. command /rolldice <integer>:
    2.   executable by: player
    3.   trigger:
    4.     set {rolldice.%player%.total} to 0
    5.     set {rolldice.%player%.count} to 0
    6.     if arg 1 isn't 1 or 2 or 3 or 4 or 5 or 6:
    7.       message "You have to roll a number between 1 and 6!"
    8.       stop
    9.     set {waited.rolldice} to difference between {rolldice.%player%.lastused} and now
    10.     if {waited.rolldice} is less than 15 minutes:
    11.       message "You have to wait"
    12.       stop
    13.     broadcast ""
    14.     broadcast "%player% is rolling some dices:"
    15.     loop arg 1 times:
    16.       set {random.%player%.rolldicenumber} to random integer from 1 to 6
    17.       if {random.%player%.rolldicenumber} is 1:
    18.         add "⚀" to {rolldice.%player%.dices::*}
    19.         #⚀
    20.         add 1 to {rolldice.%player%.total}
    21.         add 1 to {rolldice.%player%.count}
    22.       if {random.%player%.rolldicenumber} is 2:
    23.         add "⚁" to {rolldice.%player%.dices::*}
    24.         #⚁
    25.         add 2 to {rolldice.%player%.total}
    26.         add 1 to {rolldice.%player%.count}
    27.       if {random.%player%.rolldicenumber} is 3:
    28.         add "⚂" to {rolldice.%player%.dices::*}
    29.         #⚂
    30.         add 3 to {rolldice.%player%.total}
    31.         add 1 to {rolldice.%player%.count}
    32.       if {random.%player%.rolldicenumber} is 4:
    33.         add "⚃" to {rolldice.%player%.dices::*}
    34.         #⚃
    35.         add 4 to {rolldice.%player%.total}
    36.         add 1 to {rolldice.%player%.count}
    37.       if {random.%player%.rolldicenumber} is 5:
    38.         add "⚄" to {rolldice.%player%.dices::*}
    39.         #⚄
    40.         add 5 to {rolldice.%player%.total}
    41.         add 1 to {rolldice.%player%.count}
    42.       if {random.%player%.rolldicenumber} is 6:
    43.         add "⚅" to {rolldice.%player%.dices::*}
    44.         #⚅
    45.         add 6 to {rolldice.%player%.total}
    46.         add 1 to {rolldice.%player%.count}
    47.     broadcast "%{rolldice.%player%.dices::*}%"
    48.     broadcast "%player% rolled %arg 1% dices and got %{rolldice.%player%.total}% in total"
    49.     broadcast ""
    50.     clear {rolldice.%player%.dices::*}
    51.     clear {rolldice.%player%.total}
    52.     clear {rolldice.%player%.count}
     
    #4 ShaneBee, Mar 17, 2017
    Last edited by a moderator: Mar 17, 2017
    • Winner Winner x 1
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    @YoshYz
    Can you help me with this:
    Code (Skript):
    1. on consume of potion:
    2.   message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
    3.   add 33 to {poison.%player%.toxicity}
    4.  
    When loading, it says "cant understand this condition: 'on consume of potion' - There's no player in an on server start/stop event.

    Sorry to bother, but I'm finding it hard to find examples on how to use the on consume event.
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    You're welcome.
    Code (Skript):
    1. on consume:
    2.     event-item is 373:8196:
    3.         message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
    4.         add 33 to {poison.%player%.toxicity}
    You can use too
    Code (Skript):
    1. water_bottle:8196
    There isn't a support for potions as i know , so you need to use ids.
    Link: http://minecraft-ids.grahamedgecombe.com/potion-calculator

    I suggest you to use a custom rightclick event to make what you need

    Something like
    Code (Skript):
    1. on rightclick holding water bottle:
    2.     remove event-item from player's inventory
    3. #EFFECT
     
    #6 ShaneBee, Mar 17, 2017
    Last edited by a moderator: Mar 17, 2017
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    I assume you're running 1.9 or above? Your issue with the potion consume event is because potions now used an expression, not an item type. To detect consuming it, you have to detect bottle of water instead:

    Code (Skript):
    1. on consume of bottle of water:
     
    • Informative Informative x 1
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    I was trying to make a plugin that adds toxicity level to potions, just like in the game The Witcher.
    The problem with this is that bottle of water is not always potion (maybe is just water), and I think that give side effects to the consumption of water is wrong lol.

    I got issues with it, saying that there's no players in the event. I did not even try the potion part yet, as it's not loading for other issues.

    Code (Skript):
    1. variables:
    2.   {poison.%player%.toxicity} = 0
    3.  
    4. command /toxicity:
    5.   description: Check your potion toxicity level in blood serum!
    6.   executable by: players
    7.   trigger:
    8.     message "Your toxicity level is %{poison.%player%.toxicity}%"
    9.  
    10. on consume:
    11.   event-item is water_bottle:8196:
    12.     message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
    13.     add 33 to {poison.%player%.toxicity}
    14.  
    15. Every 1 second in "world" and "world_nether" and "world_the_end":
    16.   if {poison.%player%.toxicity} is higher than 0:
    17.     wait 30 seconds
    18.     remove 1 from {poison.%player%.toxicity}
    19.   if {poison.%player%.toxicity} is higher than integer 33:
    20.     message "Something ins't right..."
    21.     set {sideeffect.%player%.33more} to true
    22.     if {sideeffect.%player%.33more} is true:
    23.       apply potion of weakness of tier 1 to the player for 3 minutes  
    24.       apply potion of slowness of tier 1 to the player for 3 minutes
    25.       wait 3 minutes
    26.       if {sideeffect.%player%.33more} is true:
    27.         set {sideeffect.%player%.33more} to false
    28.         message "I'm starting to feel better."
    29.   if {poison.%player%.toxicity} is higher than integer 66:
    30.     wait 2 seconds
    31.     message "My body hurts..."
    32.     set {sideeffect.%player%.66more} to true
    33.     if {sideeffect.%player%.66more} is true:
    34.       wait 2 seconds
    35.       remove potion of weakness
    36.       remove potion of slowness
    37.       apply potion of weakness of tier 2 to the player for 3 minutes  
    38.       apply potion of slowness of tier 2 to the player for 3 minutes
    39.       wait 3 minutes
    40.       if {sideeffect.%player%.66more} is true:
    41.         apply potion of weakness of tier 1 to the player for 3 minutes  
    42.         apply potion of slowness of tier 1 to the player for 3 minutes
    43.         wait 3 minutes
    44.         if {sideeffect.%player%.66more} is true:
    45.           set {sideeffect.%player%.66more} to false
    46.   if {poison.%player%.toxicity} is higher than integer 89:
    47.     wait 10 seconds
    48.     message "I-I... I'm blind!?"
    49.     set {sideeffect.%player%.89more} to true
    50.     if {sideeffect.%player%.89more} is true:
    51.       apply potion of blindness of tier 3 to the player for 3 minutes
    52.       wait 3 minutes
    53.       if {sideeffect.%player%.89more} is true:
    54.         apply potion of blindness of tier 2 to the player for 2 minutes
    55.         wait 2 minutes
    56.         if {sideeffect.%player%.89more} is true:
    57.           apply potion of blindness of tier 1 to the player for 1 minute
    58.           wait 1 minute
    59.           if {sideeffect.%player%.89more} is true:
    60.             set {sideeffect.%player%.89more} to false
    61.             message "I can finally see again!"
    62.   if {poison.%player%.toxicity} is 99:
    63.     message "If I drink one more potion right now, I'll die for sure!"        
    64.   if {poison.%player%.toxicity} is higher than 99:
    65.     broadcast "✞%player% died drinking too much potion!✞"
    66.     make console execute command "kill %player%"
    67.   on consumption of milk:
    68.     set {sideeffect.%player%.89more} to false
    69.     set {sideeffect.%player%.66more} to false
    70.     set {sideeffect.%player%.33more} to false
    71.     remove all potion
    72.     set {poison.%player%.toxicity} to 0
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    Code (Skript):
    1. water_bottle:8196
    This won't work on 1.9. Again, potions don't use data values anymore, they use NBT. I'm not sure what's causing your error, but your code isn't going to work regardless as you have it written. If you're on 1.9 or higher and using Bensku's fork the code should say something like:

    Code (Skript):
    1. on consume of bottle of water:
    2.   player's tool is potion of poison
    3.   message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
    4.   add 33 to {poison.%player%.toxicity}
    I am able to use the 'player' expression fine in this event so it's something on your end or an error resulting as a byproduct of the other issues I've pointed out in your event code.
     
    • Informative Informative x 1
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    The error I'm having is with the "if {poison.%player%.toxicity} is higher than 0:" and the "on consumption of milk:"
     
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    What are the errors?
     
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    "there's no player in periodical event" for all "if" that I try to calculate if the toxin is higher than a certain value.

    [​IMG]

    also, this with the milk:
    [​IMG]
     
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    Can you show ALL of your code in that script? Like not just the parts you think are relevant? It looks like you're having some formatting issues; the fact that it thinks your "on consumption" event is a condition means you have it inside of another event somehow without realizing it, and it looks like your toxicity lines are in an "every <timespan>" event, which I didn't know.
    --- Double Post Merged, Mar 18, 2017, Original Post Date: Mar 18, 2017 ---
    Oh wait, I see your code above now.

    First of all, you can't use %player% in an "every" event, like your "every 1 second in..." event. Which player would you expect it reference? You're just saying "every 1 second on my server, do this". Who is 'player' supposed to refer to every second?

    Instead, inside of your periodical event, right at the start, add "loop players:", then put the rest of your "every 1 second" instead of the player loop, and use 'loop-player' in place of 'player' everywhere. Additionally, you have an extra period in all of your toxicity variables, which you may want to remove. You have {poison.%player%..toxicity}, when it should be just .toxicity}. Also, I'd recommend storing your variables in a list instead of individually, so instead of {poison.%player%.toxicity}, I'd do something like {toxicity:: poison::%player's uuid%}. That way later on if you want to check the poison toxicity levels of all players, you can do "loop {toxicity:: poison::*}".

    Secondly, your entire "on consumption of milk" event is indented once more when it shouldn't be, so Skript considers it to be part of the "every 1 second" event, so you need to bring it up one level. Even still the rest of your code is weird (you're using a lot of really long "waits" that would probably be unnecessary if this was coded better, and they won't work well at all inside of a loop inside of a periodical event).
     
    • Informative Informative x 1
  14. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    I see you're trying to do stuff with potions. Shameless promotion, I recommend my addon, QuarSK, which has a ton of features regarding potions. For any help, make sure to do it on Discord, as I'm way more active there
     
    • Funny Funny x 1
  15. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,760
    Likes Received:
    124
    Ok, i was working in another skript and got stuck when trying to create a bet system for it.
    The skript in question:
    https://forums.skunity.com/resources/⚀-⚂-dicepoker-⚅-⚃-poker-with-dices.184/

    This is the part that I can't make right, if someone help me it would be much appreciated:
    The error, I think, its in the line 36, as the indentation of subsequent lines are said to be wrong.
    Code (Skript):
    1. options:
    2.   betitem: diamonds
    3.   betminimumvalue: 1 # MAXIMUM VALUE FOR THE MINIMUM BET IS 32! otherwise, the bet will NOT work.
    4.   rerollwhenbet: false #IF TRUE, PLAYER CAN REROLL WHEN BETTING! IT'S UNFAIR AND MAKES IT EASIER TO WIN.
    5.  
    6. #COMMAND
    7. command /dicepoker [<text>] [<text>]:
    8.   trigger:
    9.     if arg 1 is "bet":
    10.       if arg 2 is set:
    11.         if arg 2 is integer:
    12.           set {dicepoker.%player%.betvalue} to arg 2
    13.           make player execute "/dcinternalbet %arg 2%"
    14.           stop
    15.  
    16. command /dcinternalbet <text>:
    17.   trigger:
    18.     if {dicepoker.waiting.%player%.bet} is not set:
    19.       set {dicepoker.waiting.%player%.bet} to true
    20.     if {dicepoker.waiting.%player%.bet} is false:
    21.       message "You cannot bet now!"
    22.       stop
    23.     if {dicepoker.%player%.betvalue} < {betminimumvalue}:
    24.       message "The bet has to be at least {betminimumvalue} {betitem}!"
    25.       stop
    26.     if {dicepoker.%player%.betvalue} > 32:
    27.       message "The maximum bet is 32 {betitem}!"
    28.       stop
    29.     if {dicepoker.waiting.%player%.bet} is true:
    30.        set {dicepoker.waiting.%player%.bet} to false
    31.        loop all items in the player's inventory:  
    32.          if player has betminimumvalue betitem in inventory:
    33.            if {dicepoker.%player%.betvalue} >= 1:
    34.              if {dicepoker.%player%.betvalue} <= 32:
    35.              set betvalue to {dicepoker.%player%.betvalue}
    36.                if player has betvalue betitem in inventory:
    37.                  set {dicepoker.game.%player%.hasbet} to true
    38.                  message "§0[§6d§4Poker§0] §fYou have %number of {betitem} in the player's inventory% {betitem} in your inventory."
    39.                  remove {dicepoker.%player%.betvalue} betitem from player's inventory
    40.                  message "§0[§6d§4Poker§0] §fWe removed {dicepoker.%player%.betvalue} {betitem} from your inventory."
    41.                  message "§0[§6d§4Poker§0] §fYou now have %number of {betitem} in the player's inventory% {betitem} in your inventory."
    42.                  message "§0[§6d§4Poker§0] §fIf you win, you'll get %{dicepoker.%player%.betvalue}+{dicepoker.%player%.betvalue}% {betitem}."
    43.                  set {dicepoker.waiting.%player%.bet} to false
    44.                  make player execute command "/dcinternalstart"
    45.                  stop
    46.                else:
    47.                  message "§0[§6d§4Poker§0] §fYou don't have enough {betitem} in your inventory!"
    48.                  message "§0[§6d§4Poker§0] §fThe game will be droped now."
    49.                  set {dicepoker.last.%player%.game.ended} to false
    50.                  make player execute "/dcinternaldrop"
    51.                  stop
    I'll look into it.

    Thanks for the tips. I'll try it later, I am kinda busy with another project now.
     
Thread Status:
Not open for further replies.
Loading...