Solved How to teleport to a location defined in a yaml file?

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

SamDFL

New Member
Mar 2, 2018
7
0
0
25
Skript Version: Skript (Latest Version)
Skript Author: SamDFL
Minecraft Version: 1.8.9

I've been trying to find a fix for this for ages, but I can't find it. Basically, I'm trying to teleport a player to a random location when they type /sw-join <arena>, which has been defined in a yaml file (see below for code). But it simply doesn't work for some reason, nothing happens. Any help would be much appreciated! Oh and also, I'm using WildSkript for yaml and not SkUtilites, I wont be switching, so please don't tell me to go to SkUtilites unless necessary.

---

Yaml Code:
code_language.skript:
arenas:
  arena:
    spawn:
      '1': 'x: -697.39, y: 64, z: 807.93''
      '2': 'x: -698.39, y: 64, z: 808.93'


Full Code:
code_language.skript:
variables:
    {ingame} = false
   
options:   
    Prefix: &3[&bCometCraft&3]&f
    Perm: skywars.staff
    Config: plugins/SkyWars/skywars.yml
   
on skript load:
    if file "{@Config}" doesn't exists:
        create file "{@Config}"
        set "" to "arenas" in yaml file "{@Config}"
   
command /skywars-create [<text>]:
    aliases: /sw-create
    usage: /skywars-create <arena name>
    permission: {@Perm}
    trigger:
        if arg 1 isn't set:
            message "{@Prefix} &cTo create an arena, select the arena with a worldedit wand and type &a&l/sw-create <map-name>&c!"
        if arg 1 is set:
            set "arenas" to "%arg 1%" in yaml file "{@Config}"
            execute console command "/rg define %arg 1%"
            execute console command "/rg flag %arg 1% passthrough allow"
            execute console command "/rg flag %arg 1% mob-spawning deny"
            execute console command "/rg flag %arg 1% pvp allow"
            message "{@Prefix} &aSkywars match &c%arg 1% &acreated! Now, use &c/skywars-setspawn <arena> <spawn-number>&a to set the spawn islands of the map!"
            stop trigger

command /skywars-setspawn <text> <int>:
    aliases: /sw-setspawn
    usage: /skywars-setspawn <arena name> <spawn number>
    permission: {@Perm}
    trigger:
        set {_arena.%arg 1%} to single value "arenas.%arg 1%" get of "{@Config}"
        set "arenas.%arg 1%.spawn.%arg 2%" to "%player's location%" in yaml file "{@Config}"
        wait 1 tick
        set {_spawn.%arg 1%.%arg 2%} to single value "arenas.%arg 1%.spawn.%arg 2%" get of "{@Config}"
        wait 1 tick
        message "{@Prefix} &aSkywars match &c%arg 1%&a's spawn number &c%arg 2% &ahas been set at &c%{_spawn.%arg 1%.%arg 2%}%!"
        stop trigger

command /skywars-join <text>:
    aliases: /sw-join
    usage: /skywars-join <arena name>
    permission: {@Perm}
    trigger:
        set {_spawns::*} to value list "arenas.%arg 1%.spawn" get of "{@Config}"
        set {spawn-area} to random location out of {_spawns::*}
        teleport player to {spawn-area}
        stop trigger


Errors on Reload:
None

Console Errors: None

Addons using (including versions):
Umbaska 2.0, WildSkript

Troubleshooting:

Have you tried searching the docs? Yes
Have you tried searching the forums? Yes
What other methods have you tried to fix it? I've tried many other methods on the skripting side of things, for example, I tried change the
code_language.skript:
set {spawn-area} to random location out of {_spawns::*}
to
code_language.skript:
set {spawn-area} to random text out of {_spawns::*}
 
I think the problem is that it isn't parsed as a location when it's in the YAML file, so I think you have to do something like this in the YAML file:
code_language.skript:
arenas:
  arena:
    spawn:
      1:
        x: -697.39
        y: 64
        z: 807.93
      2:
        x: -698.39
        y: 64
        z: 808.93
and I don't know much about YAML in Skript, but get the x, y and z coordinate in temporary variable, then use
code_language.skript:
set {_loc} to location({_x} parsed as a int, {_y} parsed as a int, {_z} parsed as a int, world "%arg-1%")
 
I think the problem is that it isn't parsed as a location when it's in the YAML file, so I think you have to do something like this in the YAML file:
code_language.skript:
arenas:
  arena:
    spawn:
      1:
        x: -697.39
        y: 64
        z: 807.93
      2:
        x: -698.39
        y: 64
        z: 808.93
and I don't know much about YAML in Skript, but get the x, y and z coordinate in temporary variable, then use
code_language.skript:
set {_loc} to location({_x} parsed as a int, {_y} parsed as a int, {_z} parsed as a int, world "%arg-1%")

Thanks dude! After some further tinkering, I've got it to work, thanks for the help! :emoji_slight_smile:
 
No problem! :emoji_slight_smile:
 
Last edited:
Status
Not open for further replies.