How to detect a vehicle
#1

I have been trying to create a vehicle system for my role play gamemode where you can buy vehicles at an authorised dealer. How I can detect a vehicle from scriptfiles' file, I'm not referring to the ID on the server. Because there are other vehicles for jobs. Moreover, I would like a vehicle to dissapear when its owner has been 24 hours disconnected. Well, this is how the vehicle system is made (I won't put all the code for now because it's large and I don't know have to do spoilers):

Код:
new PlayerInfo[MAX_PLAYERS][Info];

enum Vehicle
{
	Model,
	NumberPlate[MAX_PLAYER_NAME],
	Float:Positionx,
	Float:Positiony,
	Float:Positionz,
	Float:Angle,
	Interior,
	Virtual,
	Owner[MAX_PLAYER_NAME],
	Owned,
	Hours,
	Locked,
	ColorOne,
	ColorTwo
};

new VehicleInfo[6][Vehicle];

//ongamemodeinit

for(new h = 0; h < sizeof(VehicleInfo); h++)
	{
			if(VehicleInfo[h][Owned] == 1)
			{
			new string[15],
            vehicle = CreateVehicle(VehicleInfo[h][Model],VehicleInfo[h][Positionx],VehicleInfo[h][Positiony],VehicleInfo[h][Positionz],VehicleInfo[h][Angle],VehicleInfo[h][ColorOne],VehicleInfo[h][ColorTwo],0);
            format(string, sizeof(string), "%s", VehicleInfo[h][NumberPlate]);
            SetVehicleNumberPlate(vehicle, string);
			}
	}

public LoadVehicles()
{
	new arrCoords[14][64];
	new strFromFile2[256];
	new File: file = fopen("vehicles.cfg", io_read);
	if (file)
	{
		new idx;
		while (idx < sizeof(VehicleInfo))
		{
			fread(file, strFromFile2);
			split(strFromFile2, arrCoords, ',');
			VehicleInfo[idx][Model] = strval(arrCoords[0]);
			strmid(VehicleInfo[idx][NumberPlate], arrCoords[1], 0, strlen(arrCoords[1]), 255);
			VehicleInfo[idx][Positionx] = floatstr(arrCoords[2]);
			VehicleInfo[idx][Positiony] = floatstr(arrCoords[3]);
			VehicleInfo[idx][Positionz] = floatstr(arrCoords[4]);
			VehicleInfo[idx][Angle] = floatstr(arrCoords[5]);
			VehicleInfo[idx][Interior] = strval(arrCoords[6]);
			VehicleInfo[idx][Virtual] = strval(arrCoords[7]);
			strmid(VehicleInfo[idx][Owner], arrCoords[8], 0, strlen(arrCoords[8]), 255);
			VehicleInfo[idx][Owned] = strval(arrCoords[9]);
			VehicleInfo[idx][Hours] = strval(arrCoords[10]);
			VehicleInfo[idx][Locked] = strval(arrCoords[11]);
			VehicleInfo[idx][ColorOne] = strval(arrCoords[12]);
			VehicleInfo[idx][ColorTwo] = strval(arrCoords[13]);

			idx++;
		}
		fclose(file);
	}
	return 1;
}
Can you guys help me to for example, detect if my vehicle is near to can lock or unlock it? Thanks in advance.
Reply
#2

PHP код:
new Float:XFloat:YFloat:Z;
for(new 
0MAX_VEHICLESi++)
{
    
GetVehiclePos(iXYZ);
    if(
IsPlayerInRangeOfPoint(i4.0XYZ))
    {
        
//do whatever you need
    
}

Reply
#3

Quote:
Originally Posted by luke49
Посмотреть сообщение
PHP код:
new Float:XFloat:YFloat:Z;
for(new 
0MAX_VEHICLESi++)
{
    
GetVehiclePos(iXYZ);
    if(
IsPlayerInRangeOfPoint(i4.0XYZ))
    {
        
//do whatever you need
    
}

Nice spam man.

Btw, use unix time.
Reply
#4

Help me please, how I detect a vehicle from owned cars, in scriptfiles. I would like a command to detect a car and close/open it.

Vehicle[ID][Locked] = 1; // locked
Vehicle[ID][Locked] = 0; // open
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)