SA-MP Forums Archive
respawn a detachted trailer? - 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: respawn a detachted trailer? (/showthread.php?tid=624615)



respawn a detachted trailer? - rOps - 19.12.2016

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.


Re: respawn a detachted trailer? - Konstantinos - 19.12.2016

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.


Re: respawn a detachted trailer? - rOps - 19.12.2016

TruckTrailer is created just like other vehicles (CreateVehicle).


Re: respawn a detachted trailer? - Konstantinos - 19.12.2016

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


Re: respawn a detachted trailer? - Mutha_X - 19.12.2016

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.


Re: respawn a detachted trailer? - rOps - 19.12.2016

still respawns


Re: respawn a detachted trailer? - Mutha_X - 19.12.2016

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




Re: respawn a detachted trailer? - rOps - 19.12.2016

[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


Re: respawn a detachted trailer? - Konstantinos - 19.12.2016

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.


Re: respawn a detachted trailer? - rOps - 19.12.2016

finally. thanks a lot!!