06.08.2012, 19:17
Well, this started happening only recently, and I haven't changed the vehicle system at all nor I run any filterscripts. I save cop cars in a variable PDCar[MAX_PDCARS]; and I never destroy them or anything.
The problem is, personal cars/private cars of players sometimes get spawned as police cars, locked to be used only by police.
Now, this happened to me before back on 0.3d and I always wondered, does the car keep it's same ID when it gets destroyed (in-game destroyed, when it explodes and gets respawned) or does the ID change? This is my part of OnGamemodeInit where the police cars are spawned:
And this is my OnVehicleSpawn
And this is OnVehicleDeath
Now I don't reset the variable anywhere, nor I use DestroyVehicle(vehicleid) anywhere where it involves police cars. I checked my code and I really hope that I haven't overlooked anything, but I can't seem to find what's the problem. Also note, this happens when there's at least 15-20 people online on the server, after some hours when they spawn/despawn their personal cars and such.
Is it possible that somewhere during the re-spawn delay, another car gets spawned and takes the police car's vehicle ID?
pawn Код:
#define MAX_PDCARS 17
Now, this happened to me before back on 0.3d and I always wondered, does the car keep it's same ID when it gets destroyed (in-game destroyed, when it explodes and gets respawned) or does the ID change? This is my part of OnGamemodeInit where the police cars are spawned:
pawn Код:
// POLICE CARS
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[0] = AddStaticVehicleEx(497,616.7850,-574.9861,26.3200,271.8847,0,0,1200);
PDCar[1] = AddStaticVehicleEx(598,613.6539,-597.1769,17.0115,269.3126,0,1,1200);
SetVehicleNumberPlate(PDCar[1], platenumb);
SetVehicleToRespawn(PDCar[1]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[2] = AddStaticVehicleEx(598,613.4633,-601.6515,17.0082,271.3620,0,1,1200);
SetVehicleNumberPlate(PDCar[2], platenumb);
SetVehicleToRespawn(PDCar[2]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[3] = AddStaticVehicleEx(596,637.7685,-567.1270,16.0215,180.0906,0,1,1200);
SetVehicleNumberPlate(PDCar[3], platenumb);
SetVehicleToRespawn(PDCar[3]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[4] = AddStaticVehicleEx(596,637.8582,-575.9764,16.0167,180.4532,0,1,1200);
SetVehicleNumberPlate(PDCar[4], platenumb);
SetVehicleToRespawn(PDCar[4]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[5] = AddStaticVehicleEx(597,-1573.1486,738.3839,-5.3622,270.3502,0,1,1200);
SetVehicleNumberPlate(PDCar[5], platenumb);
SetVehicleToRespawn(PDCar[5]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[6] = AddStaticVehicleEx(599,-1572.7405,705.9237,-5.2276,89.6085,0,1,1200);
SetVehicleNumberPlate(PDCar[6], platenumb);
SetVehicleToRespawn(PDCar[6]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[7] = AddStaticVehicleEx(490,-1596.0745,675.9731,-5.1270,180.5009,0,0,1200);
SetVehicleNumberPlate(PDCar[7], platenumb);
SetVehicleToRespawn(PDCar[7]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[8] = AddStaticVehicleEx(490,-1599.9989,675.6845,-5.1266,180.1086,0,0,1200);
SetVehicleNumberPlate(PDCar[8], platenumb);
SetVehicleToRespawn(PDCar[8]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[9] = AddStaticVehicleEx(427,-1612.3112,733.4436,-5.1101,0.5981,0,1,1200);
SetVehicleNumberPlate(PDCar[9], platenumb);
SetVehicleToRespawn(PDCar[9]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[10] = AddStaticVehicleEx(523,-1603.0085,731.8671,-5.6696,183.9169,0,0,1200);
SetVehicleNumberPlate(PDCar[10], platenumb);
SetVehicleToRespawn(PDCar[10]);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[11] = AddStaticVehicleEx(402,-1583.9558,749.0897,-5.3823,179.4820,0,0,1200);
SetVehicleNumberPlate(PDCar[11], platenumb);
SetVehicleToRespawn(PDCar[11]);
AttachObjectToVehicle(EmergencyLightsObject[0], PDCar[11], 0.009999, -1.844998, 0.234999, 0.000000, 0.000000, 0.000000); //Object Model: 19419 |
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[12] = AddStaticVehicleEx(426,-1573.0706,734.8633,-5.4459,269.8038,0,0,1200);
SetVehicleNumberPlate(PDCar[12], platenumb);
SetVehicleToRespawn(PDCar[12]);
AttachObjectToVehicle(EmergencyLightsObject[2], PDCar[12], 0.000000, -1.219999, 0.624999, 0.000000, 0.000000, 0.000000);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[13] = AddStaticVehicleEx(426,-1573.6077,730.8414,-5.4443,268.3748,0,0,1200);
SetVehicleNumberPlate(PDCar[13], platenumb);
SetVehicleToRespawn(PDCar[13]);
AttachObjectToVehicle(EmergencyLightsObject[3], PDCar[13], 0.000000, -1.219999, 0.624999, 0.000000, 0.000000, 0.000000);
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[14] = AddStaticVehicleEx(554,-1600.5024,693.3920,-5.1591,359.0697,1,1,1200);
SetVehicleNumberPlate(PDCar[14], platenumb);
SetVehicleToRespawn(PDCar[14]);
AttachObjectToVehicle(EmergencyLightsObject[1], PDCar[14], 0.000000, 0.000000, 1.054999, 0.000000, 0.000000, 0.000000); //Object Model: 19419 |
format(platenumb, 12, "%d%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9), random(9));
PDCar[15] = AddStaticVehicleEx(525,589.2283,-588.6844,18.0744,270.5537,17,20,1200);
SetVehicleNumberPlate(PDCar[15], platenumb);
SetVehicleToRespawn(PDCar[15]);
PDCar[16] = AddStaticVehicleEx(430,2128.1443,-131.7103,-0.2871,149.8316,46,26,1200);
pawn Код:
public OnVehicleSpawn(vehicleid)
{
VehicleLocked[vehicleid] = 0;
SetVehicleParamsForAll(vehicleid,0,0);
EngineStatus[vehicleid] = 0;
Fuel[vehicleid] = 100;
LoadedSupplies[vehicleid] = 0;
new engine, light, alarm, doors, bonnet, boot, objective;
if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510)
{
EngineStatus[vehicleid] = 1;
GetVehicleParamsEx(vehicleid, engine, light, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
}
else
{
GetVehicleParamsEx(vehicleid, engine, light, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_OFF, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
}
for(new emi=0;emi<MAX_EMSCARS;emi++)
{
if(vehicleid == EMSCar[emi])
{
VehicleLocked[vehicleid] = 1;
SetVehicleParamsForAll(vehicleid,0,1);
}
}
for(new ci=0;ci<MAX_PDCARS;ci++)
{
if(vehicleid == PDCar[ci])
{
VehicleLocked[vehicleid] = 1;
SetVehicleParamsForAll(vehicleid,0,1);
TrunkSlots[vehicleid][Slot1] = 25;
TrunkSlots[vehicleid][Slot1a] = 50;
TrunkSlots[vehicleid][Slot2] = 31;
TrunkSlots[vehicleid][Slot2a] = 150;
TrunkSlots[vehicleid][Slot3] = 100;
TrunkSlots[vehicleid][Slot4] = 0;
}
}
return 1;
}
pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
if(AdminVehicle[vehicleid] == 1) DestroyVehicle(vehicleid);
AdminVehicle[vehicleid] = 0;
TrunkSlots[vehicleid][Slot1] = 0;
TrunkSlots[vehicleid][Slot1a] = 0;
TrunkSlots[vehicleid][Slot2] = 0;
TrunkSlots[vehicleid][Slot2a] = 0;
TrunkSlots[vehicleid][Slot3] = 0;
TrunkSlots[vehicleid][Slot4] = 0;
for(new playa=0;playa<MAX_PLAYERS;playa++)
{
if(vehicletracked[playa] == vehicleid)
{
KillTimer(TrackerTimer[playa]);
vehicletracked[playa] = -1;
}
}
for(new ppl=0;ppl<MAX_PLAYERS;ppl++)
{
if(vehicleid == RCToy[ppl])
{
PlayerInfo[ppl][pRCToy] = 0;
DestroyVehicle(RCToy[ppl]);
RCToy[ppl] = -1;
IsPlayerInBaron[ppl] = 0;
return SendClientMessage(ppl, COLOR_ORANGE, "[SERVER:] Your RC toy is destroyed. You need to buy a new one from the store.");
}
}
for(new i=0; i<MAX_ONLINE_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(gPlayerLogged[i])
{
if(PlayerInfo[i][pVeh1CarID] == vehicleid)
{
new string[128];
new rprice = GetVehiclePrice(i, PlayerInfo[i][pVeh1Model])/10;
format(string, sizeof(string), "[SERVER:] Your %s was destroyed. Type /(v)ehicle repair to repair it. Repair price: $%d.",VehicleNames[PlayerInfo[i][pVeh1Model]-400],rprice);
SendClientMessage(i, COLOR_ORANGE, string);
PlayerInfo[i][pVeh1Destroyed] = 4;
PlayerInfo[i][pVeh1CarID] = -1;
DestroyVehicle(vehicleid);
return 1;
}
else if(PlayerInfo[i][pVeh2CarID] == vehicleid)
{
new string[128];
new rprice = GetVehiclePrice(i, PlayerInfo[i][pVeh2Model])/10;
format(string, sizeof(string), "[SERVER:] Your %s was destroyed. Type /(v)ehicle repair to repair it. Repair price: $%d.",VehicleNames[PlayerInfo[i][pVeh2Model]-400],rprice);
SendClientMessage(i, COLOR_ORANGE, string);
PlayerInfo[i][pVeh2Destroyed] = 4;
PlayerInfo[i][pVeh2CarID] = -1;
DestroyVehicle(vehicleid);
return 1;
}
else if(PlayerInfo[i][pVeh3CarID] == vehicleid)
{
new string[128];
new rprice = GetVehiclePrice(i, PlayerInfo[i][pVeh3Model])/10;
format(string, sizeof(string), "[SERVER:] Your %s was destroyed. Type /(v)ehicle repair to repair it. Repair price: $%d.",VehicleNames[PlayerInfo[i][pVeh3Model]-400],rprice);
SendClientMessage(i, COLOR_ORANGE, string);
PlayerInfo[i][pVeh3Destroyed] = 4;
PlayerInfo[i][pVeh3CarID] = -1;
DestroyVehicle(vehicleid);
return 1;
}
}
}
}
return 1;
}
Is it possible that somewhere during the re-spawn delay, another car gets spawned and takes the police car's vehicle ID?