# code in range

## Recommended Posts

hi

please send example code for ( if in range )

I want to be able to use a cmd when the player is in a certain range

sorry for bad english

Edited by javad_iran

#### Share this post

##### Share on other sites
```public static bool IsInRangeOfPoint(Vector3 playerPos, Vector3 target, float range)
{
var direct = new Vector3(target.X - playerPos.X, target.Y - playerPos.Y, target.Z - playerPos.Z);
var len = direct.X * direct.X + direct.Y * direct.Y + direct.Z * direct.Z;
return range * range > len;
}```

Example of usage:

```if(IsInRangeOfPoint(player.position, new Vector3(0, 0, 0), 5f))
{
// the player is close to the coordinates >> (0, 0, 0)
}
else
{
// the player is not close to the coordinates.
}```

#### Share this post

##### Share on other sites
14 hours ago, skazi said:
```public static bool IsInRangeOfPoint(Vector3 playerPos, Vector3 target, float range)
{
var direct = new Vector3(target.X - playerPos.X, target.Y - playerPos.Y, target.Z - playerPos.Z);
var len = direct.X * direct.X + direct.Y * direct.Y + direct.Z * direct.Z;
return range * range > len;
}```

Example of usage:

```if(IsInRangeOfPoint(player.position, new Vector3(0, 0, 0), 5f))
{
// the player is close to the coordinates >> (0, 0, 0)
}
else
{
// the player is not close to the coordinates.
}```

thanks.

how to get time for your cmd?

example:

```if(IsInRangeOfPoint(player.position, new Vector3(0, 0, 0), 5f))
{
console.log(`\${player.name} use the cmd in \${time} `);
}
```

for \${time} please help

sorry for bad english

#### Share this post

##### Share on other sites

...

Edited by javad_iran

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Recently Browsing   0 members

No registered users viewing this page.