SA-MP Forums Archive
Destroy car after car exit. - 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: Destroy car after car exit. (/showthread.php?tid=346714)



Destroy car after car exit. - cod5devious - 29.05.2012

I made an admin car.
how do I destroy it after exit?

pawn Код:
CMD:acar(playerid, params[])
{
if(AdminLevel[playerid] < 2)
return SendClientMessage( playerid, COLOR_RED, "You do not have permission to use that command!" );

if(AdminLevel[playerid] >= 2)
return SendClientMessage( playerid, COLOR_RED, "[SERVER] You have spawned an admin car" );
new Float:x, Float:y, Float:z, Float:angle;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, angle);
new veh = CreateVehicle(415, x, y, z, angle, 0, 0, 60);
PutPlayerInVehicle(playerid, veh, 0);
ChangeVehicleColor(429, 1, 1);
return 1;
}
Thanks


Re: Destroy car after car exit. - FalconX - 29.05.2012

Quote:
Originally Posted by cod5devious
Посмотреть сообщение
I made an admin car.
how do I destroy it after exit?

pawn Код:
CMD:acar(playerid, params[])
{
if(AdminLevel[playerid] < 2)
return SendClientMessage( playerid, COLOR_RED, "You do not have permission to use that command!" );

if(AdminLevel[playerid] >= 2)
return SendClientMessage( playerid, COLOR_RED, "[SERVER] You have spawned an admin car" );
new Float:x, Float:y, Float:z, Float:angle;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, angle);
new veh = CreateVehicle(415, x, y, z, angle, 0, 0, 60);
PutPlayerInVehicle(playerid, veh, 0);
ChangeVehicleColor(429, 1, 1);
return 1;
}
Thanks
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if( vehicleid == veh )
    {
        DestroyVehicle( veh );
    }
    return 1;
}
Try this

-FalconX


Re: Destroy car after car exit. - MP2 - 29.05.2012

pawn Код:
new gAdminVeh[MAX_VEHICLES];

CMD:acar(playerid, params[])
{
    // Blah blah blah
    new vid = CreateVehicle(...);
    gAdminVeh[vid] = 1;
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2) SetPVarInt(playerid, "lastveh", GetPlayerVehicleID(playerid));

    new lastveh = GetPVarInt(playerid, "lastveh");
    if(oldstate == 2 && gAdminVeh[lastveh] == 1)
    {
        DestroyVehicle(lastveh);
        gAdminVeh[lastveh] = 0;
    }
}
Not tested.


Re: Destroy car after car exit. - kaisersouse - 29.05.2012

Check out OnPlayerExitVehicle too


Re: Destroy car after car exit. - MP2 - 29.05.2012

I wouldn't personally use OnPlayerExitVehicle for two reasons.

A. it's called as soon as you start to exit, so it will just delete the vehicle and look weird.
B. It's not called if you bail out*

*AFAIK


Re: Destroy car after car exit. - Jonny5 - 29.05.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
I wouldn't personally use OnPlayerExitVehicle for two reasons.

B. It's not called if you bail out*

*AFAIK
i just tested it 5 times by bailing out and it seams to work,
I do remember reading that it did not get called, might be something fixed in 0.3e or
it just is not constantly calling every time someone bails.

but point A: was a valid reason not to use it for this.
I however use it for something else and was worried i was not updating
so I tested it and thought id post my results here,


regards,
J5