Search In
• More options...
Find results that contain...
Find results in...

# [.NET] Let's Discuss Range/Distance

## Recommended Posts

Hello everyone. In order to make the scripts I desire, I need to understand how I can effectively use range to my advantage. I'll get right to the point.

What I Want To Accomplish:

-creating random spawn points for call outs to occur (preferably randomized based on location or distance)

-spawning a vehicle with Peds in it and having them drive to my location like a normal, dispatched vehicle (not spawning in front of me)

-same thing but for ambient PEDS or spawned in PEDS

-creating that police search circle around a certain area

My Logic:

-using Vectors

-some way to check whether the area is not obstructed

-check for spawning on street

-natives to determine range or something

-learning how to determine range using natives or .NET API

-learning how to spawn a vehicle far enough away and task it to drive to your location

-learning to gather ambient peds within range and have them do something (come to player)

-learning how to create a search circle with a certain range

-learning how to randomize the fallouts created based on different range or location

This is HUGE for my script development, so I'll be coming back and adding to this topic as discussion goes.

##### Share on other sites

-some way to check whether the area is not obstructed

-check for spawning on street

There is a function that does just that:

Vector3 World.GetNextPositionOnStreet(Vector3 position, bool unoccupied)

The only issue, is that it doesn't return the heading for the position. So your vehicle may be facing the wrong way when spawning and the driver will have to turn around on the road, etc.

You will need to check manually if the area is obstructed: IS_POINT_OBSCURED_BY_A_MISSION_ENTITY

-learning how to determine range using natives or .NET API

Do you mean distance between two coordinates?

if so:

`// Calculate the distance between two coordinates using GPS pathfloat World.CalculateTravelDistance(Vector3 origin, Vector3 destination)// Calculate the distance between two coordinatesfloat World.GetDistance(Vector3 origin, Vector3 destination)`

-learning how to spawn a vehicle far enough away and task it to drive to your location

Maybe not the best method, but you can use Vector3's function Vector3 Around(float distance) which return a random location in a radius of distance.

Then, if you want to be sure it is far enough, you can run this function until the distance between your character and the returned value is adequate (Vector3 also has a float DistanceTo(Vector3 position) which you can use to tell if it is far enough).

Driving a vehicle to the player is quite easy, you can use Ped's function Task.DriveTo(Vehicle vehicle, Vector3 target, float radius, float speed, DrivingStyle)

-learning to gather ambient peds within range and have them do something (come to player)

World.GetNearbyPeds(Vector3 position, float radius) is certainly what you want. You use this function with the player's coordinates and a radius, and it will return an array with the peds around the player.

Then for each Ped in the array, you call ped's Task.GoTo(Entity target)

-learning how to create a search circle with a certain range

I think it is a minimap scaleform since this seems to fit your needs (not tested) https://scaleform.devtesting.pizza/minimap.html#minimap - function SET_WANTED_LEVEL(circle, wantedLevel, radius) Edited by Bob_74

##### Share on other sites

Once again, Bob. Always quick to answer.

"Do you mean distance between two coordinates?"

The script I have in mind is a mini callout script. In order to make it work the way I want, I need to be able to randomize the distance it takes to drive to where the callout occurs and also will need to randomize the locations where each callout spawns. Aka, I don't want to hard code callout areas unless I have to. Would rather have them randomized based on both distance and location.

Vector3 Position. This could also take the players' position as an argument, right?

So you're saying the wanted level search circle may be a scaleform? Okay. I'll look into it.

##### Share on other sites

The script I have in mind is a mini callout script. In order to make it work the way I want, I need to be able to randomize the distance it takes to drive to where the callout occurs and also will need to randomize the locations where each callout spawns. Aka, I don't want to hard code callout areas unless I have to. Would rather have them randomized based on both distance and location.

For the callout itself, I would hardcode some locations because an entirely random location could lead at the top of a mountain or in the middle of the sea.

You can set a large radius when calling Around() function to better randomize the position.

Then you can call World.GetNextPositionOnSidewalk or World.GetNextPositionOnStreet depending where you want it to occur.

UNLESS, you want it to happen only around the player. Then you can use Around() with the player's position without having to hardcode any coordinates.

Vector3 Position. This could also take the players' position as an argument, right?

Yes, the player's position is a Vector3.

## Create an account

Register a new account