Car Destory Help X2 (Different)
#1

If a person spawns a car then gets out and spawns another one , one car stays and it causes lag... Is there a way when the player enters another vehicle his old one gets destroyed...?
Thanks
Reply
#2

............
Reply
#3

pawn Код:
new lastcar[MAX_PLAYERS];

native IsValidVehicle(vehicleid);

public OnPlayerConnect(playerid)
{
lastcar[playerid] = -1;
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
{
if (IsValidVehicle(lastcar[playerid])) DestroyVehicle(lastcar[playerid]);
lastcar[playerid] = GetPlayerVehicleID(playerid);
}
else if (newstate == PLAYER_STATE_ONFOOT) lastcar[playerid] = -1;
return 1;
}
I also added some extra checks that aren't needed but make it a bit safer.
Reply
#4

Next time PAWN /PAWN please
Thanks!
Reply
#5

It doesn't work.
Reply
#6

pawn Код:
if(pVehicles[playerid] != -1)
    {
        for(new i; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(IsPlayerInVehicle(i,  pVehicles[playerid])) DestroyVehicle(pVehicles[playerid]);
            }
        }
    }
    DestroyVehicle(pVehicles[playerid]);
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, ang);
    pVehicles[playerid] = CreateVehicle(vid, x, y, z, ang, -1, -1, 0);
    vVW = GetPlayerVirtualWorld(playerid);
    vINT = GetPlayerInterior(playerid);
    SetVehicleVirtualWorld(pVehicles[playerid], vVW);
   LinkVehicleToInterior(pVehicles[playerid], vINT);
    PutPlayerInVehicle(playerid, pVehicles[playerid], 0);
Use those.
Reply
#7

Quote:
Originally Posted by JimmyCh
Посмотреть сообщение
pawn Код:
if(pVehicles[playerid] != -1)
    {
        for(new i; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(IsPlayerInVehicle(i,  pVehicles[playerid])) DestroyVehicle(pVehicles[playerid]);
            }
        }
    }
    DestroyVehicle(pVehicles[playerid]);
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, ang);
    pVehicles[playerid] = CreateVehicle(vid, x, y, z, ang, -1, -1, 0);
    vVW = GetPlayerVirtualWorld(playerid);
    vINT = GetPlayerInterior(playerid);
    SetVehicleVirtualWorld(pVehicles[playerid], vVW);
   LinkVehicleToInterior(pVehicles[playerid], vINT);
    PutPlayerInVehicle(playerid, pVehicles[playerid], 0);
Use those.
I can see a mistake here:

pawn Код:
for(new i; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(IsPlayerInVehicle(i,  pVehicles[playerid])) DestroyVehicle(pVehicles[playerid]);
            }
        }
    }
I believe you wanted to destroy the car if nobody is using it, but it does the opposite.

pawn Код:
new found;
for(new i; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(IsPlayerInVehicle(i,  pVehicles[playerid]))
                        {
                             found = 1;
                             break;
                         }
            }
        }
    }
if (!found) DestroyVehicle(pVehicles[playerid]);
Edit: Really bad tabbing :S
Reply
#8

Still none work.
Basically what I want is...
If a player spawns a vehicle then spawns another one.. One vehicle stays I want that vehicle destroyed
How can I do this?
Reply
#9

Quote:
Originally Posted by kvann
Посмотреть сообщение
pawn Код:
new lastcar[MAX_PLAYERS];

native IsValidVehicle(vehicleid);

public OnPlayerConnect(playerid)
{
lastcar[playerid] = -1;
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
{
if (IsValidVehicle(lastcar[playerid])) DestroyVehicle(lastcar[playerid]);
lastcar[playerid] = GetPlayerVehicleID(playerid);
}
else if (newstate == PLAYER_STATE_ONFOOT) lastcar[playerid] = -1;
return 1;
}
I also added some extra checks that aren't needed but make it a bit safer.
That should work, but an advise. Check if the vehicleid the player is in is not the one lastcar[playerid] "holds", because it will delete the player's current vehicle.

EDIT: So when he spawns a second, to destroy the first one. Then go to your command and destroy the vehicle. Store the vehicleid when you create the vehicle.
Reply
#10

Quote:
Originally Posted by _Zeus
Посмотреть сообщение
That should work, but an advise. Check if the vehicleid the player is in is not the one lastcar[playerid] "holds", because it will delete the player's current vehicle.
That does not work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)