Destroy car when player leaves it
#1

Guys... I've tried just about everything, but I can't get it working. I have this command:

pawn Code:
command(spawncar, playerid, params[])
{
    new carid, color1, color2, Float: CarToX, Float: CarToY, Float: CarToZ;
    if(PlayerStatistics[playerid][pAdminLevel] < 3)
        return false;
    if(sscanf(params, "ddd", carid, color1, color2))
        return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /spawncar [modelid] [color1] [color2]");
    if(carid < 400 || carid > 611)
        return SendClientMessage(playerid, COLOR_WHITE, "Wrong vehicle model ID! (400 - 600))!");
    if(color1 < 0 || color1 > 300 || color2 < 0 || color2 > 300)
        return SendClientMessage(playerid, COLOR_WHITE, "Wrong color ID! (0 - 300)");

    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    AdminVehicle[playerid] = CreateVehicle(carid, CarToX, CarToY, CarToZ, 90, color1, color2, -1);
    LinkVehicleToInterior(AdminVehicle[playerid], GetPlayerInterior(playerid));
    PutPlayerInVehicle(playerid, AdminVehicle[playerid], 0);
    return 1;
}
* Which, for some reason won't put the player in the vehicle...

When a player leaves the vehicle, which was spawned using this command, I want to destroy it. How could I do that?
Reply
#2

You need to put the player in after a little bit of time, the car has to generate first. Put the placement in a timer.
Reply
#3

pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_DRIVER && AdminVehicle[playerid])
    {
        DestroyVehicle(AdminVehicle[playerid]);
        AdminVehicle[playerid] = 0;
    }
    return 1;
}
Looks ok to me.
Reply
#4

I tested this in a filterscript, and it seems to work fine, although I would get the players angle and include that in the code.
pawn Code:
new veh;

command(spawncar, playerid, params[])
{
    new carid, color1, color2, Float: CarToX, Float: CarToY, Float: CarToZ;
    if(sscanf(params, "ddd", carid, color1, color2))
    {
        return SendClientMessage(playerid, COLOR_GREY, "SYNTAX: /spawncar [modelid] [color1] [color2]");
    }
    if(carid < 400 || carid > 611)
        return SendClientMessage(playerid, COLOR_GREY, "Wrong vehicle model ID! (400 - 600))!");
    if(color1 < 0 || color1 > 300 || color2 < 0 || color2 > 300)
        return SendClientMessage(playerid, COLOR_GREY, "Wrong color ID! (0 - 300)");
    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    veh = CreateVehicle(carid, CarToX, CarToY, CarToZ, 90, color1, color2, -1);
    LinkVehicleToInterior(veh, GetPlayerInterior(playerid));
    PutPlayerInVehicle(playerid, veh, 0);
    return 1;
}
the only thing did was remove the admin check, and change the variable that the carid was stored in.

as for destroying the vehicle after you get out, create a global variable...
pawn Code:
new LastVeh[MAX_PLAYERS];
...
public OnPlayerStateChange(playerid,newstate,oldstate)
{
     if(newstate == PLAYER_STATE_DRIVER)
     {
          LastVeh[playerid] = GetPlayerVehicleID(playerid);
     }
     if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
     {
          if(LastVeh[playerid] == AdminVehicle[playerid] && GetVehicleModel(AdminVehicle[playerid]) > 0)
          {
               DestroyVehicle(AdminVehicle[playerid]);
               AdminVehicle[playerid] = 0;
               LastVeh[playerid] = 0;
          }
     }
     // etc etc
     return 1;
}
may need some fine tuning
Reply
#5

Quote:
Originally Posted by Rachael
View Post
I tested this in a filterscript, and it seems to work fine, although I would get the players angle and include that in the code.
pawn Code:
new veh;

command(spawncar, playerid, params[])
{
    new carid, color1, color2, Float: CarToX, Float: CarToY, Float: CarToZ;
    if(sscanf(params, "ddd", carid, color1, color2))
    {
        return SendClientMessage(playerid, COLOR_GREY, "SYNTAX: /spawncar [modelid] [color1] [color2]");
    }
    if(carid < 400 || carid > 611)
        return SendClientMessage(playerid, COLOR_GREY, "Wrong vehicle model ID! (400 - 600))!");
    if(color1 < 0 || color1 > 300 || color2 < 0 || color2 > 300)
        return SendClientMessage(playerid, COLOR_GREY, "Wrong color ID! (0 - 300)");
    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    veh = CreateVehicle(carid, CarToX, CarToY, CarToZ, 90, color1, color2, -1);
    LinkVehicleToInterior(veh, GetPlayerInterior(playerid));
    PutPlayerInVehicle(playerid, veh, 0);
    return 1;
}
the only thing did was remove the admin check, and change the variable that the carid was stored in.
When you changed the variable, it made it global, not "player specific" so when a player who used that command exits his vehicle, all of the rest of the vehicles made with that command will be destroyed as well...
Reply
#6

I was only testing the functionality of the command to spawn the vehicle, and put the player in it. I was not suggesting that you use this variable in your script.
Also, I edited my post with my suggestion as to destroying the vehicle apon exit.
Reply
#7

I think my GM is what's causing the player not to be put in the vehicle, but I'm not sure why. I don't think there is anything which should be stopping the action when the vehicle is spawned. I'll have to look into it though.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)