respawn a detachted trailer?
#1

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?

Код HTML:
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.
Reply
#2

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.
Reply
#3

TruckTrailer is created just like other vehicles (CreateVehicle).
Reply
#4

Yes, but the vehicle IDs you store in it are from the vehicle trucks or the trailers which are attached to them?
Reply
#5

Quote:
Originally Posted by rOps
Посмотреть сообщение
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
Код HTML:
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.
Reply
#6

still respawns
Reply
#7

what console prints at
PHP код:
for(new trucktrailerindex 0trucktrailerindex sizeof(TruckTrailer); ++trucktrailerindex) { 
printf("TT: %d %d"trucktrailerindexTruckTrailer[trucktrailerindex]);

?


ADD: realised that im forgot about mean of "IsTrailerAttachedToVehicle"
PHP код:
for(new trucktrailerindex 0trucktrailerindex sizeof(TruckTrailer); ++trucktrailerindex) { 
    for(new 
vehicleid 0vehicleid MAX_VEHICLESvehicleid ++) {
        if(
GetVehicleTrailer(vehicleid) == TruckTrailer[trucktrailerindex]) {
            
SetVehicleToRespawn(TruckTrailer[trucktrailerindex]);
            break;
        }
    }

Reply
#8

[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
Reply
#9

If the array stores only the trailer IDs in sequence, then:
pawn Код:
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.
Reply
#10

finally. thanks a lot!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)