PDA

View Full Version : respawn a detachted trailer?


rOps
19/12/2016, 07:37 PM
hi all. I tried many ways to respawn a detached trailer, but all my struggle was senseless.
so I decided to ask you, maybe you know how to respawn all detached trailers?

for(new vehicleid = 0; vehicleid < MAX_VEHICLES; vehicleid ++)
{
if(TruckTrailer[0] <= vehicleid <= TruckTrailer[sizeof(TruckTrailer) - 1])
{
if(!IsTrailerAttachedToVehicle(Truck[0] <= vehicleid <= Truck[sizeof(Truck) - 1]))
{
SetVehicleToRespawn(vehicleid);
}
}
}

this is my code, but this code still respawns attached trailer.

Konstantinos
19/12/2016, 08:06 PM
Without letting the loop finish, you can't possibly know whether a trailer is attached or not if the array strores the trailerid. Be sure the vehicle IDs are in sequential order, otherwise it will fail.

TruckTrailer array stores the vehicle ID of the truck or the trailer? Your code is a bit confusing.

rOps
19/12/2016, 08:09 PM
TruckTrailer is created just like other vehicles (CreateVehicle).

Konstantinos
19/12/2016, 08:10 PM
Yes, but the vehicle IDs you store in it are from the vehicle trucks or the trailers which are attached to them?

Mutha_X
19/12/2016, 08:13 PM
hi all. I tried many ways to respawn a detached trailer, but all my struggle was senseless.
so I decided to ask you, maybe you know how to respawn all detached trailers?
...
this is my code, but this code still respawns attached trailer.
look this maybe help you

for(new trucktrailerindex = 0; trucktrailerindex < sizeof(TruckTrailer); ++trucktrailerindex) {
if(!IsTrailerAttachedToVehicle(TruckTrailer[trucktrailerindex])) {
SetVehicleToRespawn(TruckTrailer[trucktrailerindex]);
}
}


p.s. you also need to check if truck trailer is exist and vehicle is trailer
+ in that case you didnt have to make sequential IDs in TruckTrailer.

rOps
19/12/2016, 08:20 PM
still respawns

Mutha_X
19/12/2016, 08:26 PM
what console prints at

for(new trucktrailerindex = 0; trucktrailerindex < sizeof(TruckTrailer); ++trucktrailerindex) {
printf("TT: %d %d", trucktrailerindex, TruckTrailer[trucktrailerindex]);
}

?


ADD: realised that im forgot about mean of "IsTrailerAttachedToVehicle"

for(new trucktrailerindex = 0; trucktrailerindex < sizeof(TruckTrailer); ++trucktrailerindex) {
for(new vehicleid = 0; vehicleid < MAX_VEHICLES; vehicleid ++) {
if(GetVehicleTrailer(vehicleid) == TruckTrailer[trucktrailerindex]) {
SetVehicleToRespawn(TruckTrailer[trucktrailerindex]);
break;
}
}
}

rOps
19/12/2016, 08:31 PM
[23:25:37] TT: 0 166
[23:25:37] TT: 1 167
[23:25:37] TT: 2 168
[23:25:37] TT: 3 169
[23:25:37] TT: 4 170
[23:25:37] TT: 5 171
[23:25:37] TT: 6 172
[23:25:37] TT: 7 173
[23:25:37] TT: 8 174
[23:25:37] TT: 9 175
[23:25:37] TT: 10 176
[23:25:37] TT: 11 177

Konstantinos
19/12/2016, 08:42 PM
If the array stores only the trailer IDs in sequence, then:

const TruckTrailer_size = sizeof TruckTrailer;
new bool: attached_trailers[TruckTrailer_size char], trailer_id, last_vehicleid = TruckTrailer[TruckTrailer_size - 1];

for (new vehicleid = 1, j = GetVehiclePoolSize(); vehicleid <= j; vehicleid++)
{
if (!(trailer_id = GetVehicleTrailer(vehicleid))) continue;
if (!(TruckTrailer[0] <= trailer_id <= last_vehicleid)) continue;

attached_trailers{TruckTrailer_size - (last_vehicleid - trailer_id) - 1} = true;
}

for (new i; i != TruckTrailer_size; i++)
{
if (!attached_trailers{i}) SetVehicleToRespawn(TruckTrailer[i]);
}

and you'll avoid the 2 loops that go through 24000 iterations in total.

rOps
19/12/2016, 08:51 PM
finally. thanks a lot!!