Comparing two locations always fails

Discussion in 'Skript' started by Buzzycaf, May 28, 2017.

  1. Hello all,
    Still new to skript. All I'm trying to do is teleport someone with the /doit command only if they're standing at a particular location. However, the condition always fails. I've also tried if player's location is {_locationspawn} as well and it always fails. I've printed the coords of each variable as a check and they match but the condition fails anyway. I've googled around and no one seems to be comparing locations. Any suggestions would be helpful, thank you.

    Code (Text):
    command /doit:
        trigger:
       
            set {_locationspawn} to the location at 0, 55, 0
            message "_locationspawn is %{_locationspawn}%"
           
            set {_locationA} to the location at 0, 52, 10
            message "_locationA is %{_locationA}%"
           
            set {_playerlocation} to player's location
               
            message "%player% is at %{_playerlocation}%"
           
            if {_playerlocation} is {_locationspawn}:
                message "Teleporting!!"
                teleport the player to {_locationA}
            else:
                message "DID NOT WORK!"
     
  2. Try to check the condition using string
    Like :
    Code (Text):
    if "%{_playerlocation}%" is "%{_locationspawn}%":
     
  3. konsolas

    Supporter

    (not a skript developer here)

    Locations in spigot are stored as real numbers - that is, with a decimal.
    For your check to succeed, the player would need to stand exactly on {_locationspawn}, not even being 0.0000001 away from it. This is very difficult, so that's probably why your check doesn't succeed.

    You could do a few things:
    • Check if {_playerlocation} is within X blocks of {_locationspawn}
    • Get the block at the player's location, and then compare the location of the block. (this rounds the player's location to a whole number)
    • Create a region, specified by two locations and check if the player is in the cuboid between the two.
     
  4. Code (Text):

    command /doit:
      trigger:
        set {_locationspawn} to the location at 0, 55, 0
        message "_locationspawn is %{_locationspawn}%"
        set {_locationA} to the location at 0, 52, 10
        message "_locationA is %{_locationA}%"
        set {_playerlocation::x} to the rounded down player's x-coordinate
        set {_playerlocation::y} to the rounded down player's y-coordinate
        set {_playerlocation::z} to the rounded down player's z-coordinate
        set {_checkplayerlocation} to "x: %{_playerlocation::x}%, y: %{_playerlocation::y}%, z: %{_playerlocation::z}%"
        message "%player% is at %{_checkplayerlocation}%"
        if {_checkplayerlocation} is {_locationspawn}:
          message "Teleporting!!"
          teleport the player to {_locationA}
        else:
          message "IT SHOULD WORK!"
     
    Tell me if it's working.
     
  5. This is the definition of a script kiddie.
     
    • Funny Funny x 1
    • Optimistic Optimistic x 1
  6. CD.

    CD. Previously Cediee

    Player's location from variable {_playerlocation} has xyz coords, yaw and pitch while {_locationspawn} has xyz coords while it doesn't have yaw and pitch.