SA-MP Forums Archive
CMD;car problem - 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: CMD;car problem (/showthread.php?tid=498010)



CMD;car problem - ReD_HunTeR - 01.03.2014

pawn Код:
CMD:car(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4 || IsPlayerAdmin(playerid))
    {
          new vid, Float:X, Float:Y, Float:Z, Float:Angle, col1, col2;
          if(sscanf(params,"d", vid)) return SendClientMessage(playerid, COLOR_GREY,"Syntax /car [vehicleid] [vcol1] [vcol2]");
          if(vid < 400 || vid > 611) return SendClientMessage(playerid,COLOR_RED,"Invalid Vehicle ID (400 - 611)");
          GetPlayerPos(playerid, X, Y, Z);
          GetPlayerFacingAngle(playerid, Angle);
          CreateVehicle(vid, X, Y, Z, Angle, col1, col2, 60);
    }
    else SendClientMessage(playerid,COLOR_RED,"You do not have the right admin permissions for this command!");
    return 1;
}
how can i make this to when player leave the car it will be respawn automaticly?


Re: CMD;car problem - Threshold - 01.03.2014

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;
}



Re: CMD;car problem - ReD_HunTeR - 01.03.2014

Thanks, For The help.