How to set a text to a variable?

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

aescraft

Well-Known Member
Mar 1, 2017
295
13
0
36
code_language.skript:
command /XYZ :
  executable by: player
  trigger:
    set {_text.%player%.broadcast} to "Text: "
    add "HELLO WORD," to {_text.%player%.broadcast}
    add " I LOVE ICE CREAM" to {_text.%player%.broadcast}
    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:
 
code_language.skript:
command /XYZ :
  executable by: player
  trigger:
    set {_text.%player%.broadcast} to "Text: "
    add "HELLO WORD," to {_text.%player%.broadcast}
    add " I LOVE ICE CREAM" to {_text.%player%.broadcast}
    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:

@aescraft You need to use variable list
code_language.skript:
command /xyz:
    trigger:
        add "HELLO WORD," to {_text.%player%.broadcast::*}
        add "I LOVE ICE CREAM" to {_text.%player%.broadcast::*}
        broadcast "Text: %{_text.%player%.broadcast::1}%%{_text.%player%.broadcast::2}%"
 
Last edited by a moderator:
@aescraft You need to use variable list
code_language.skript:
command /xyz:
    trigger:
        add "HELLO WORD," to {_text.%player%.broadcast::*}
        add "I LOVE ICE CREAM" to {_text.%player%.broadcast::*}
        broadcast "Text: %{_text.%player%.broadcast::1}%%{_text.%player%.broadcast::2}%"
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_language.skript:
command /rolldice <integer>:
  executable by: player
  trigger:
    set {rolldice.%player%.total} to 0
    set {rolldice.%player%.count} to 0
    if arg 1 isn't 1 or 2 or 3 or 4 or 5 or 6:
      message "You have to roll a number between 1 and 6!"
      stop
    set {waited.rolldice} to difference between {rolldice.%player%.lastused} and now
    if {waited.rolldice} is less than 15 minutes:
      message "You have to wait"
      stop
    broadcast ""     
    broadcast "%player% is rolling some dices:"   
    loop arg 1 times:
      set {random.%player%.rolldicenumber} to random integer from 1 to 6
      if {random.%player%.rolldicenumber} is 1:
        add "⚀" to {rolldice.%player%.dices::*} 
        #⚀
        add 1 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 2:
        add "⚁" to {rolldice.%player%.dices::*} 
        #⚁
        add 2 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 3:
        add "⚂" to {rolldice.%player%.dices::*} 
        #⚂
        add 3 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 4:
        add "⚃" to {rolldice.%player%.dices::*} 
        #⚃
        add 4 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 5:
        add "⚄" to {rolldice.%player%.dices::*}
        #⚄
        add 5 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 6:
        add "⚅" to {rolldice.%player%.dices::*} 
        #⚅
        add 6 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
    broadcast "%{rolldice.%player%.dices::*}%"
    broadcast "%player% rolled %arg 1% dices and got %{rolldice.%player%.total}% in total"
    broadcast ""
    set {rolldice.%player%.dices::*} to ""
    set {rolldice.%player%.dices::1} to ""
    set {rolldice.%player%.dices::2} to ""
    set {rolldice.%player%.dices::3} to ""
    set {rolldice.%player%.dices::4} to ""
    set {rolldice.%player%.dices::5} to ""
    set {rolldice.%player%.dices::6} to ""
    set {rolldice.%player%.total} to "0"
    set {rolldice.%player%.count} to "0"
    set {list::broadcast.%player%.dice} to ""
 
@aescraft didn't understand your problem here , can you explain it better?

EDIT:

Fixed your problem
code_language.skript:
command /rolldice <integer>:
  executable by: player
  trigger:
    set {rolldice.%player%.total} to 0
    set {rolldice.%player%.count} to 0
    if arg 1 isn't 1 or 2 or 3 or 4 or 5 or 6:
      message "You have to roll a number between 1 and 6!"
      stop
    set {waited.rolldice} to difference between {rolldice.%player%.lastused} and now
    if {waited.rolldice} is less than 15 minutes:
      message "You have to wait"
      stop
    broadcast "" 
    broadcast "%player% is rolling some dices:"
    loop arg 1 times:
      set {random.%player%.rolldicenumber} to random integer from 1 to 6
      if {random.%player%.rolldicenumber} is 1:
        add "⚀" to {rolldice.%player%.dices::*}
        #⚀
        add 1 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 2:
        add "⚁" to {rolldice.%player%.dices::*}
        #⚁
        add 2 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 3:
        add "⚂" to {rolldice.%player%.dices::*}
        #⚂
        add 3 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 4:
        add "⚃" to {rolldice.%player%.dices::*}
        #⚃
        add 4 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 5:
        add "⚄" to {rolldice.%player%.dices::*}
        #⚄
        add 5 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
      if {random.%player%.rolldicenumber} is 6:
        add "⚅" to {rolldice.%player%.dices::*}
        #⚅
        add 6 to {rolldice.%player%.total}
        add 1 to {rolldice.%player%.count}
    broadcast "%{rolldice.%player%.dices::*}%"
    broadcast "%player% rolled %arg 1% dices and got %{rolldice.%player%.total}% in total"
    broadcast ""
    clear {rolldice.%player%.dices::*}
    clear {rolldice.%player%.total}
    clear {rolldice.%player%.count}
 
Last edited by a moderator:
@YoshYz
Can you help me with this:
code_language.skript:
on consume of potion:
  message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
  add 33 to {poison.%player%.toxicity}
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.
 
@YoshYz
Can you help me with this:
code_language.skript:
on consume of potion:
  message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
  add 33 to {poison.%player%.toxicity}
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.

You're welcome.
code_language.skript:
on consume:
    event-item is 373:8196:
        message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
        add 33 to {poison.%player%.toxicity}

You can use too
code_language.skript:
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_language.skript:
on rightclick holding water bottle:
    remove event-item from player's inventory
#EFFECT
 
Last edited by a moderator:
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_language.skript:
on consume of bottle of water:
 
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_language.skript:
on consume of bottle of water:
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_language.skript:
variables:
  {poison.%player%.toxicity} = 0

command /toxicity:
  description: Check your potion toxicity level in blood serum!
  executable by: players
  trigger:
    message "Your toxicity level is %{poison.%player%.toxicity}%"

on consume:
  event-item is water_bottle:8196:
    message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
    add 33 to {poison.%player%.toxicity}

Every 1 second in "world" and "world_nether" and "world_the_end":
  if {poison.%player%.toxicity} is higher than 0:
    wait 30 seconds
    remove 1 from {poison.%player%.toxicity}
  if {poison.%player%.toxicity} is higher than integer 33:
    message "Something ins't right..."
    set {sideeffect.%player%.33more} to true
    if {sideeffect.%player%.33more} is true:
      apply potion of weakness of tier 1 to the player for 3 minutes   
      apply potion of slowness of tier 1 to the player for 3 minutes
      wait 3 minutes
      if {sideeffect.%player%.33more} is true:
        set {sideeffect.%player%.33more} to false
        message "I'm starting to feel better."
  if {poison.%player%.toxicity} is higher than integer 66:
    wait 2 seconds
    message "My body hurts..."
    set {sideeffect.%player%.66more} to true
    if {sideeffect.%player%.66more} is true:
      wait 2 seconds
      remove potion of weakness
      remove potion of slowness
      apply potion of weakness of tier 2 to the player for 3 minutes   
      apply potion of slowness of tier 2 to the player for 3 minutes
      wait 3 minutes
      if {sideeffect.%player%.66more} is true:
        apply potion of weakness of tier 1 to the player for 3 minutes   
        apply potion of slowness of tier 1 to the player for 3 minutes
        wait 3 minutes
        if {sideeffect.%player%.66more} is true:
          set {sideeffect.%player%.66more} to false
  if {poison.%player%.toxicity} is higher than integer 89:
    wait 10 seconds
    message "I-I... I'm blind!?"
    set {sideeffect.%player%.89more} to true
    if {sideeffect.%player%.89more} is true:
      apply potion of blindness of tier 3 to the player for 3 minutes
      wait 3 minutes
      if {sideeffect.%player%.89more} is true:
        apply potion of blindness of tier 2 to the player for 2 minutes
        wait 2 minutes
        if {sideeffect.%player%.89more} is true:
          apply potion of blindness of tier 1 to the player for 1 minute
          wait 1 minute
          if {sideeffect.%player%.89more} is true:
            set {sideeffect.%player%.89more} to false
            message "I can finally see again!"
  if {poison.%player%.toxicity} is 99:
    message "If I drink one more potion right now, I'll die for sure!"         
  if {poison.%player%.toxicity} is higher than 99:
    broadcast "✞%player% died drinking too much potion!✞"
    make console execute command "kill %player%"
  on consumption of milk:
    set {sideeffect.%player%.89more} to false
    set {sideeffect.%player%.66more} to false
    set {sideeffect.%player%.33more} to false
    remove all potion
    set {poison.%player%.toxicity} to 0
 
code_language.skript:
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_language.skript:
on consume of bottle of water:
  player's tool is potion of poison
  message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
  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.
 
code_language.skript:
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_language.skript:
on consume of bottle of water:
  player's tool is potion of poison
  message "Added 33 toxicity points from drinking a potion! Check your toxicity level by using the /toxicity command."
  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.
The error I'm having is with the "if {poison.%player%.toxicity} is higher than 0:" and the "on consumption of milk:"
 
What are the errors?
"there's no player in periodical event" for all "if" that I try to calculate if the toxin is higher than a certain value.

IGxKtYf.png


also, this with the milk:
wAl5DY9.png
 
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.
[doublepost=1489818584,1489818045][/doublepost]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).
 
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
 
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_language.skript:
options:
  betitem: diamonds
  betminimumvalue: 1 # MAXIMUM VALUE FOR THE MINIMUM BET IS 32! otherwise, the bet will NOT work.
  rerollwhenbet: false #IF TRUE, PLAYER CAN REROLL WHEN BETTING! IT'S UNFAIR AND MAKES IT EASIER TO WIN.

#COMMAND
command /dicepoker [<text>] [<text>]:
  trigger:
    if arg 1 is "bet":
      if arg 2 is set:
        if arg 2 is integer:
          set {dicepoker.%player%.betvalue} to arg 2
          make player execute "/dcinternalbet %arg 2%"
          stop

command /dcinternalbet <text>:
  trigger:
    if {dicepoker.waiting.%player%.bet} is not set:
      set {dicepoker.waiting.%player%.bet} to true
    if {dicepoker.waiting.%player%.bet} is false:
      message "You cannot bet now!"
      stop
    if {dicepoker.%player%.betvalue} < {betminimumvalue}:
      message "The bet has to be at least {betminimumvalue} {betitem}!"
      stop
    if {dicepoker.%player%.betvalue} > 32:
      message "The maximum bet is 32 {betitem}!"
      stop
    if {dicepoker.waiting.%player%.bet} is true:
       set {dicepoker.waiting.%player%.bet} to false
       loop all items in the player's inventory:   
         if player has betminimumvalue betitem in inventory:
           if {dicepoker.%player%.betvalue} >= 1:
             if {dicepoker.%player%.betvalue} <= 32:
             set betvalue to {dicepoker.%player%.betvalue}
               if player has betvalue betitem in inventory:
                 set {dicepoker.game.%player%.hasbet} to true
                 message "§0[§6d§4Poker§0] §fYou have %number of {betitem} in the player's inventory% {betitem} in your inventory."
                 remove {dicepoker.%player%.betvalue} betitem from player's inventory
                 message "§0[§6d§4Poker§0] §fWe removed {dicepoker.%player%.betvalue} {betitem} from your inventory."
                 message "§0[§6d§4Poker§0] §fYou now have %number of {betitem} in the player's inventory% {betitem} in your inventory."
                 message "§0[§6d§4Poker§0] §fIf you win, you'll get %{dicepoker.%player%.betvalue}+{dicepoker.%player%.betvalue}% {betitem}."
                 set {dicepoker.waiting.%player%.bet} to false
                 make player execute command "/dcinternalstart"
                 stop
               else:
                 message "§0[§6d§4Poker§0] §fYou don't have enough {betitem} in your inventory!"
                 message "§0[§6d§4Poker§0] §fThe game will be droped now."
                 set {dicepoker.last.%player%.game.ended} to false
                 make player execute "/dcinternaldrop"
                 stop

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
I'll look into it.

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.
[doublepost=1489818584,1489818045][/doublepost]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).
Thanks for the tips. I'll try it later, I am kinda busy with another project now.
 
Status
Not open for further replies.