Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <stack>
- std::stack<Any> GetNearbyPeds(Ped ped, float radius, int maxAmount)
- {
- std::stack<Any> peds;
- int *handles = new int[maxAmount * 2 + 2];
- //0 index is the size of the array
- handles[0] = maxAmount;
- int count = PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), (Any*)handles, -1);
- if (handles != NULL)
- {
- for (int i = 0; i < count; i++)
- {
- int offsettedID = i * 2 + 2;
- if (handles[offsettedID] != NULL && ENTITY::DOES_ENTITY_EXIST(handles[offsettedID]))
- {
- Vector3 pedCoord = ENTITY::GET_ENTITY_COORDS(ped, 1);
- Vector3 ped2Coord = ENTITY::GET_ENTITY_COORDS(handles[offsettedID], 1);
- if (GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(pedCoord.x, pedCoord.y, pedCoord.z, ped2Coord.x, ped2Coord.y, ped2Coord.z, 1) <= radius)
- {
- peds.push(handles[offsettedID]);
- }
- }
- }
- }
- return peds;
- }
- std::stack<Any> GetNearbyVehicles(Ped ped, float radius, int maxAmount)
- {
- std::stack<Any> vehs;
- int *handles = new int[maxAmount * 2 + 2];
- //0 index is the size of the array
- handles[0] = maxAmount;
- int count = PED::GET_PED_NEARBY_VEHICLES(PLAYER::PLAYER_PED_ID(), (Any*)handles);
- if (handles != NULL)
- {
- for (int i = 0; i < count; i++)
- {
- int offsettedID = i * 2 + 2;
- if (handles[offsettedID] != NULL && ENTITY::DOES_ENTITY_EXIST(handles[offsettedID]))
- {
- Vector3 pedCoord = ENTITY::GET_ENTITY_COORDS(ped, 1);
- Vector3 vehCoord = ENTITY::GET_ENTITY_COORDS(handles[offsettedID], 1);
- if (GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(pedCoord.x, pedCoord.y, pedCoord.z, vehCoord.x, vehCoord.y, vehCoord.z, 1) <= radius)
- {
- vehs.push(handles[offsettedID]);
- }
- }
- }
- }
- return vehs;
- }
- //example nearby vehicles
- std::stack<Any> vehs = GetNearbyVehicles(PLAYER::PLAYER_PED_ID(), 100, 10000);
- while (!vehs.empty())
- {
- if (vehs.top() != NULL && ENTITY::DOES_ENTITY_EXIST(vehs.top()))
- {
- //do stuff
- }
- vehs.pop();
- }
- //example nearby peds
- std::stack<Any> peds = GetNearbyPeds(PLAYER::PLAYER_PED_ID(), 100, 10000);
- while (!peds.empty())
- {
- if (peds.top() != NULL && ENTITY::DOES_ENTITY_EXIST(peds.top()))
- {
- //do stuff
- }
- peds.pop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement