Car system, how do I make it despawn the previous car when typing /v?
#2

At the top of the script:

pawn Код:
new PlayerHasVehicle[MAX_PLAYERS]; // Global variable for all the players.
When the player connects:

pawn Код:
public OnPlayerConnect(playerid)
{
    PlayerHasVehicle[playerid] = -1; // The default vehicle ID (user defined) if he hasn't got a vehicle.
    return 1;
}
The new /v command:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[200], idx;
    cmd = strtok(cmdtext, idx);
    if(strcmp(cmd, "/v", true, 10) == 0)
    {
        new String[200];
        new tmp[256];
        new Float:x, Float:y, Float:z;

        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, l_red, "You didn't give a vehicle name");

        new vehicle = GetVehicleModelIDFromName(tmp);

        if(vehicle < 400 || vehicle > 611) return SendClientMessage(playerid, l_red, "That vehicle name was not found");
        if(PlayerHasVehicle[playerid] != -1)
        {
            DestroyVehicle(PlayerHasVehicle[playerid]); // This will destroy the original vehicle if the player's vehicle was not -1, which I set to as the default above.
        }

        new Float:a;
        GetPlayerFacingAngle(playerid, a);
        GetPlayerPos(playerid, x, y, z);

        if(IsPlayerInAnyVehicle(playerid) == 1)
        {
            GetXYInFrontOfPlayer(playerid, x, y, 8);
        }
        else
        {
            GetXYInFrontOfPlayer(playerid, x, y, 5);
        }
        PlayerHasVehicle[playerid] = CreateVehicle(vehicle, x, y, z, a+90, -1, -1, -1); // This will set the playerid's vehicle to that vehicle that was just created.
        LinkVehicleToInterior(PlayersVehicle, GetPlayerInterior(playerid));.

        format(String, sizeof(String), "You have spawned a %s", aVehicleNames[vehicle - 400]);
        SendClientMessage(playerid, l_green, String);
        return 1;
    }
    return 0;
}
Reply


Messages In This Thread
Car system, how do I make it despawn the previous car when typing /v? - by ExtendedCarbon - 07.09.2013, 22:06
Re: Car system, how do I make it despawn the previous car when typing /v? - by DanishHaq - 07.09.2013, 22:22

Forum Jump:


Users browsing this thread: 5 Guest(s)