#include "script.h"

#include <string>
#include <ctime>

#pragma warning(disable : 4244 4305) // double <-> float conversions

std::string statusText;
DWORD statusTextDrawTicksMax;
bool statusTextGxtEntry;
bool showText = false;

Vehicle cargoplaneVeh,
cutterVeh,
annihilatorVeh,
skyliftVeh,
speedo2Veh,
mesa3Veh,
boxville3Veh,
cargobob2Veh,
fixterVeh,
police4Veh,
pony2Veh,
handlerVeh,
policebVeh,
dune2Veh,
ztypeVeh;

int cargoplaneSpawned = 0,
cutterSpawned = 0,
annihilatorSpawned = 0,
skyliftSpawned = 0,
speedo2Spawned = 0,
mesa3Spawned = 0,
boxville3Spawned = 0,
cargobob2Spawned = 0,
fixterSpawned = 0,
police4Spawned = 0,
pony2Spawned = 0,
handlerSpawned = 0,
policebSpawned = 0,
dune2Spawned = 0,
ztypeSpawned = 0;

void set_status_text(std::string str, DWORD time = 2500, bool isGxtEntry = false)
{
	statusText = str;
	statusTextDrawTicksMax = time;
	statusTextGxtEntry = isGxtEntry;
}

void update()
{
	Ped playerPed = PLAYER::PLAYER_PED_ID();
	Vehicle veh = PED::GET_VEHICLE_PED_IS_USING(playerPed);
	Vector3 position = ENTITY::GET_ENTITY_COORDS(playerPed, 1);

	/////////////////////////////////////////////////////////////////////////////////////////////
	/*BOOL xxxExist = ENTITY::DOES_ENTITY_EXIST(xxxVeh);
	DWORD xxx = GAMEPLAY::GET_HASH_KEY("xxx");
	int xxxSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(x, x, x, position.x, position.y, position.z, 0);

	if (xxxSpawnDistance < 1000)
	{
	if (xxxSpawned == 0)
	{
	STREAMING::REQUEST_MODEL(xxx);
	while (!STREAMING::HAS_MODEL_LOADED(xxx))
	WAIT(0);
	xxxVeh = VEHICLE::CREATE_VEHICLE(xxx, x, x, x, 0.0, 1, 1);
	ENTITY::SET_ENTITY_HEADING(xxxVeh, x);
	VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(xxxVeh);
	xxxSpawned += 1;
	}
	}

	Vector3 xxxVehPosition = ENTITY::GET_ENTITY_COORDS(xxxVeh, 1);
	int xxxVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(xxxVehPosition.x, xxxVehPosition.y, xxxVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(xxxVeh, 0))
	{
	ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&xxxVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, xxxVeh, 0) && xxxVehDistance > 1000)
	{
	ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&xxxVeh);
	}
	if (xxxSpawnDistance > 1000 && xxxVehDistance > 1000)
	{
	if (xxxSpawned == 1)
	{
	ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&xxxVeh);
	xxxSpawned -= 1;
	}
	}*///template
	/////////////////////////////////////////////////////////////////////////////////////////////

	BOOL cargoplaneExist = ENTITY::DOES_ENTITY_EXIST(cargoplaneVeh);
	DWORD cargoplane = GAMEPLAY::GET_HASH_KEY("cargoplane");
	int cargoplaneSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-1430.27f, -2668.88f, 19.38f, position.x, position.y, position.z, 0);

	if (cargoplaneSpawnDistance < 1000)
	{
		if (cargoplaneSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(cargoplane);
			while (!STREAMING::HAS_MODEL_LOADED(cargoplane))
				WAIT(0);
			cargoplaneVeh = VEHICLE::CREATE_VEHICLE(cargoplane, -1430.27f, -2668.88f, 19.38f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(cargoplaneVeh, 240.14f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(cargoplaneVeh);
			cargoplaneSpawned += 1;
		}
	}

	Vector3 cargoplaneVehPosition = ENTITY::GET_ENTITY_COORDS(cargoplaneVeh, 1);
	int cargoplaneVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(cargoplaneVehPosition.x, cargoplaneVehPosition.y, cargoplaneVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(cargoplaneVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cargoplaneVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, cargoplaneVeh, 0) && cargoplaneVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cargoplaneVeh);
	}
	if (cargoplaneSpawnDistance > 1000 && cargoplaneVehDistance > 1000)
	{
		if (cargoplaneSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cargoplaneVeh);
			cargoplaneSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL cutterExist = ENTITY::DOES_ENTITY_EXIST(cutterVeh);
	DWORD cutter = GAMEPLAY::GET_HASH_KEY("cutter");
	int cutterSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(66.37f, -774.79f, 17.31f, position.x, position.y, position.z, 0);

	if (cutterSpawnDistance < 1000)
	{
		if (cutterSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(cutter);
			while (!STREAMING::HAS_MODEL_LOADED(cutter))
				WAIT(0);
			cutterVeh = VEHICLE::CREATE_VEHICLE(cutter, 66.37f, -774.79f, 17.31f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(cutterVeh, 136.12f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(cutterVeh);
			cutterSpawned += 1;
		}
	}

	Vector3 cutterVehPosition = ENTITY::GET_ENTITY_COORDS(cutterVeh, 1);
	int cutterVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(cutterVehPosition.x, cutterVehPosition.y, cutterVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(cutterVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cutterVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, cutterVeh, 0) && cutterVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cutterVeh);
	}
	if (cutterSpawnDistance > 1000 && cutterVehDistance > 1000)
	{
		if (cutterSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cutterVeh);
			cutterSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL annihilatorExist = ENTITY::DOES_ENTITY_EXIST(annihilatorVeh);
	DWORD annihilator = GAMEPLAY::GET_HASH_KEY("annihilator");
	int annihilatorSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(2512.20f, -340.75f, 117.92f, position.x, position.y, position.z, 0);

	if (annihilatorSpawnDistance < 1000)
	{
		if (annihilatorSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(annihilator);
			while (!STREAMING::HAS_MODEL_LOADED(annihilator))
				WAIT(0);
			annihilatorVeh = VEHICLE::CREATE_VEHICLE(annihilator, 2512.20f, -340.75f, 117.92f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(annihilatorVeh, 317.31f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(annihilatorVeh);
			annihilatorSpawned += 1;
		}
	}

	Vector3 annihilatorVehPosition = ENTITY::GET_ENTITY_COORDS(annihilatorVeh, 1);
	int annihilatorVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(annihilatorVehPosition.x, annihilatorVehPosition.y, annihilatorVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(annihilatorVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&annihilatorVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, annihilatorVeh, 0) && annihilatorVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&annihilatorVeh);
	}
	if (annihilatorSpawnDistance > 1000 && annihilatorVehDistance > 1000)
	{
		if (annihilatorSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&annihilatorVeh);
			annihilatorSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL skyliftExist = ENTITY::DOES_ENTITY_EXIST(skyliftVeh);
	DWORD skylift = GAMEPLAY::GET_HASH_KEY("skylift");
	int skyliftSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-539.57f, -2804.50f, 7.83f, position.x, position.y, position.z, 0);

	if (skyliftSpawnDistance < 1000)
	{
		if (skyliftSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(skylift);
			while (!STREAMING::HAS_MODEL_LOADED(skylift))
				WAIT(0);
			skyliftVeh = VEHICLE::CREATE_VEHICLE(skylift, -539.57f, -2804.50f, 7.83f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(skyliftVeh, 166.94f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(skyliftVeh);
			skyliftSpawned += 1;
		}
	}

	Vector3 skyliftVehPosition = ENTITY::GET_ENTITY_COORDS(skyliftVeh, 1);
	int skyliftVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(skyliftVehPosition.x, skyliftVehPosition.y, skyliftVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(skyliftVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&skyliftVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, skyliftVeh, 0) && skyliftVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&skyliftVeh);
	}
	if (skyliftSpawnDistance > 1000 && skyliftVehDistance > 1000)
	{
		if (skyliftSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&skyliftVeh);
			skyliftSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL speedo2Exist = ENTITY::DOES_ENTITY_EXIST(speedo2Veh);
	DWORD speedo2 = GAMEPLAY::GET_HASH_KEY("speedo2");
	int speedo2SpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-1315.83f, -1263.96f, 4.31f, position.x, position.y, position.z, 0);

	if (speedo2SpawnDistance < 1000)
	{
		if (speedo2Spawned == 0)
		{
			STREAMING::REQUEST_MODEL(speedo2);
			while (!STREAMING::HAS_MODEL_LOADED(speedo2))
				WAIT(0);
			speedo2Veh = VEHICLE::CREATE_VEHICLE(speedo2, -1315.83f, -1263.96f, 4.31f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(speedo2Veh, 19.04f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(speedo2Veh);
			speedo2Spawned += 1;
		}
	}

	Vector3 speedo2VehPosition = ENTITY::GET_ENTITY_COORDS(speedo2Veh, 1);
	int speedo2VehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(speedo2VehPosition.x, speedo2VehPosition.y, speedo2VehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(speedo2Veh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&speedo2Veh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, speedo2Veh, 0) && speedo2VehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&speedo2Veh);
	}
	if (speedo2SpawnDistance > 1000 && speedo2VehDistance > 1000)
	{
		if (speedo2Spawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&speedo2Veh);
			speedo2Spawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL mesa3Exist = ENTITY::DOES_ENTITY_EXIST(mesa3Veh);
	DWORD mesa3 = GAMEPLAY::GET_HASH_KEY("mesa3");
	int mesa3SpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(446.73f, -3073.87f, 5.84f, position.x, position.y, position.z, 0);

	if (mesa3SpawnDistance < 1000)
	{
		if (mesa3Spawned == 0)
		{
			STREAMING::REQUEST_MODEL(mesa3);
			while (!STREAMING::HAS_MODEL_LOADED(mesa3))
				WAIT(0);
			mesa3Veh = VEHICLE::CREATE_VEHICLE(mesa3, 446.73f, -3073.87f, 5.84f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(mesa3Veh, 307.46f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(mesa3Veh);
			mesa3Spawned += 1;
		}
	}

	Vector3 mesa3VehPosition = ENTITY::GET_ENTITY_COORDS(mesa3Veh, 1);
	int mesa3VehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(mesa3VehPosition.x, mesa3VehPosition.y, mesa3VehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(mesa3Veh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&mesa3Veh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, mesa3Veh, 0) && mesa3VehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&mesa3Veh);
	}
	if (mesa3SpawnDistance > 1000 && mesa3VehDistance > 1000)
	{
		if (mesa3Spawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&mesa3Veh);
			mesa3Spawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL boxville3Exist = ENTITY::DOES_ENTITY_EXIST(boxville3Veh);
	DWORD boxville3 = GAMEPLAY::GET_HASH_KEY("boxville3");
	int boxville3SpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(3531.36f, 3758.88f, 29.82f, position.x, position.y, position.z, 0);

	if (boxville3SpawnDistance < 1000)
	{
		if (boxville3Spawned == 0)
		{
			STREAMING::REQUEST_MODEL(boxville3);
			while (!STREAMING::HAS_MODEL_LOADED(boxville3))
				WAIT(0);
			boxville3Veh = VEHICLE::CREATE_VEHICLE(boxville3, 3531.36f, 3758.88f, 29.82f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(boxville3Veh, 259.64f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(boxville3Veh);
			boxville3Spawned += 1;
		}
	}

	Vector3 boxville3VehPosition = ENTITY::GET_ENTITY_COORDS(boxville3Veh, 1);
	int boxville3VehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(boxville3VehPosition.x, boxville3VehPosition.y, boxville3VehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(boxville3Veh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&boxville3Veh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, boxville3Veh, 0) && boxville3VehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&boxville3Veh);
	}
	if (boxville3SpawnDistance > 1000 && boxville3VehDistance > 1000)
	{
		if (boxville3Spawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&boxville3Veh);
			boxville3Spawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL cargobob2Exist = ENTITY::DOES_ENTITY_EXIST(cargobob2Veh);
	DWORD cargobob2 = GAMEPLAY::GET_HASH_KEY("cargobob2");
	int cargobob2SpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-1214.11f, -1801.33f, 4.36f, position.x, position.y, position.z, 0);

	if (cargobob2SpawnDistance < 1000)
	{
		if (cargobob2Spawned == 0)
		{
			STREAMING::REQUEST_MODEL(cargobob2);
			while (!STREAMING::HAS_MODEL_LOADED(cargobob2))
				WAIT(0);
			cargobob2Veh = VEHICLE::CREATE_VEHICLE(cargobob2, -1214.11f, -1801.33f, 4.36f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(cargobob2Veh, 35.10f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(cargobob2Veh);
			cargobob2Spawned += 1;
		}
	}

	Vector3 cargobob2VehPosition = ENTITY::GET_ENTITY_COORDS(cargobob2Veh, 1);
	int cargobob2VehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(cargobob2VehPosition.x, cargobob2VehPosition.y, cargobob2VehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(cargobob2Veh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cargobob2Veh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, cargobob2Veh, 0) && cargobob2VehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cargobob2Veh);
	}
	if (cargobob2SpawnDistance > 1000 && cargobob2VehDistance > 1000)
	{
		if (cargobob2Spawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&cargobob2Veh);
			cargobob2Spawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL fixterExist = ENTITY::DOES_ENTITY_EXIST(fixterVeh);
	DWORD fixter = GAMEPLAY::GET_HASH_KEY("fixter");
	int fixterSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-622.66f, 241.65f, 81.49f, position.x, position.y, position.z, 0);

	if (fixterSpawnDistance < 1000)
	{
		if (fixterSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(fixter);
			while (!STREAMING::HAS_MODEL_LOADED(fixter))
				WAIT(0);
			fixterVeh = VEHICLE::CREATE_VEHICLE(fixter, -622.66f, 241.65f, 81.49f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(fixterVeh, 87.24f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(fixterVeh);
			fixterSpawned += 1;
		}
	}

	Vector3 fixterVehPosition = ENTITY::GET_ENTITY_COORDS(fixterVeh, 1);
	int fixterVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(fixterVehPosition.x, fixterVehPosition.y, fixterVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(fixterVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&fixterVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, fixterVeh, 0) && fixterVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&fixterVeh);
	}
	if (fixterSpawnDistance > 1000 && fixterVehDistance > 1000)
	{
		if (fixterSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&fixterVeh);
			fixterSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL police4Exist = ENTITY::DOES_ENTITY_EXIST(police4Veh);
	DWORD police4 = GAMEPLAY::GET_HASH_KEY("police4");
	int police4SpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(376.96f, -1830.01f, 28.39f, position.x, position.y, position.z, 0);

	if (police4SpawnDistance < 1000)
	{
		if (police4Spawned == 0)
		{
			STREAMING::REQUEST_MODEL(police4);
			while (!STREAMING::HAS_MODEL_LOADED(police4))
				WAIT(0);
			police4Veh = VEHICLE::CREATE_VEHICLE(police4, 376.96f, -1830.01f, 28.39f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(police4Veh, 167.22f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(police4Veh);
			police4Spawned += 1;
		}
	}

	Vector3 police4VehPosition = ENTITY::GET_ENTITY_COORDS(police4Veh, 1);
	int police4VehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(police4VehPosition.x, police4VehPosition.y, police4VehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(police4Veh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&police4Veh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, police4Veh, 0) && police4VehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&police4Veh);
	}
	if (police4SpawnDistance > 1000 && police4VehDistance > 1000)
	{
		if (police4Spawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&police4Veh);
			police4Spawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL pony2Exist = ENTITY::DOES_ENTITY_EXIST(pony2Veh);
	DWORD pony2 = GAMEPLAY::GET_HASH_KEY("pony2");
	int pony2SpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-1155.34f, -1567.54f, 4.21f, position.x, position.y, position.z, 0);

	if (pony2SpawnDistance < 1000)
	{
		if (pony2Spawned == 0)
		{
			STREAMING::REQUEST_MODEL(pony2);
			while (!STREAMING::HAS_MODEL_LOADED(pony2))
				WAIT(0);
			pony2Veh = VEHICLE::CREATE_VEHICLE(pony2, -1155.34f, -1567.54f, 4.21f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(pony2Veh, 34.53f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(pony2Veh);
			pony2Spawned += 1;
		}
	}

	Vector3 pony2VehPosition = ENTITY::GET_ENTITY_COORDS(pony2Veh, 1);
	int pony2VehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(pony2VehPosition.x, pony2VehPosition.y, pony2VehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(pony2Veh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&pony2Veh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, pony2Veh, 0) && pony2VehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&pony2Veh);
	}
	if (pony2SpawnDistance > 1000 && pony2VehDistance > 1000)
	{
		if (pony2Spawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&pony2Veh);
			pony2Spawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL policebExist = ENTITY::DOES_ENTITY_EXIST(policebVeh);
	DWORD policeb = GAMEPLAY::GET_HASH_KEY("policeb");
	int policebSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-2566.83f, 2313.10f, 32.69f, position.x, position.y, position.z, 0);

	if (policebSpawnDistance < 1000)
	{
		if (policebSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(policeb);
			while (!STREAMING::HAS_MODEL_LOADED(policeb))
				WAIT(0);
			policebVeh = VEHICLE::CREATE_VEHICLE(policeb, -2566.83f, 2313.10f, 32.69f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(policebVeh, 4.16f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(policebVeh);
			policebSpawned += 1;
		}
	}

	Vector3 policebVehPosition = ENTITY::GET_ENTITY_COORDS(policebVeh, 1);
	int policebVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(policebVehPosition.x, policebVehPosition.y, policebVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(policebVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&policebVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, policebVeh, 0) && policebVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&policebVeh);
	}
	if (policebSpawnDistance > 1000 && policebVehDistance > 1000)
	{
		if (policebSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&policebVeh);
			policebSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL handlerExist = ENTITY::DOES_ENTITY_EXIST(handlerVeh);
	DWORD handler = GAMEPLAY::GET_HASH_KEY("handler");
	int handlerSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-419.12f, -2285.27f, 7.79f, position.x, position.y, position.z, 0);

	if (handlerSpawnDistance < 1000)
	{
		if (handlerSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(handler);
			while (!STREAMING::HAS_MODEL_LOADED(handler))
				WAIT(0);
			handlerVeh = VEHICLE::CREATE_VEHICLE(handler, -419.12f, -2285.27f, 7.79f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(handlerVeh, 359.43f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(handlerVeh);
			handlerSpawned += 1;
		}
	}

	Vector3 handlerVehPosition = ENTITY::GET_ENTITY_COORDS(handlerVeh, 1);
	int handlerVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(handlerVehPosition.x, handlerVehPosition.y, handlerVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(handlerVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&handlerVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, handlerVeh, 0) && handlerVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&handlerVeh);
	}
	if (handlerSpawnDistance > 1000 && handlerVehDistance > 1000)
	{
		if (handlerSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&handlerVeh);
			handlerSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL dune2Exist = ENTITY::DOES_ENTITY_EXIST(dune2Veh);
	DWORD dune2 = GAMEPLAY::GET_HASH_KEY("dune2");
	int dune2SpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(2476.39f, 3779.22f, 40.98f, position.x, position.y, position.z, 0);

	if (dune2SpawnDistance < 1000)
	{
		if (dune2Spawned == 0)
		{
			STREAMING::REQUEST_MODEL(dune2);
			while (!STREAMING::HAS_MODEL_LOADED(dune2))
				WAIT(0);
			dune2Veh = VEHICLE::CREATE_VEHICLE(dune2, 2476.39f, 3779.22f, 40.98f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(dune2Veh, 358.24f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(dune2Veh);
			dune2Spawned += 1;
		}
	}

	Vector3 dune2VehPosition = ENTITY::GET_ENTITY_COORDS(dune2Veh, 1);
	int dune2VehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(dune2VehPosition.x, dune2VehPosition.y, dune2VehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(dune2Veh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&dune2Veh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, dune2Veh, 0) && dune2VehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&dune2Veh);
	}
	if (dune2SpawnDistance > 1000 && dune2VehDistance > 1000)
	{
		if (dune2Spawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&dune2Veh);
			dune2Spawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	BOOL ztypeExist = ENTITY::DOES_ENTITY_EXIST(ztypeVeh);
	DWORD ztype = GAMEPLAY::GET_HASH_KEY("ztype");
	int ztypeSpawnDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(-310.70f, 225.91f, 87.32f, position.x, position.y, position.z, 0);

	if (ztypeSpawnDistance < 1000)
	{
		if (ztypeSpawned == 0)
		{
			STREAMING::REQUEST_MODEL(ztype);
			while (!STREAMING::HAS_MODEL_LOADED(ztype))
				WAIT(0);
			ztypeVeh = VEHICLE::CREATE_VEHICLE(ztype, -310.70f, 225.91f, 87.32f, 0.0, 1, 1);
			ENTITY::SET_ENTITY_HEADING(ztypeVeh, 281.07f);
			VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(ztypeVeh);
			ztypeSpawned += 1;
		}
	}

	Vector3 ztypeVehPosition = ENTITY::GET_ENTITY_COORDS(ztypeVeh, 1);
	int ztypeVehDistance = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(ztypeVehPosition.x, ztypeVehPosition.y, ztypeVehPosition.z, position.x, position.y, position.z, 0);

	if (!VEHICLE::IS_VEHICLE_DRIVEABLE(ztypeVeh, 0))
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&ztypeVeh);
	}
	if (!PED::IS_PED_IN_VEHICLE(playerPed, ztypeVeh, 0) && ztypeVehDistance > 1000)
	{
		ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&ztypeVeh);
	}
	if (ztypeSpawnDistance > 1000 && ztypeVehDistance > 1000)
	{
		if (ztypeSpawned == 1)
		{
			ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&ztypeVeh);
			ztypeSpawned -= 1;
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
}

void update_status_text()
{
	if (showText == true)
	{
		UI::SET_TEXT_FONT(0);
		UI::SET_TEXT_SCALE(0.0, 0.0);
		UI::SET_TEXT_COLOUR(255, 255, 255, 255);
		UI::SET_TEXT_WRAP(0.0, 1.0);
		UI::SET_TEXT_CENTRE(1);
		UI::SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0);
		UI::SET_TEXT_EDGE(1, 0, 0, 0, 205);
		if (statusTextGxtEntry)
		{
			UI::_SET_TEXT_ENTRY((char *)statusText.c_str());
		}
		else
		{
			UI::_SET_TEXT_ENTRY("STRING");
			UI::_ADD_TEXT_COMPONENT_STRING((char *)statusText.c_str());
		}
		UI::_DRAW_TEXT(0.0, 0.0);
	}
}

void main()
{
	while (true)
	{
		update();
		WAIT(0);
	}
}

void ScriptMain()
{
	srand(GetTickCount());
	main();
}

