/respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID
#1

pawn Код:
CMD:respawnallvehicles(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(AdminLevel[playerid] < 1) return SendClientMessage(playerid, COLOUR_GREY, "You are not authorized to use this command.");
    new string[128], vehid;
    for(new v = 1; v  < GetVehiclePoolSize()+1; v++)
    {
        if(GetVehicleModel(v) != 510 && !IsATrailer(v) && !IsVehicleInUse(v))
            {
            vehid = v;
                        DestroyVehicle(v);
                        CreateVehicle(VehModel[vehid], VehSpawnX[vehid], VehSpawnY[vehid], VehSpawnZ[vehid],             VehSpawnAngle[vehid], VehColour1[vehid], VehColour2[vehid], 0, VehSiren[vehid]);
            SetVehicleNumberPlate(vehid, VehPlate[vehid]);
            new vehicleid = vehid;
            if(VehOwner[vehicleid] > 0 || VehicleFaction[vehicleid] > 0)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 1, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
            if(VehJob[vehicleid] > 0 || VehDealership[vehicleid] > 0 || RentVeh[vehicleid] == 1)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 0, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
        }
    }
    format(string, sizeof(string), ""COL_GREEN"All Vehicles Respawned.");
    SendClientMessage(playerid, COLOUR_WHITE, string);
    SendClientMessageToAll(COLOUR_WHITE, "All vehicles have been respawned.");
    return 1;
}
I think this may be slightly bugged due to ID's being messed up and this command below duplicates vehicles.
pawn Код:
CMD:frespawnall(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    new string[128], id;
    if(FRank[playerid] < 5 && AdminLevel[playerid] < 1)return SendClientMessage(playerid, COLOUR_GREY, "You must be at least rank 5 to use this.");
    for(new v = 1; v < GetVehiclePoolSize()+1; v++)
    {
        if(VehicleFaction[v] == Faction[playerid])
        {
            id = v;
            DestroyVehicle(v);
            CreateVehicle(VehModel[id], VehSpawnX[id], VehSpawnY[id], VehSpawnZ[id], VehSpawnAngle[id], VehColour1[id], VehColour2[id], 0, VehSiren[id]);
            format(string, sizeof(string), "Vehicle: "COL_WHITE"%d Respawned.", id);
            SetVehicleNumberPlate(id, VehPlate[id]);
            new vehicleid = id;
            if(VehOwner[vehicleid] > 0 || VehicleFaction[vehicleid] > 0)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 1, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
            if(VehJob[vehicleid] > 0 || VehDealership[vehicleid] > 0 || RentVeh[vehicleid] == 1)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 0, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
        }
    }
    format(string, sizeof(string), "ALL FACTION VEHICLES RESPAWNED.");
    SendClientMessage(playerid, COLOUR_ORANGE, string);
    return 1;
}
Reply
#2

Why do you destroy the vehicle and create it again? In most cases it won't get the same ID which was assigned to it before. You should use SetVehicleToRespawn instead.
Reply
#3

That won't set the angle correctly.
Reply
#4

SetVehiclePos, SetVehicleZAngle after respawning?
Reply
#5

Use my command, if you use ZCMD.

Код:
CMD:rc(playerid)
{
    new string[256];
    LevelCheck(playerid, 3);
    format(string, sizeof(string), "Administrator %s has respawn all cars !", PlayerName(playerid));
    SendClientMessageToAll(COLOR_BLUE, string);
    PlayerPlaySound(playerid, 1058,0.0,0.0,0.0);
    for(new i = 0; i <= MAX_VEHICLES; i++)
    {
        if(!VehicleOccupied(i)
	{
	    SetVehicleToRespawn(i);
	}
    }
    return 1;
}
Reply
#6

Doesn't set it on unoccupied vehicles.
Reply
#7

Код:
stock VehicleOccupied(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i, vehicleid)) return 1;
    }
    return 0;
}
Reply
#8

Please read the post before posting useless information.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)