Destroy car after car exit.
#1

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
Reply
#2

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
Reply
#3

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.
Reply
#4

Check out OnPlayerExitVehicle too
Reply
#5

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
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)