SA-MP Forums Archive
Problem displaying vehicle info - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem displaying vehicle info (/showthread.php?tid=523816)



Problem displaying vehicle info - Blademaster680 - 04.07.2014

I have a problem displaying my vehicle's info...

It only works if I run a loop through all the vehicles to get the vehicle info... but it gives me the info for all the vehicles.

I made a function that is suppose to loop through and find the car's ID that matches the ID im in but it doesnt work...

Code:
Working:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	new str[128];
	for(new i=1; i < MAX_DVEHICLES; i++)
	{
		format(str, sizeof(str), "Owner: %s | Price: %d", vInfo[i][vOwner], vInfo[i][vPrice]);
		SendClientMessage(playerid, -1, str);
	}
	return 1;
}
Not working:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	new id = GetVehicleID(GetPlayerVehicleID(playerid));
	new str[128];
	format(str, sizeof(str), "Owner: %s | Price: %d", vInfo[id][vOwner], vInfo[id][vPrice]);
	SendClientMessage(playerid, -1, str);
	return 1;
}
Function:
Код:
GetVehicleID(vehicleid)
{
	for(new i=1; i < MAX_DVEHICLES; i++)
	{
		if(VehicleCreated[i] && VehicleID[i] == vehicleid) return i;
	}
	return 0;
}
Please could someone help me


Re: Problem displaying vehicle info - Threshold - 04.07.2014

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new id = GetVehicleID(vehicleid);
    if(id != INVALID_VEHICLE_ID)
    {
        new str[55];
        format(str, sizeof(str), "Owner: %s | Price: %d", vInfo[id][vOwner], vInfo[id][vPrice]);
        SendClientMessage(playerid, -1, str);
    }
    return 1;
}

GetVehicleID(vehicleid)
{
    for(new i = 1; i < MAX_DVEHICLES; i++)
    {
        if(!VehicleCreated[i]) continue;
        if(VehicleID[i] == vehicleid) return i;
    }
    return INVALID_VEHICLE_ID;
}
OnPlayerEnterVehicle is called when a player begins to enter a vehicle, not when they actually enter one. (OnPlayerStateChange is more effective in that circumstance)

So when you are using 'GetPlayerVehicleID(playerid)' under OnPlayerEnterVehicle, the player is not actually in the vehicle yet, so it returns INVALID_VEHICLE_ID and the GetVehicleID won't really work with an invalid vehicle id.

Source:
https://sampwiki.blast.hk/wiki/OnPlayerEnterVehicle


Re: Problem displaying vehicle info - Blademaster680 - 04.07.2014

Quote:

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new id = GetVehicleID(vehicleid);
if(id != INVALID_VEHICLE_ID)
{
new str[55];
format(str, sizeof(str), "Owner: %s | Price: %d", vInfo[id][vOwner], vInfo[id][vPrice]);
SendClientMessage(playerid, -1, str);
}
return 1;
}

GetVehicleID(vehicleid)
{
for(new i = 1; i < MAX_DVEHICLES; i++)
{
if(!VehicleCreated[i]) continue;
if(VehicleID[i] == vehicleid) return i;
}
return INVALID_VEHICLE_ID;
}

It still doesn't want to work


Re: Problem displaying vehicle info - Threshold - 04.07.2014

Then the problem is in 'VehicleID[i]' and cannot be fixed by myself or anyone else.