DestroyVehicle
#1

How to make when player spawns another vehicle if there is old spawned the old to be destroyed
I have tryed to make it but it wont work:
pawn Код:
new Veh[512],id[MAX_PLAYERS],VehicleID;
            VehicleID = id[playerid];
            DestroyVehicle(Veh[VehicleID]);
            Veh[VehicleID] = CreateVehicle(583, -1547.6190,-442.2964,9.0000, 0.0000, -1, -1, 100);
            PutPlayerInVehicle(playerid, Veh[VehicleID], 0);
Ideas ?
Reply
#2

pawn Код:
// Top of the script
new pTempVeh[MAX_PLAYERS]; // a per-player global var to store a player's temporary vehicle in
// The following code goes where you spawn a vehicle
if(GetPlayerVehicleID(playerid) == pTempVeh[playerid]) // if the player in his/her temporary vehicle
    DestroyVehicle(pTempVeh[playerid]); // destroy it
   
pTempVeh[playerid] = CreateVehicle(583, -1547.6190,-442.2964,9.0000, 0.0000, -1, -1, 100); // assigns the temp vehicle variable to the vehicle we created
PutPlayerInVehicle(playerid, pTempVeh[playerid], 0);
Reply
#3

Thanks
Reply
#4

It wont work when i tested it :9 the vehicle isnt destroying
Reply
#5

Quote:
Originally Posted by TheDeath
Посмотреть сообщение
It wont work when i tested it :9 the vehicle isnt destroying
Hmm can you show how you made it?
Reply
#6

Remove the vehicle id check.
Reply
#7

pawn Код:
new pTempVeh[MAX_VEHICLES];//Top
//I HAVE A LOT OF SPAWNING PLACES
            case DIALOG_COP_SPAWN:
            {
                if(response)
                {
                switch(listitem)
                {
                    case 0:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(597, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }
                    case 1:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(523, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }
                    case 2:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(599, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);

                    }
                    case 3:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(427, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }


                }
                }

            }
            case DIALOG_COP_SPAWN_TWO:
            {
                if(response)
                {
                switch(listitem)
                {
                    case 0:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(597, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }
                    case 1:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(523, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }
                    case 2:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(599, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);

                    }
                    case 3:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(427, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }


                }
                }

            }
            case DIALOG_SPAWN_TUG:
            {
            if(response){
                if(GetPlayerVehicleID(playerid) == Veh[playerid])
                DestroyVehicle(Veh[playerid]);
                Veh[playerid] = CreateVehicle(583, -1547.6190,-442.2964,9.0000, 0.0000, -1, -1, 100);
                PutPlayerInVehicle(playerid, Veh[playerid], 0);
            }
            }
            case DIALOG_SPAWN_PLANE:
            {
                if(response)
                {
                switch(listitem)
                {
                    case 0:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(511, -1274.1472,-618.5521,14.1484, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }
                    case 1:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(513, -1274.1472,-618.5521,14.1484, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);
                    }
                    case 2:
                    {
                        if(GetPlayerVehicleID(playerid) == Veh[playerid])
                        DestroyVehicle(Veh[playerid]);
                        Veh[playerid] = CreateVehicle(593, -1274.1472,-618.5521,14.1484, 0.0000, -1, -1, 100);
                        PutPlayerInVehicle(playerid, Veh[playerid], 0);

                    }


                }
                }

            }
Reply
#8

Quote:
Originally Posted by milanosie
Посмотреть сообщение
Remove the vehicle id check.
Thanks it worked!
Quote:
Originally Posted by milanosie
Посмотреть сообщение
As i said before, remove the if statement on every case.
I saw it before this post
Най-накрая някой българин
Reply
#9

Is that what I told you? Re-read my post carefully please.


Well change
pawn Код:
new pTempVeh[MAX_VEHICLES];
to
pawn Код:
new pTempVeh[MAX_PLAYERS];
and change
pawn Код:
if(GetPlayerVehicleID(playerid) == Veh[playerid])
    DestroyVehicle(Veh[playerid]);
Veh[playerid] = CreateVehicle(597, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
PutPlayerInVehicle(playerid, Veh[playerid], 0);
to

pawn Код:
if(GetPlayerVehicleID(playerid) == pTempVeh[playerid])
    DestroyVehicle(pTempVeh[playerid]);
pTempVeh[playerid] = CreateVehicle(597, -1622.4440,651.8917,10.1875, 0.0000, -1, -1, 100);
PutPlayerInVehicle(playerid, pTempVeh[playerid], 0);
And notice that it will only destroy the old spawned vehicle if the player is in it (while spawning a new one).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)