Random Integer Between 2 Locations

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

oHeckGage

Active Member
Mar 24, 2020
110
6
18
22
Ok so I am trying to make a skript where when you select a kit, it summons you to a random location between -22 9 5 and 25 0 56 and I know single number random integers but not 2 coords, and help??

Full Code:

Code:
command /kits:
    trigger:
        open virtual chest with size 4 named "&9Kits" to player
        wait 1 tick
        format gui slot 10 of player with iron helmet named "&8&lKit PVP" to run:
            execute command "give %player% iron_helmet 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_chestplate 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_leggings 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_boots 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}],Unbreakable:1}"
            give player 8 golden apple
            execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
            give player 16 ender pearls
            give player 1 arrow
            teleport player to {spawn}
        format gui slot 19 of player with diamond helmet named "&8&lKit TANK" to run:
            give player 1 iron helmet
            give player 1 diamond chestplate
            give player 1 diamond leggings
            give player 1 diamond boots
            apply slowness 2 to player for 999 days
            set {tank.%player%} to true
            give player 1 stone sword
            give player 2 golden apple
            teleport player to {spawn}
        format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
            if player has permission "kit.assassin":
                execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
                execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"  
                execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
                execute command "give %player% leather_boots 1 0 {display:{color:0}}"
                execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
                execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
                give player 1 arrow
                execute command "give %player% invislongpot 1"
                give player 8 golden apple
                give player 8 ender pearls
                set {_random} to a random integer between (-22 9 5 and 25 0 56) #problem line I just need it on all of them since I just tried it on 1 kit
                teleport player to {_random}
            else:
                send "&cYou need 50 kills!"
              
on death:
    if {tank.%player%} is true:
        set {tank.%player%} to false
        remove slowness from player
every 1 second in world "world":
    loop all players:
        if loop-player doesn't have permission "kits.assassin":
            if {kills.%loop-player%} is 50:
                execute command "pex user %loop-player% add kits.assassin"
                send "&aYou unlocked kit ""&8&lASSASSIN""" to loop-player
 
Ok so I am trying to make a skript where when you select a kit, it summons you to a random location between -22 9 5 and 25 0 56 and I know single number random integers but not 2 coords, and help??

Full Code:

Code:
command /kits:
    trigger:
        open virtual chest with size 4 named "&9Kits" to player
        wait 1 tick
        format gui slot 10 of player with iron helmet named "&8&lKit PVP" to run:
            execute command "give %player% iron_helmet 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_chestplate 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_leggings 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_boots 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}],Unbreakable:1}"
            give player 8 golden apple
            execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
            give player 16 ender pearls
            give player 1 arrow
            teleport player to {spawn}
        format gui slot 19 of player with diamond helmet named "&8&lKit TANK" to run:
            give player 1 iron helmet
            give player 1 diamond chestplate
            give player 1 diamond leggings
            give player 1 diamond boots
            apply slowness 2 to player for 999 days
            set {tank.%player%} to true
            give player 1 stone sword
            give player 2 golden apple
            teleport player to {spawn}
        format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
            if player has permission "kit.assassin":
                execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
                execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"
                execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
                execute command "give %player% leather_boots 1 0 {display:{color:0}}"
                execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
                execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
                give player 1 arrow
                execute command "give %player% invislongpot 1"
                give player 8 golden apple
                give player 8 ender pearls
                set {_random} to a random integer between (-22 9 5 and 25 0 56) #problem line I just need it on all of them since I just tried it on 1 kit
                teleport player to {_random}
            else:
                send "&cYou need 50 kills!"
           
on death:
    if {tank.%player%} is true:
        set {tank.%player%} to false
        remove slowness from player
every 1 second in world "world":
    loop all players:
        if loop-player doesn't have permission "kits.assassin":
            if {kills.%loop-player%} is 50:
                execute command "pex user %loop-player% add kits.assassin"
                send "&aYou unlocked kit ""&8&lASSASSIN""" to loop-player
Before asnwering to your question, I have some remarks:
  • Avoid using console commands.
  • There is a give effect in skript, ex:
    Code:
    give player 1 of diamond
random integer gives a random interger what else do you expect ?
if you want a random location just create 3 random numbers relative to x y and z
Code:
#Replace a, b, c, d, e and f with actual values
set {_x} to random number from a to b
set {_y} to random number from c to d
set {_z} to random number from e to f

set {_location} to location at {_x}, {_y} and {_z} in world "world_name_here" parsed as world
now you can teleport the player:
Code:
teleport player to {_location}
 
Last edited:
Before asnwering to your question, I have some remarks:
  • Avoid using console commands.
  • There is a give effect in skript, ex:
    Code:
    give player 1 of diamond
random integer gives a random interger what else do you expect ?
if you want a random location just create 3 random numbers relative to x y and z
Code:
#Replace a, b, c, d, e and f with actual values
set {_x} to random nmber from a to b
set {_y} to random nmber from c to d
set {_z} to random nmber from e to f

set {_location} to location at {_x}, {_y} and {_z} in world "world_name_here" parsed as world
now you can teleport the player:
Code:
teleport player to {_location}

Thank you! The only reason I use console commands is because I know commands for enchantments and I don't know skript enchant conditions.

Edit:

For some reason, it won't teleport the player.

Code:
every 1 second in world "world":
    loop {_x}, {_y}, and {_z}:
        set {_x} to random number between -22 and 25
        set {_y} to random number between 9 and 0
        set {_x} to random number between 5 and 56
        set {_location} to location at {_x}, {_y}, {_z}
teleport player to {_location}

It won't work when I teleport the player. What is happening is the format gui slot and when you click on it, it gives you the kit and teleports you but it won't teleport the player. Any idea why?

Gui Code:

Code:
        format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
            if player has permission "kit.assassin":
                execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
                execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"   
                execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
                execute command "give %player% leather_boots 1 0 {display:{color:0}}"
                execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
                execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
                give player 1 arrow
                execute command "give %player% invislongpot 1"
                give player 8 golden apple
                give player 8 ender pearls
                teleport player to {_location}
            else:
                send "&cYou need 50 kills!"
[doublepost=1588193311,1588190481][/doublepost]Also I tried closing the gui before hand but still
 
Thank you! The only reason I use console commands is because I know commands for enchantments and I don't know skript enchant conditions.

Edit:

For some reason, it won't teleport the player.

Code:
every 1 second in world "world":
    loop {_x}, {_y}, and {_z}:
        set {_x} to random number between -22 and 25
        set {_y} to random number between 9 and 0
        set {_x} to random number between 5 and 56
        set {_location} to location at {_x}, {_y}, {_z}
teleport player to {_location}

It won't work when I teleport the player. What is happening is the format gui slot and when you click on it, it gives you the kit and teleports you but it won't teleport the player. Any idea why?

Gui Code:

Code:
        format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
            if player has permission "kit.assassin":
                execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
                execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"
                execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
                execute command "give %player% leather_boots 1 0 {display:{color:0}}"
                execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
                execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
                give player 1 arrow
                execute command "give %player% invislongpot 1"
                give player 8 golden apple
                give player 8 ender pearls
                teleport player to {_location}
            else:
                send "&cYou need 50 kills!"
[doublepost=1588193311,1588190481][/doublepost]Also I tried closing the gui before hand but still
first of all this line is useless
Code:
loop {_x}, {_y}, and {_z}
you setted {_location} in a diffrent block of code and it's a local variable you have to make it global (remove the underscore) if you want to use it globaly in your scripts. But there is no point to set the location every second, just set the location value under the format effect.
 
first of all this line is useless
Code:
loop {_x}, {_y}, and {_z}
you setted {_location} in a diffrent block of code and it's a local variable you have to make it global (remove the underscore) if you want to use it globaly in your scripts. But there is no point to set the location every second, just set the location value under the format effect.
Ok Thanks! I will see if it works. Also the reason I put it in a separate place is because I don't want to have to type that for all the kits, that will just make it automatically do it without me inserting it into the kits. That would be much more work


Edit:
Didn't Work Still.

BUT Wait another edit I forgot to parse it into the world not into the other world xD

And another edit still doesn't work:

Code:
command /kits:
    trigger:
        open virtual chest with size 4 named "&9Kits" to player
        wait 1 tick
        format gui slot 10 of player with iron helmet named "&8&lKit PVP" to run:
            execute command "give %player% iron_helmet 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_chestplate 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_leggings 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_boots 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
            execute command "give %player% iron_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}],Unbreakable:1}"
            give player 8 golden apple
            execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
            give player 16 ender pearls
            give player 1 arrow
            wait 1 tick
            teleport the player to {location}
        format gui slot 19 of player with diamond helmet named "&8&lKit TANK" to run:
            give player 1 iron helmet
            give player 1 diamond chestplate
            give player 1 diamond leggings
            give player 1 diamond boots
            apply slowness 2 to player for 999 days
            set {tank.%player%} to true
            give player 1 stone sword
            give player 2 golden apple
            teleport player to {location}
        format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
            if player has permission "kit.assassin":
                execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
                execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"   
                execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
                execute command "give %player% leather_boots 1 0 {display:{color:0}}"
                execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
                execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
                give player 1 arrow
                execute command "give %player% invislongpot 1"
                give player 8 golden apple
                give player 8 ender pearls
                teleport player to {location}
            else:
                send "&cYou need 50 kills!"
               
on death:
    if {tank.%player%} is true:
        set {tank.%player%} to false
        remove slowness from player
every 1 second in world "world":
    loop all players:
        if loop-player doesn't have permission "kits.assassin":
            if {kills.%loop-player%} is 50:
                execute command "pex user %loop-player% add kits.assassin"
                send "&aYou unlocked kit ""&8&lASSASSIN""" to loop-player
every 1 second in world "world":
    loop {_x}, {_y}, and {_z}:
        set {_x} to random number between -22 and 25
        set {_y} to random number between 9 and 0
        set {_x} to random number between 5 and 56
        set {location} to location at {_x}, {_y}, {_z} in world "map" parsed as a world
[doublepost=1588196535,1588196194][/doublepost]Btw no errors
 
Before asnwering to your question, I have some remarks:
  • Avoid using console commands.
  • There is a give effect in skript, ex:
    Code:
    give player 1 of diamond
random integer gives a random interger what else do you expect ?
if you want a random location just create 3 random numbers relative to x y and z
Code:
#Replace a, b, c, d, e and f with actual values
set {_x} to random nmber from a to b
set {_y} to random nmber from c to d
set {_z} to random nmber from e to f

set {_location} to location at {_x}, {_y} and {_z} in world "world_name_here" parsed as world
now you can teleport the player:
Code:
teleport player to {_location}

Just curious why do u parse the world?
 
Just curious why do u parse the world?
well I tested using a string before and caused errors.
but noticed that the "location at" expression takes a world type at the last parameter, I know it is optional to specify the world but there are cases where you need to if I remember correctly.
Just curious why do u parse the world?
Code:
[the] (location|position) [at] [(][x[ ][=[ ]]]%number%, [y[ ][=[ ]]]%number%, [and] [z[ ][=[ ]]]%number%[)] [[(in|of) [[the] world]] %world%]
 
well I tested using a string before and caused errors.
but noticed that the "location at" expression takes a world type at the last parameter, I know it is optional to specify the world but there are cases where you need to if I remember correctly.

Code:
[the] (location|position) [at] [(][x[ ][=[ ]]]%number%, [y[ ][=[ ]]]%number%, [and] [z[ ][=[ ]]]%number%[)] [[(in|of) [[the] world]] %world%]
This should work just fine:

Code:
Set {_l} to location 0, 0, 0 in world “world”

Otherwise:

Code:
Set {_l} to location 0, 0, 0 in world world “world”

The world has to exist and be loaded to not get any errors.

Next to that as u Said yes u need the world name sometimes. Its needed when there is no way for the code to know what world is beeing available with the trigger. So if a player does a command no world is needed bc it uses the world of the player by default. But if u would do the same command from the console it would error out. Bc Skript cant comeup with any Logic since the console is not in a world.
 
This should work just fine:

Code:
Set {_l} to location 0, 0, 0 in world “world”

Otherwise:

Code:
Set {_l} to location 0, 0, 0 in world world “world”

The world has to exist and be loaded to not get any errors.

Next to that as u Said yes u need the world name sometimes. Its needed when there is no way for the code to know what world is beeing available with the trigger. So if a player does a command no world is needed bc it uses the world of the player by default. But if u would do the same command from the console it would error out. Bc Skript cant comeup with any Logic since the console is not in a world.


Its not:
Code:
set {_1} to location 0, 0, 0 in world "world"

It is:
Code:
set {_1} to location AT 0, 0, 0 in world "world"
, just saying atleast that doesn't work for me xD
 
Status
Not open for further replies.