SA-MP Forums Archive
/respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - 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: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID (/showthread.php?tid=618123)



/respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - Dokins - 01.10.2016

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



Re: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - Jayse - 01.10.2016

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.


Re: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - Dokins - 01.10.2016

That won't set the angle correctly.


Re: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - Jayse - 01.10.2016

SetVehiclePos, SetVehicleZAngle after respawning?


Re: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - ActionTanki91 - 01.10.2016

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



Re: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - Dokins - 01.10.2016

Doesn't set it on unoccupied vehicles.


Re: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - ActionTanki91 - 01.10.2016

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



Re: /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID - Dokins - 01.10.2016

Please read the post before posting useless information.