Spawn specefic player vehicle
#1

Hi, so I was trying to figured out how to spawn the specific vehicle id that the player owns from thiis dialog:

Код HTML:
CMD:spawncar(playerid, params[])
{
	new string[128], count;
	foreach(new i : Vehicles)
	{
	    if(PlayerInfo[playerid][pID] == VehicleInfo[i][vOwnerID])
	    {
	    	format(string, sizeof(string), "%sOwner: %s ID: %d\n", string, VehicleInfo[i][vOwner], i);
	    	count++;
		}
	}
	if(count)
	{
		Dialog_Show(playerid, SpawnCar, DIALOG_STYLE_LIST, "My Cars", string, "Close", "");
	}
	else return SendErrorMessage(playerid, "You don't own any vehicle.");
	return 1;
}
From there it's all good, showing all my 3 vehicles that I own on the list then I got confused how to spawn them in the next dialog:

Код HTML:
Dialog:SpawnCar(playerid, response, listitem, inputtext[])
{
	if(response)
	{
		switch(listitem)
		{
	    	case 0:
		    {
	        
			}
			case 1:
			{
			
			}
		}
	}
	return 1;
}
I tried everything for an hour and couldn't figure it out the reason why I'm here , any ideas ?
Reply
#2

Case 0 should represent the first car, so add in Case 0 the spawn pos for car1
Reply
#3

I need to spawn one of my 3 cars that I own by clicking on the list from my vehicle database
Reply
#4

I'm sort of blank right now, there are better methods than this - The way you could do with what you have now is to use the listitem ID. Your loop on your command starts from 0 to last spawned vehicle and formats it. So, the one to be fetched first becomes the first option in your dialog. You could consider the listitem ID, then loop and count according to the option number you've chosen. If it's the second list item you picked, you'd need the count to reach 2 inside the loop for your owned vehicles to pick one. Let me get straight to code to avoid further confusion.
pawn Код:
Dialog:SpawnCar(playerid, response, listitem, inputtext[]) {

    if(response) {

        new
            temp_Counts = 0;
        foreach(new i : Vehicles) { //Looping through all vehicles.
       
            if(PlayerInfo[playerid][pID] == VehicleInfo[i][vOwnerID]) //If the vehicle belongs to the player,
                temp_Counts++; //Counts increases.

            if((temp_Counts - 1) == listitem) { //if counts-1 is equal to listitem (since in your cmd, first found player's vehicle comes first in the list)

                //Your code to spawn vehicle.
                break; //The loop must exit then!
            }
        }
    }
    return 1;
}
Reply
#5

Код:
CMD:spawncar(playerid, params[])
{
	new string[128], count;
	foreach(new i : Vehicles)
	{
	    if(PlayerInfo[playerid][pID] == VehicleInfo[i][vOwnerID])
	    {
	    	format(string, sizeof(string), "%sOwner: %s ID: %d\n", string, VehicleInfo[i][vOwner], i);
	    	count++;
		}
	}
	if(count)
	{
		Dialog_Show(playerid, MyCars, DIALOG_STYLE_LIST, "My Cars", string, "Close", "");
	}
	else return SendErrorMessage(playerid, "You don't own any vehicle.");
	return 1;
}

Dialog:SpawnCar(playerid, response, listitem, inputtext[])
{
    if(response)
	{
        new temp_Counts = 0;
        foreach(new i : Vehicles)
		{

            if(PlayerInfo[playerid][pID] == VehicleInfo[i][vOwnerID])
                temp_Counts++;

            if((temp_Counts - 1) == listitem)
			{
                VehicleInfo[i][vID] = CreateVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vPosX], VehicleInfo[i][vPosY], VehicleInfo[i][vPosZ], VehicleInfo[i][vPosA], VehicleInfo[i][vColor1], VehicleInfo[i][vColor2], -1, 0);
                break;
            }
        }
    }
    return 1;
}
I might be missing something but I can't really make it work yet and can't really understand how that would work I don't know why I'm confuse since if it wasn't from a dialog, it'd be easy to do lol anything else ?
Reply
#6

I'm not much familiar with easyDialogs.inc but I guess you should mention SpawnCar instead of MyCars on Dialog_Show function. Or else rename SpawnCar to MyCars.
Reply
#7

Oh shit lol, I copy/paste yours so I didn't pay attention to it, thought it was the same

EDIT: Working perfectly +rep
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)