SA-MP Forums Archive
Vehicle list won't show - 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: Vehicle list won't show (/showthread.php?tid=634195)



Vehicle list won't show - McGuiness - 14.05.2017

Hey all,

So I was working on a /vehicles command which shows you all the vehicles you own, but when I had bought the vehicle and used the command it said that my character doesn't own any vehicles, yet I'm sure I did everything right, someone mind showing me what I did wrong and why I did it wrong?

Code:
pawn Код:
CMD:vehicles(playerid, params[])
{
    new bool:found = false, list[512];
    list = "ID\tVehicle\tNumber Plate\n";
   
    for (new i = 0; i < MAX_VEHICLES; i++)
    {
        if(PlayerVehicle[v][pvStatus] == 1)
        {
            if (!strcmp(PlayerVehicle[i][pvOwner], owner, true)) {
                found = true;
                format(list, sizeof(list), "%s%d\t%s\t%s\n", list, v, GetVehicleName(v), PlayerVehicle[v][pvPlate]);
            }
        }
    }
    if(found == true) return ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_TABLIST_HEADERS, "Vehicles", list, "Select", "Close");
    else return ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "Vehicles", "{FF0000}No vehicles found!", "Close", "");
}



Re: Vehicle list won't show - Hansrutger - 14.05.2017

Where does "owner" come from in
Код:
if (!strcmp(PlayerVehicle[i][pvOwner], owner, true))
After looking closer at this, you must have either been very tired or copied this from another part of the same or different script.
Код:
if(PlayerVehicle[v][pvStatus] == 1)
should hopefully be "i" instead of "v"? Or is there code I am simply not seeing? : x


Re: Vehicle list won't show - McGuiness - 14.05.2017

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Where does "owner" come from in
Код:
if (!strcmp(PlayerVehicle[i][pvOwner], owner, true))
After looking closer at this, you must have either been very tired or copied this from another part of the same or different script.
Код:
if(PlayerVehicle[v][pvStatus] == 1)
should hopefully be "i" instead of "v"? Or is there code I am simply not seeing? : x
The "owner" was meant to be a "GetPlayerName(playerid)", I had changed it a little before going straight back to all the other stuff. And the "v" was meant to be a "i", and I'm not sure how I did it, it just came to mind, that or I was half alseep when creating it, how should it really be? Cause I think I tried if(PlayerVehicle[i][pvStatus]) continue;


Re: Vehicle list won't show - Hansrutger - 14.05.2017

Well firstly, what is pvStatus?


Re: Vehicle list won't show - McGuiness - 14.05.2017

pvStatus is just a thing that will check if the vehicle is in use, so like pvCarID will contain the CreateVehicle on creation and keep the car ID in it, then the pvStatus is to be so when it checks, it checks that vehicle ID is in use, so basically checking if it's being used in the server.


Re: Vehicle list won't show - Hansrutger - 14.05.2017

Код:
CMD:vehicles(playerid, params[])
{
	new bool:found = false, list[512];
	list = "ID\tVehicle\tNumber Plate\n";
	
	new owner[MAX_PLAYER_NAME];
	GetPlayerName(playerid, owner, MAX_PLAYER_NAME);
	
	for (new i = 0; i < MAX_VEHICLES; i++)
	{
	    if(PlayerVehicle[i][pvStatus] && !strcmp(PlayerVehicle[i][pvOwner], owner, true))
	    {
			found = true;
    		format(list, sizeof(list), "%s%d\t%s\t%s\n", list, i, GetVehicleName(i), PlayerVehicle[i][pvPlate]);
		}
	}
	if(found == true) return ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_TABLIST_HEADERS, "Vehicles", list, "Select", "Close");
	else return ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "Vehicles", "{FF0000}No vehicles found!", "Close", "");
}
Try this.


Re: Vehicle list won't show - McGuiness - 14.05.2017

Just tried it, but now, if I do have vehicles, it won't show the dialog, just shows no dialog nor any text or anything


Re: Vehicle list won't show - Hansrutger - 14.05.2017

I have an idea of what it might be, but run this and SS/copy the console result:
Код:
CMD:vehicles(playerid, params[])
{
	new bool:found = false, list[512];
	list = "ID\tVehicle\tNumber Plate\n";
	
	new owner[MAX_PLAYER_NAME];
	GetPlayerName(playerid, owner, MAX_PLAYER_NAME);
	printf("Starting debugging...");
	for (new i = 0; i < MAX_VEHICLES; i++)
	{
	    if(PlayerVehicle[i][pvStatus] && !strcmp(PlayerVehicle[i][pvOwner], owner))
	    {
	    	printf("Listing vehicleid %i", i);
			found = true;
    		format(list, sizeof(list), "%s%d\t%s\t%s\n", list, i, GetVehicleName(i), PlayerVehicle[i][pvPlate]);
		}
	}

	if(found == true) 
	{
		printf("About to post: %s", list);
		return ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_TABLIST_HEADERS, "Vehicles", list, "Select", "Close");
	}
	else 
	{
		printf("No vehicles were found.");
		return ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "Vehicles", "{FF0000}No vehicles found!", "Close", "");
	}
}



Re: Vehicle list won't show - McGuiness - 14.05.2017

All it shows is the starting the debugging, nothing else:

http://i.imgur.com/u7yFugw.png


Re: Vehicle list won't show - Hansrutger - 14.05.2017

Good so now we know that "PlayerVehicle[i][pvStatus]" is actually 0 / false. When you buy a vehicle, check so that it will be set to 1. Also make sure that "PlayerVehicle[i][pvOwner]" is actually assigned the correct value.