PDA

View Full Version : /respawnallvehicles - Trying to ensure the vehicle is created in the exact same ID


Dokins
01/10/2016, 01:57 PM
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.

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

Jayse
01/10/2016, 02:19 PM
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 (https://wiki.sa-mp.com/wiki/Function:SetVehicleToRespawn) instead.

Dokins
01/10/2016, 02:20 PM
That won't set the angle correctly.

Jayse
01/10/2016, 02:27 PM
SetVehiclePos, SetVehicleZAngle after respawning?

ActionTanki91
01/10/2016, 02:35 PM
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;
}

Dokins
01/10/2016, 02:35 PM
Doesn't set it on unoccupied vehicles.

ActionTanki91
01/10/2016, 02:45 PM
stock VehicleOccupied(vehicleid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInVehicle(i, vehicleid)) return 1;
}
return 0;
}

Dokins
01/10/2016, 02:55 PM
Please read the post before posting useless information.