How to make if statement remove old car
#1

I have a dialog command to display a list of driftcar.

/driftcar command

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/driftcar", cmdtext, true, 10) == 0)
	{
        ShowPlayerDialog(playerid, DIALOG_DRIFTCAR, DIALOG_STYLE_LIST, "Drift Car", "Elegy\nSultan\nBuffalo", "Select", "Exit");
		return 1;
	}
	return 0;
}
ondialogresponse

Код:
    public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_DRIFTCAR)
    {
        if(response) 
        {
            switch(listitem)
            {
                case 0:
				{
				    new Float:x, Float:y, Float:z;
     				GetPlayerPos(playerid, x, y, z);
     				new elegy = AddStaticVehicleEx (562, x, y, z, 0.0, -1, -1, 30);
     				PutPlayerInVehicle(playerid, elegy, 0);
     				
				}
                case 1: 
				{
				    new Float:x, Float:y, Float:z;
     				GetPlayerPos(playerid, x, y, z);
     				new sultan = AddStaticVehicleEx (560, x, y, z, 0.0, -1, -1, 30);
     				PutPlayerInVehicle(playerid, sultan, 0);

				}
                case 2: 
				{
				    new Float:x, Float:y, Float:z;
     				GetPlayerPos(playerid, x, y, z);
     				new buffalo = AddStaticVehicleEx (402, x, y, z, 0.0, -1, -1, 30);
     				PutPlayerInVehicle(playerid, buffalo, 0);

				}
            }
        }
        return 1; 
    }
    return 0; 
}
And if I type the command /driftcar again old vehicle will be destroyed, how to make like this?
Reply
#2

Add on top of your game mode
Код:
new VehiclePlayerID[MAX_PLAYERS] = 999;
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_DRIFTCAR)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
				{
    				    new Float:x, Float:y, Float:z;
     				    GetPlayerPos(playerid, x, y, z);
     				    if(VehiclePlayerID[playerid] != 999) DestroyVehicle(VehiclePlayerID[playerid]);
     				    VehiclePlayerID[playerid] = AddStaticVehicleEx(562, x, y, z, 0.0, -1, -1, 30);
     				    PutPlayerInVehicle(playerid, VehiclePlayerID[playerid], 0);
				}
                case 1:
				{
     				    new Float:x, Float:y, Float:z;
     				    GetPlayerPos(playerid, x, y, z);
     				    if(VehiclePlayerID[playerid] != 999) DestroyVehicle(VehiclePlayerID[playerid]);
     				    VehiclePlayerID[playerid] = AddStaticVehicleEx(560, x, y, z, 0.0, -1, -1, 30);
     				    PutPlayerInVehicle(playerid, VehiclePlayerID[playerid], 0);
				}
                case 2:
				{
    				    new Float:x, Float:y, Float:z;
     				    GetPlayerPos(playerid, x, y, z);
     				    if(VehiclePlayerID[playerid] != 999) DestroyVehicle(VehiclePlayerID[playerid]);
     				    VehiclePlayerID[playerid] = AddStaticVehicleEx(402, x, y, z, 0.0, -1, -1, 30);
     				    PutPlayerInVehicle(playerid, VehiclePlayerID[playerid], 0);
				}
            }
        }
        return 1;
    }
    return 0;
}
This will cause the vehicle to be destroyed when the player exits the server.
Код:
public OnPlayerDisconnect(playerid, reason)
{
	if(VehiclePlayerID[playerid] != 999) DestroyVehicle(VehiclePlayerID[playerid]);
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)