Solved Distance between no Y

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

Aralwen

Active Member
May 26, 2017
164
14
18
25
Hello guys,

I wish to make the position Y not taken into account
I have try : set {MidPos.%player%} to distance x and z between player and {Mid} but don't work

My skript :

code_language.skript:
command /setmid:
    trigger:
        set {Mid} to player's location
 
command /mid:
    trigger:
        set {MidPos.%player%} to distance between player and {Mid}
        set {MidPos.%player%} to round({MidPos.%player%})
        send "%{MidPos.%player%}%"

@Donut i tag you because you helped me before, have you a idea ?
Thank you in advance !

Skript Version: 2.2
Skript Author: ?
Minecraft Version: 1.8.8


Errors on Reload : Nothing
Console Errors : Nothing


Troubleshooting:

Have you tried searching the docs? Yes
Have you tried searching the forums ? Yes
 
First of all, you shouldn't use global variables if you're gonna to use them only once, you can use local variables (the ones prefixed with an underscore) which were made for that.

Now, regarding your issue. Try with the following instead:
code_language.skript:
distance betwen player's location and {Mid}
 
First of all, you shouldn't use global variables if you're gonna to use them only once, you can use local variables (the ones prefixed with an underscore) which were made for that.

Now, regarding your issue. Try with the following instead:
code_language.skript:
distance betwen player's location and {Mid}

Ok, my new skript :
code_language.skript:
command /setmid:
    trigger:
        set {Mid} to player's location
 
command /mid:
    trigger:
        set {_distance} to distance between player and {Mid}
        set {_distance} to round({_distance})
        send "%{_distance%}%"

But, your proposal does not work : I want the position Y not to be calculated when using the command. Only X and Z
Thank's for your answer !
 
Use the distance formula
code_language.skript:
set {_x1} to player's x-coord
set {_y1} to player's y-coord
set {_x2} to {Mid}'s x-coord
set {_y2} to {Mid}'s y-coord

set {_delta_x} to {_x2} - {_x1}
set {_delta_x} to {_delta_x}^2
set {_delta_y} to {_y2} - {_y1}
set {_delta_y} to {_delta_y}^2

set {_distance} to {_delta_x} - {_delta_y}
set {_distance} to sqrt({_distance})
 
  • Like
Reactions: Aralwen
Use this:
code_language.skript:
command /setmid:
    trigger:
        set {Mid} to player's location
command /mid:
    trigger:
        #<-- on aligne les deux variable sur la même hauteur -->
        set {_loc} to {Mid}
        set y-coordinate of {_loc} to y-coordinate of player
      
        #<-- compare les deux variables -->
        set {MidPos.%player%} to distance between player and {Mid}
        send "%{MidPos.%player%}%"
 
  • Like
Reactions: Aralwen
Use the distance formula
code_language.skript:
set {_x1} to player's x-coord
set {_y1} to player's y-coord
set {_x2} to {Mid}'s x-coord
set {_y2} to {Mid}'s y-coord

set {_delta_x} to {_x2} - {_x1}
set {_delta_x} to {_delta_x}^2
set {_delta_y} to {_y2} - {_y1}
set {_delta_y} to {_delta_y}^2

set {_distance} to {_delta_x} - {_delta_y}
set {_distance} to sqrt({_distance})
Hello, thank's for your answer !
It does not work, i want the X and Z positon only, but this don't work. The counter increases and does not descend depending on the position
 
Oh my bad i forgot y and z coords are switched in minecraft so change "set {_y1} to player's y-coord" to "set {_y1} to player's z-coord" and change "set {_y2} to {Mid}'s y-coord" to "set {_y2} to {Mid}'s z-coord"
 
  • Like
Reactions: Aralwen
Use this:
code_language.skript:
command /setmid:
    trigger:
        set {Mid} to player's location
command /mid:
    trigger:
        #<-- on aligne les deux variable sur la même hauteur -->
        set {_loc} to {Mid}
        set y-coordinate of {_loc} to y-coordinate of player
   
        #<-- compare les deux variables -->
        set {MidPos.%player%} to distance between player and {Mid}
        send "%{MidPos.%player%}%"
Really not stupid this algorithm !
Set the Y position to that Y position of Location. As a result, it can not change

Thank's ! :emoji_wink:
And Thank's too @Donut :emoji_slight_smile:
Solved
 
Status
Not open for further replies.