CMD;car problem
#2

pawn Код:
native IsValidVehicle(vehicleid); //Add this DIRECTLY under your #include <a_samp> line.
new PlayerVehicle[MAX_PLAYERS]; //Add this at the top of your script.

public OnPlayerConnect(playerid)
{
    PlayerVehicle[playerid] = INVALID_VEHICLE_ID; //Will make sure the vehicle does not exist when the player connects.
    return 1;
}

CMD:car(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 4 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You do not have the right admin permissions for this command!");
    new vid, col1, col2;
    if(sscanf(params,"dI(0)I(0)", vid)) return SendClientMessage(playerid, COLOR_GREY, "Syntax /car [model] [vcol1] [vcol2]");
    if(vid < 400 || vid > 611) return SendClientMessage(playerid, COLOR_RED, "Invalid Vehicle ID (400 - 611)");
    new Float:X, Float:Y, Float:Z, Float:Angle;
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, Angle);
    if(IsValidVehicle(PlayerVehicle[playerid])) DestroyVehicle(PlayerVehicle[playerid]); //Will destroy the old vehicle created with /car if it exists.
    PlayerVehicle[playerid] = CreateVehicle(vid, X, Y, Z, Angle, col1, col2, 60); //Creates the new car.
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER) //If the player was a driver, but is now on foot...
    {
        if(IsValidVehicle(PlayerVehicle[playerid])) SetVehicleToRespawn(PlayerVehicle[playerid]);
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(IsValidVehicle(PlayerVehicle[playerid]))
    {
        DestroyVehicle(PlayerVehicle[playerid]); //Destroy the vehicle, just in case the player quits without leaving the vehicle.
        PlayerVehicle[playerid] = INVALID_VEHICLE_ID; //Just to make sure that the vehicle doesn't remain in the server.
    }
    return 1;
}
Reply


Messages In This Thread
CMD;car problem - by ReD_HunTeR - 01.03.2014, 15:05
Re: CMD;car problem - by Threshold - 01.03.2014, 15:18
Re: CMD;car problem - by ReD_HunTeR - 01.03.2014, 15:41

Forum Jump:


Users browsing this thread: 1 Guest(s)