<commit_before>#include <YSI\y_hooks>


#define MAX_VEHICLES_IN_RANGE			(8)
#define VEH_STREAMER_AREA_IDENTIFIER	(500)


enum e_vehicle_range_data
{
			E_VEHICLE_AREA_VEHICLEID,
Float:		E_VEHICLE_AREA_DISTANCE
}

static
			varea_AreaID[MAX_VEHICLES],
			varea_NearList[MAX_PLAYERS][MAX_VEHICLES_IN_RANGE],
Iterator:	varea_NearIndex[MAX_PLAYERS]<MAX_VEHICLES_IN_RANGE>;


forward OnPlayerInteractVehicle(playerid, vehicleid, Float:angle);
forward OnPlayerEnterVehicleArea(playerid, vehicleid);
forward OnPlayerLeaveVehicleArea(playerid, vehicleid);


static HANDLER = -1;


hook OnScriptInit()
{
	print("\n[OnScriptInit] Initialising 'Vehicle/Interact'...");

	Iter_Init(varea_NearIndex);

	HANDLER = debug_register_handler("vehicle/interact");
}


/*==============================================================================

	Core

==============================================================================*/


stock CreateVehicleArea(vehicleid)
{
	if(!IsValidVehicle(vehicleid))
		return 0;

	new
		Float:x,
		Float:y,
		Float:z,
		data[2];

	GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, x, y, z);

	varea_AreaID[vehicleid] = CreateDynamicSphere(0.0, 0.0, 0.0, (y / 2.0) + 3.0, 0);
	AttachDynamicAreaToVehicle(varea_AreaID[vehicleid], vehicleid);

	data[0] = VEH_STREAMER_AREA_IDENTIFIER;
	data[1] = vehicleid;

	Streamer_SetArrayData(STREAMER_TYPE_AREA, varea_AreaID[vehicleid], E_STREAMER_EXTRA_ID, data, 2);

	return 1;
}


/*==============================================================================

	Internal

==============================================================================*/


public OnVehicleCreated(vehicleid)
{
	CreateVehicleArea(vehicleid);

	#if defined vint_OnVehicleCreated
		return vint_OnVehicleCreated(vehicleid);
	#else
		return 1;
	#endif
}
#if defined _ALS_OnVehicleCreated
	#undef OnVehicleCreated
#else
	#define _ALS_OnVehicleCreated
#endif

#define OnVehicleCreated vint_OnVehicleCreated
#if defined vint_OnVehicleCreated
	forward vint_OnVehicleCreated(vehicleid);
#endif

public OnPlayerEnterDynamicArea(playerid, areaid)
{
	_vint_EnterArea(playerid, areaid);

	#if defined vint_OnPlayerEnterDynamicArea
		return vint_OnPlayerEnterDynamicArea(playerid, areaid);
	#else
		return 1;
	#endif
}
#if defined _ALS_OnPlayerEnterDynamicArea
	#undef OnPlayerEnterDynamicArea
#else
	#define _ALS_OnPlayerEnterDynamicArea
#endif
 
#define OnPlayerEnterDynamicArea vint_OnPlayerEnterDynamicArea
#if defined vint_OnPlayerEnterDynamicArea
	forward vint_OnPlayerEnterDynamicArea(playerid, areaid);
#endif

public OnPlayerLeaveDynamicArea(playerid, areaid)
{
	_vint_LeaveArea(playerid, areaid);

	#if defined vint_OnPlayerLeaveDynamicArea
		return vint_OnPlayerLeaveDynamicArea(playerid, areaid);
	#else
		return 1;
	#endif
}
#if defined _ALS_OnPlayerLeaveDynamicArea
	#undef OnPlayerLeaveDynamicArea
#else
	#define _ALS_OnPlayerLeaveDynamicArea
#endif
 
#define OnPlayerLeaveDynamicArea vint_OnPlayerLeaveDynamicArea
#if defined vint_OnPlayerLeaveDynamicArea
	forward vint_OnPlayerLeaveDynamicArea(playerid, areaid);
#endif

_vint_EnterArea(playerid, areaid)
{
	d:1:HANDLER("[_vint_EnterArea] %d %d", playerid, areaid);

	if(IsPlayerInAnyVehicle(playerid))
	{
		d:1:HANDLER("[_vint_EnterArea] Player in vehicle");
		return;
	}

	if(Iter_Count(varea_NearIndex[playerid]) == MAX_VEHICLES_IN_RANGE)
	{
		d:1:HANDLER("[_vint_EnterArea] Player already in maximum amount of vehicle areas");
		return;
	}

	new data[2];

	Streamer_GetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, data, 2);

	if(data[0] != VEH_STREAMER_AREA_IDENTIFIER)
	{
		d:1:HANDLER("[_vint_EnterArea] Area not vehicle area type");
		return;
	}

	if(!IsValidVehicle(data[1]))
	{
		d:1:HANDLER("[_vint_EnterArea] Area contains invalid vehicle ID");
		return;
	}

	new cell = Iter_Free(varea_NearIndex[playerid]);

	varea_NearList[playerid][cell] = data[1];
	Iter_Add(varea_NearIndex[playerid], cell);

	CallLocalFunction("OnPlayerEnterVehicleArea", "dd", playerid, data[1]);

	return;
}

_vint_LeaveArea(playerid, areaid)
{
	if(IsPlayerInAnyVehicle(playerid))
	{
		d:1:HANDLER("[_vint_LeaveArea] Player in vehicle");
		return;
	}

	if(Iter_Count(varea_NearIndex[playerid]) == 0)
	{
		d:1:HANDLER("[_vint_LeaveArea] Vehicle area list is empty");
		return;
	}

	new data[2];

	Streamer_GetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, data, 2);

	if(data[0] != VEH_STREAMER_AREA_IDENTIFIER)
	{<commit_msg>Added a workaround for a bug with vehicle interacts<commit_after>#include <YSI\y_hooks>


#define MAX_VEHICLES_IN_RANGE			(8)
#define VEH_STREAMER_AREA_IDENTIFIER	(500)


enum e_vehicle_range_data
{
			E_VEHICLE_AREA_VEHICLEID,
Float:		E_VEHICLE_AREA_DISTANCE
}

static
			varea_AreaID[MAX_VEHICLES],
			varea_NearList[MAX_PLAYERS][MAX_VEHICLES_IN_RANGE],
Iterator:	varea_NearIndex[MAX_PLAYERS]<MAX_VEHICLES_IN_RANGE>;


forward OnPlayerInteractVehicle(playerid, vehicleid, Float:angle);
forward OnPlayerEnterVehicleArea(playerid, vehicleid);
forward OnPlayerLeaveVehicleArea(playerid, vehicleid);


static HANDLER = -1;


hook OnScriptInit()
{
	print("\n[OnScriptInit] Initialising 'Vehicle/Interact'...");

	Iter_Init(varea_NearIndex);

	HANDLER = debug_register_handler("vehicle/interact");
}


/*==============================================================================

	Core

==============================================================================*/


stock CreateVehicleArea(vehicleid)
{
	if(!IsValidVehicle(vehicleid))
		return 0;

	new
		Float:x,
		Float:y,
		Float:z,
		data[2];

	GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, x, y, z);

	varea_AreaID[vehicleid] = CreateDynamicSphere(0.0, 0.0, 0.0, (y / 2.0) + 3.0, 0);
	AttachDynamicAreaToVehicle(varea_AreaID[vehicleid], vehicleid);

	data[0] = VEH_STREAMER_AREA_IDENTIFIER;
	data[1] = vehicleid;

	Streamer_SetArrayData(STREAMER_TYPE_AREA, varea_AreaID[vehicleid], E_STREAMER_EXTRA_ID, data, 2);

	return 1;
}


/*==============================================================================

	Internal

==============================================================================*/


public OnVehicleCreated(vehicleid)
{
	CreateVehicleArea(vehicleid);

	#if defined vint_OnVehicleCreated
		return vint_OnVehicleCreated(vehicleid);
	#else
		return 1;
	#endif
}
#if defined _ALS_OnVehicleCreated
	#undef OnVehicleCreated
#else
	#define _ALS_OnVehicleCreated
#endif

#define OnVehicleCreated vint_OnVehicleCreated
#if defined vint_OnVehicleCreated
	forward vint_OnVehicleCreated(vehicleid);
#endif

public OnPlayerEnterDynamicArea(playerid, areaid)
{
	_vint_EnterArea(playerid, areaid);

	#if defined vint_OnPlayerEnterDynamicArea
		return vint_OnPlayerEnterDynamicArea(playerid, areaid);
	#else
		return 1;
	#endif
}
#if defined _ALS_OnPlayerEnterDynamicArea
	#undef OnPlayerEnterDynamicArea
#else
	#define _ALS_OnPlayerEnterDynamicArea
#endif
 
#define OnPlayerEnterDynamicArea vint_OnPlayerEnterDynamicArea
#if defined vint_OnPlayerEnterDynamicArea
	forward vint_OnPlayerEnterDynamicArea(playerid, areaid);
#endif

public OnPlayerLeaveDynamicArea(playerid, areaid)
{
	_vint_LeaveArea(playerid, areaid);

	#if defined vint_OnPlayerLeaveDynamicArea
		return vint_OnPlayerLeaveDynamicArea(playerid, areaid);
	#else
		return 1;
	#endif
}
#if defined _ALS_OnPlayerLeaveDynamicArea
	#undef OnPlayerLeaveDynamicArea
#else
	#define _ALS_OnPlayerLeaveDynamicArea
#endif
 
#define OnPlayerLeaveDynamicArea vint_OnPlayerLeaveDynamicArea
#if defined vint_OnPlayerLeaveDynamicArea
	forward vint_OnPlayerLeaveDynamicArea(playerid, areaid);
#endif

_vint_EnterArea(playerid, areaid)
{
	d:1:HANDLER("[_vint_EnterArea] %d %d", playerid, areaid);

	if(IsPlayerInAnyVehicle(playerid))
	{
		d:1:HANDLER("[_vint_EnterArea] Player in vehicle");
		return;
	}

	if(Iter_Count(varea_NearIndex[playerid]) == MAX_VEHICLES_IN_RANGE)
	{
		d:1:HANDLER("[_vint_EnterArea] Player already in maximum amount of vehicle areas");
		return;
	}

	new data[2];

	Streamer_GetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, data, 2);

	if(data[0] != VEH_STREAMER_AREA_IDENTIFIER)
	{
		d:1:HANDLER("[_vint_EnterArea] Area not vehicle area type");
		return;
	}

	if(!IsValidVehicle(data[1]))
	{
		d:1:HANDLER("[_vint_EnterArea] Area contains invalid vehicle ID");
		return;
	}

	new bool:exists = false;

	foreach(new i : varea_NearIndex[playerid])
	{
		if(varea_NearList[playerid][i] == data[1])
		{
			exists = true;
			break;
		}
	}

	if(!exists)
	{
		new cell = Iter_Free(varea_NearIndex[playerid]);

		varea_NearList[playerid][cell] = data[1];
		Iter_Add(varea_NearIndex[playerid], cell);
	}
	else
	{
		printf("ERROR: Vehicle %d already in NearList for player %d", data[1], playerid);
	}

	CallLocalFunction("OnPlayerEnterVehicleArea", "dd", playerid, data[1]);

	return;
}

_vint_LeaveArea(playerid, areaid)
{
	if(IsPlayerInAnyVehicle(playerid))
	{
		d:1:HANDLER("[_vint_LeaveArea] Player in vehicle");
		return;
	}

	if(Iter_Count(varea_NearIndex[playerid]) == 0)
	{
		d:1:HANDLER("[_vint_LeaveArea] Vehicle area list is empty");
		return;
	}

	new data[2];

	Streamer_GetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, data, 2);

	if(data[0] != VEH_STREAMER_AREA_IDENTIFIER)
	{
{'fraction_non_alphanumeric': 0.16534835843536677, 'fraction_numerical': 0.009318452703434826, 'mean_word_length': 7.530499075785582, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '960242', 'n_tokens_mistral': 3588, 'n_tokens_neox': 3359, 'n_words': 556}