Find Nearest Person

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

Crocie

Member
Jul 2, 2021
36
0
6
16
Line 8:
I need an expression similar to that.

Code:
command /eventstart:
    permission: "event.admin"
    trigger:
        loop players in radius 200 of {eventpos}:
            set {target} to loop-player
            if {target} is set:
                set {eventpos} to location at (0, 4, 0) in world "world"
                message "&9%closest player to {eventpos}%"
        if {target} is not set:
            message "&9No Players Within 200 blocks."
 
Code:
function nearestPlayer(p:player,range:number=100) :: player:
    set {_loc} to location of {_p}
    set {_pllist::*} to all players in radius {_range} around {_loc} where [player input is not {_p}]
    set {_nearest} to first element of {_pllist::*}
    loop {_pllist::*}:
        if distance between location of loop-value and {_loc} is less than distance between {_loc} and {_nearest}:
            set {_nearest} to loop-value
    return {_nearest}