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

Random Integer Between 2 Locations

Discussion in 'Skript' started by oHeckGage, Apr 29, 2020.

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

    oHeckGage Active Member

    Joined:
    Mar 24, 2020
    Messages:
    105
    Likes Received:
    5
    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 (Text):
    1.  
    2. command /kits:
    3.     trigger:
    4.         open virtual chest with size 4 named "&9Kits" to player
    5.         wait 1 tick
    6.         format gui slot 10 of player with iron helmet named "&8&lKit PVP" to run:
    7.             execute command "give %player% iron_helmet 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    8.             execute command "give %player% iron_chestplate 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    9.             execute command "give %player% iron_leggings 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    10.             execute command "give %player% iron_boots 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    11.             execute command "give %player% iron_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}],Unbreakable:1}"
    12.             give player 8 golden apple
    13.             execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
    14.             give player 16 ender pearls
    15.             give player 1 arrow
    16.             teleport player to {spawn}
    17.         format gui slot 19 of player with diamond helmet named "&8&lKit TANK" to run:
    18.             give player 1 iron helmet
    19.             give player 1 diamond chestplate
    20.             give player 1 diamond leggings
    21.             give player 1 diamond boots
    22.             apply slowness 2 to player for 999 days
    23.             set {tank.%player%} to true
    24.             give player 1 stone sword
    25.             give player 2 golden apple
    26.             teleport player to {spawn}
    27.         format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
    28.             if player has permission "kit.assassin":
    29.                 execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
    30.                 execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"  
    31.                 execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
    32.                 execute command "give %player% leather_boots 1 0 {display:{color:0}}"
    33.                 execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
    34.                 execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
    35.                 give player 1 arrow
    36.                 execute command "give %player% invislongpot 1"
    37.                 give player 8 golden apple
    38.                 give player 8 ender pearls
    39.                 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
    40.                 teleport player to {_random}
    41.             else:
    42.                 send "&cYou need 50 kills!"
    43.              
    44. on death:
    45.     if {tank.%player%} is true:
    46.         set {tank.%player%} to false
    47.         remove slowness from player
    48. every 1 second in world "world":
    49.     loop all players:
    50.         if loop-player doesn't have permission "kits.assassin":
    51.             if {kills.%loop-player%} is 50:
    52.                 execute command "pex user %loop-player% add kits.assassin"
    53.                 send "&aYou unlocked kit ""&8&lASSASSIN""" to loop-player
    54.              
    55.      
    56.  
     
  2. Best Answer:
    Post #2 by Abdera7mane, Apr 29, 2020
  3. Abdera7mane

    Abdera7mane Active Member

    Joined:
    Aug 18, 2019
    Messages:
    56
    Likes Received:
    7
    Before asnwering to your question, I have some remarks:
    • Avoid using console commands.
    • There is a give effect in skript, ex:
      Code (Text):
      1. 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 (Text):
    1. #Replace a, b, c, d, e and f with actual values
    2. set {_x} to random number from a to b
    3. set {_y} to random number from c to d
    4. set {_z} to random number from e to f
    5.  
    6. set {_location} to location at {_x}, {_y} and {_z} in world "world_name_here" parsed as world
    7.  
    now you can teleport the player:
    Code (Text):
    1. teleport player to {_location}
     
    #2 Abdera7mane, Apr 29, 2020
    Last edited: Apr 30, 2020
  4. oHeckGage

    oHeckGage Active Member

    Joined:
    Mar 24, 2020
    Messages:
    105
    Likes Received:
    5
    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 (Text):
    1.  
    2. every 1 second in world "world":
    3.     loop {_x}, {_y}, and {_z}:
    4.         set {_x} to random number between -22 and 25
    5.         set {_y} to random number between 9 and 0
    6.         set {_x} to random number between 5 and 56
    7.         set {_location} to location at {_x}, {_y}, {_z}
    8. teleport player to {_location}
    9.  
    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 (Text):
    1.  
    2.         format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
    3.             if player has permission "kit.assassin":
    4.                 execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
    5.                 execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"  
    6.                 execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
    7.                 execute command "give %player% leather_boots 1 0 {display:{color:0}}"
    8.                 execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
    9.                 execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
    10.                 give player 1 arrow
    11.                 execute command "give %player% invislongpot 1"
    12.                 give player 8 golden apple
    13.                 give player 8 ender pearls
    14.                 teleport player to {_location}
    15.             else:
    16.                 send "&cYou need 50 kills!"
    17.  
    --- Double Post Merged, Apr 29, 2020, Original Post Date: Apr 29, 2020 ---
    Also I tried closing the gui before hand but still
     
  5. Abdera7mane

    Abdera7mane Active Member

    Joined:
    Aug 18, 2019
    Messages:
    56
    Likes Received:
    7
    first of all this line is useless
    Code (Text):
    1. 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.
     
  6. oHeckGage

    oHeckGage Active Member

    Joined:
    Mar 24, 2020
    Messages:
    105
    Likes Received:
    5
    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 (Text):
    1. command /kits:
    2.     trigger:
    3.         open virtual chest with size 4 named "&9Kits" to player
    4.         wait 1 tick
    5.         format gui slot 10 of player with iron helmet named "&8&lKit PVP" to run:
    6.             execute command "give %player% iron_helmet 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    7.             execute command "give %player% iron_chestplate 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    8.             execute command "give %player% iron_leggings 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    9.             execute command "give %player% iron_boots 1 0 {Enchantments:[{id:protection,lvl:1}],Unbreakable:1}"
    10.             execute command "give %player% iron_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}],Unbreakable:1}"
    11.             give player 8 golden apple
    12.             execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
    13.             give player 16 ender pearls
    14.             give player 1 arrow
    15.             wait 1 tick
    16.             teleport the player to {location}
    17.         format gui slot 19 of player with diamond helmet named "&8&lKit TANK" to run:
    18.             give player 1 iron helmet
    19.             give player 1 diamond chestplate
    20.             give player 1 diamond leggings
    21.             give player 1 diamond boots
    22.             apply slowness 2 to player for 999 days
    23.             set {tank.%player%} to true
    24.             give player 1 stone sword
    25.             give player 2 golden apple
    26.             teleport player to {location}
    27.         format gui slot 16 of player with diamond sword named "&8&lKit ASSASSIN" to run:
    28.             if player has permission "kit.assassin":
    29.                 execute command "give %player% leather_helmet 1 0 {display:{color:0}}"
    30.                 execute command "give %player% leather_chestplate 1 0 {display:{color:5263440}}"  
    31.                 execute command "give %player% leather_leggings 1 0 {display:{color:5263440}}"
    32.                 execute command "give %player% leather_boots 1 0 {display:{color:0}}"
    33.                 execute command "give %player% diamond_sword 1 0 {Enchantments:[{id:sharpness,lvl:1}]}"
    34.                 execute command "give %player% bow 1 0 {Enchantments:[{id:infinity,lvl:1},{id:power,lvl:1}]}"
    35.                 give player 1 arrow
    36.                 execute command "give %player% invislongpot 1"
    37.                 give player 8 golden apple
    38.                 give player 8 ender pearls
    39.                 teleport player to {location}
    40.             else:
    41.                 send "&cYou need 50 kills!"
    42.                
    43. on death:
    44.     if {tank.%player%} is true:
    45.         set {tank.%player%} to false
    46.         remove slowness from player
    47. every 1 second in world "world":
    48.     loop all players:
    49.         if loop-player doesn't have permission "kits.assassin":
    50.             if {kills.%loop-player%} is 50:
    51.                 execute command "pex user %loop-player% add kits.assassin"
    52.                 send "&aYou unlocked kit ""&8&lASSASSIN""" to loop-player
    53. every 1 second in world "world":
    54.     loop {_x}, {_y}, and {_z}:
    55.         set {_x} to random number between -22 and 25
    56.         set {_y} to random number between 9 and 0
    57.         set {_x} to random number between 5 and 56
    58.         set {location} to location at {_x}, {_y}, {_z} in world "map" parsed as a world
    --- Double Post Merged, Apr 29, 2020, Original Post Date: Apr 29, 2020 ---
    Btw no errors
     
  7. Lego_freak1999

    Lego_freak1999 Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    664
    Likes Received:
    45
    Just curious why do u parse the world?
     
  8. Abdera7mane

    Abdera7mane Active Member

    Joined:
    Aug 18, 2019
    Messages:
    56
    Likes Received:
    7
    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 (Text):
    1. [the] (location|position) [at] [(][x[ ][=[ ]]]%number%, [y[ ][=[ ]]]%number%, [and] [z[ ][=[ ]]]%number%[)] [[(in|of) [[the] world]] %world%]
     
  9. Lego_freak1999

    Lego_freak1999 Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    664
    Likes Received:
    45
    This should work just fine:

    Code (Text):
    1. Set {_l} to location 0, 0, 0 in world “world”
    Otherwise:

    Code (Text):
    1. 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.
     
    • Useful Useful x 1
  10. oHeckGage

    oHeckGage Active Member

    Joined:
    Mar 24, 2020
    Messages:
    105
    Likes Received:
    5

    Its not:
    Code (Text):
    1. set {_1} to location 0, 0, 0 in world "world"
    It is:
    Code (Text):
    1. set {_1} to location AT 0, 0, 0 in world "world"
    , just saying atleast that doesn't work for me xD
     
  11. Lego_freak1999

    Lego_freak1999 Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    664
    Likes Received:
    45

    It should tho

    https://skriptlang.github.io/Skript/expressions.html#ExprLocationAt



    • [the] (location|position) [at] [\(][x[ ][=[ ]]]%number%, [y[ ][=[ ]]]%number%, [and] [z[ ][=[ ]]]%number%[\)] [[(in|of) [[the] world]] %world%]

      [at] = optional
     
Thread Status:
Not open for further replies.

Share This Page

Loading...