Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float getDistanceBetweenVectors(Vector3 vector1, Vector3 vector2){
- return SYSTEM::VDIST(vector1.x, vector1.y, vector1.z, vector2.x, vector2.y, vector2.z);
- }
- bool doesEntityExistsAndIsNotNull(Entity entity)
- {
- return (entity != NULL && ENTITY::DOES_ENTITY_EXIST(entity));
- }
- Ped getPlayerPed()
- {
- return PLAYER::PLAYER_PED_ID();
- }
- Ped getClosestPed(Vector3 point, float maxDistance) // distance in meters
- {
- Ped ped = NULL;
- float shortestDistance = maxDistance; // start value
- const int ARR_SIZE = 1024;
- Ped peds[ARR_SIZE];
- int count = worldGetAllPeds(peds, ARR_SIZE);
- if (peds != NULL)
- {
- for (int i = 0; i < count; i++)
- {
- if (doesEntityExistsAndIsNotNull(peds[i]))
- {
- Vector3 pedCoords = ENTITY::GET_ENTITY_COORDS(peds[i], true);
- float distanceFound = getDistanceBetweenVectors(point, pedCoords);
- if (distanceFound <= shortestDistance)
- {
- shortestDistance = distanceFound;
- ped = peds[i];
- }
- }
- }
- }
- return ped;
- }
- void howToUseExample(){
- if (doesEntityExistsAndIsNotNull(getPlayerPed()))
- {
- Vector3 playerCoords = ENTITY::GET_ENTITY_COORDS(getPlayerPed(), true);
- Ped closestPedToPlayerPos = getClosestPed(playerCoords, 100);
- if (doesEntityExistsAndIsNotNull(closestPedToPlayerPos))
- {
- // Do something with closestPedToPlayerPos
- }
- }
- }
- // Fixed a few things
Advertisement
RAW Paste Data
Copied
Advertisement