Problem displaying vehicle info
#1

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
Reply
#2

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
Reply
#3

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
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)