Solved Help with random integer

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

AndhyIrfanID

New Member
Jun 22, 2017
9
0
0
24
So im using this code:

set {_number} to "1 and 6"
set {_random} to random integer between {_number}

^^ But it doesn't work

can someone help fix this problem?

Thanks before
 
code_language.skript:
set {_1} to 1
set {_2} to 2
set {_random} to random integer between {_1} and {_2}

try this way
But i got the number from the lore tho, for example:

code_language.skript:
if lore of player's held item contain "Damage: 1-6"
set {_lore} to lore of player's held item
replace all "Damage" in {_lore} with ""
replace all "-" in {_lore} with " and " #So {_lore} is "1 and 6" now
set {_random} to random integer between {_lore}

But it doesn't work
 
So, the variable {_lore} contains the string "1 and 6". The issue I believe you are having is that the random integer between expression expects two integer values, while you're giving it a string.

This may work:

code_language.skript:
if lore of player's tool contains "Damage: 1-6":
    # this will get everything after "Damage: ", so, only "1-6"
    set {_lore} to subtext of player's held item's lore from characters (first index of ": " in event-item's lore + 2) to (length of event-item's lore)
    set {_random} to random integer between (first element out of split {_lore} at "-" parsed as integer) and (last element out of split {_lore} at "-" parsed as integer)
    # The previous line is the same thing as:
    # set {_loreIntegers::*} to {_lore} split at "-"
    # set {_loreInt1} to "%{_loreIntegers::1}%" parsed as integer
    # set {_loreInt2} to "%{_loreIntegers::2}%" parsed as integer
    # set {_random} to random integer between {_loreInt1} and {_loreInt2}
 
So, the variable {_lore} contains the string "1 and 6". The issue I believe you are having is that the random integer between expression expects two integer values, while you're giving it a string.

This may work:

code_language.skript:
if lore of player's tool contains "Damage: 1-6":
    # this will get everything after "Damage: ", so, only "1-6"
    set {_lore} to subtext of player's held item's lore from characters (first index of ": " in event-item's lore + 2) to (length of event-item's lore)
    set {_random} to random integer between (first element out of split {_lore} at "-" parsed as integer) and (last element out of split {_lore} at "-" parsed as integer)
    # The previous line is the same thing as:
    # set {_loreIntegers::*} to {_lore} split at "-"
    # set {_loreInt1} to "%{_loreIntegers::1}%" parsed as integer
    # set {_loreInt2} to "%{_loreIntegers::2}%" parsed as integer
    # set {_random} to random integer between {_loreInt1} and {_loreInt2}
code_language.skript:
set {_random} to a random integer between first element out of lore of player's tool parsed as ("Damage: %number%-%number%") parsed as a number and last element out of lore of player's tool parsed as ("Damage: %number%-%number%") parsed as a number

But because of the ":" this is prone to the not a valid item data error, so yours is better though its one line longer not to mention yours is easier to read
 
So, the variable {_lore} contains the string "1 and 6". The issue I believe you are having is that the random integer between expression expects two integer values, while you're giving it a string.

This may work:

code_language.skript:
if lore of player's tool contains "Damage: 1-6":
    # this will get everything after "Damage: ", so, only "1-6"
    set {_lore} to subtext of player's held item's lore from characters (first index of ": " in event-item's lore + 2) to (length of event-item's lore)
    set {_random} to random integer between (first element out of split {_lore} at "-" parsed as integer) and (last element out of split {_lore} at "-" parsed as integer)
    # The previous line is the same thing as:
    # set {_loreIntegers::*} to {_lore} split at "-"
    # set {_loreInt1} to "%{_loreIntegers::1}%" parsed as integer
    # set {_loreInt2} to "%{_loreIntegers::2}%" parsed as integer
    # set {_random} to random integer between {_loreInt1} and {_loreInt2}
OMG thank you so much this one working
code_language.skript:
if lore of player's tool contains "&7Damage: 1-6":
           set {_lore} to lore of player's held item
           replace all "&7Damage: " in {_lore} with ""
           set {_loreIntegers::*} to {_lore} split at "-"
           set {_loreInt1} to "%{_loreIntegers::1}%" parsed as integer
           set {_loreInt2} to "%{_loreIntegers::2}%" parsed as integer
           set {_random} to random integer between {_loreInt1} and {_loreInt2}
           send "%{_random}%"
 
Last edited by a moderator:
Status
Not open for further replies.