Respawn all free trailers?
#1

Hello guys, I was searching for the answer of this question in older threads, but didn't found it.

My question is how to respawn all FREE trailers, I mean all trailers, which didn't attached to the vehicle.
Reply
#2

HTML Code:
new trailerid = sizeof(TruckTrailer);

for(new vehicleid; vehicleid <= GetVehiclePoolSize(); vehicleid ++) 
{
     if(!IsTrailerAttachedToVehicle(vehicleid))
     {
          SetVehicleToRespawn(trailerid);
     }
}
Is this code correct? I don't think so.
Reply
#3

But how to get a list of used trailers?
Reply
#4

PHP Code:
for(new 0sizeof(TruckTrailer); i++)
{
    if(!
IsTrailerAttachedToVehicle(i))
    {
        
SetVehicleToRespawn(i);
    }

Not tested but I am 99% sure this would work
Reply
#5

PHP Code:

new bool:TrailerIsFree[MAX_VEHICLES] = true;
public 
OnPlayerCommandText(playeridcmdtext[])
{
if(!
strcmp(cmdtext"/respawnfreetrailers"true))
{
new 
TrailerID = -1;
for(new 
i=0i<MAX_VEHICLES;i=i+1)
{
if(
IsTrailerAttachedToVehicle(i) == 1)
{
TrailerID GetVehicleTrailer(i);
TrailerIsFree[TrailerID] = false;
}
}
for(new 
i=0i<MAX_VEHICLES;i=i+1)
{
if(
TrailerIsFree[i] == true)
{
SetVehicleToRespawn(i);
}
}
}
return 
0;

Reply
#6

Write it like this:

PHP Code:
new bool:trailer[(sizeof(TruckTrailer)) char];
for(new 
GetVehiclePoolSize(),iv!=0v--)
{
    if(
IsTrailerAttachedToVehicle(v) && (i=GetTrailerIndex(v)) != -1)
    {
        
trailer{i} = true;
    }
}
for(new 
ii<sizeof(TruckTrailer); i++)
{
    if(!
trailer{i}) SetVehicleToRespawn(TruckTrailer[i]);
}
stock GetTrailerIndex(v)
{
    for(new 
ii<sizeof(TruckTrailer); i++)
    {
        if(
TruckTrailer[i] == v) return i;
    }
    return -
1;

Reply
#7

Quote:
Originally Posted by Kaliber
View Post
PHP Code:
for(new ii<sizeof(TruckTrailer); i++) 
If TruckTrailer has size of 50 and there are 100 vehicles, half of them will be ignored.

https://sampwiki.blast.hk/wiki/OnTrailerUpdate

You can track when a trailer is attached/detached in this callback and store in in an array of MAX_VEHICLES. When you want to respawn trailers, you loop from 0 to sizeof(TruckTrailer)-1 and you check if the value of the array for the vehicleid is not attached and you respawn it.
Reply
#8

Quote:
Originally Posted by Calisthenics
View Post
If TruckTrailer has size of 50 and there are 100 vehicles, half of them will be ignored.
Yes, you don't say.

But in another post he used that, so it seemed that all Trailer he wanna respawn are TruckTrailer.

Otherwise it would be complete non-sense from him, he used that variable.
Reply
#9

Oh yeah, I forgot to check for the vehicle model, This one should definitely work but it would be better if you keept track of trailers towed with a vehicle variable that changes when a vehicle starts towing/untowing.

PHP Code:
new bool:TrailerIsFree[MAX_VEHICLES] = true;
public 
OnPlayerCommandText(playeridcmdtext[])
{
if(!
strcmp(cmdtext"/respawnfreetrailers"true))
{
new 
TrailerID = -1;
for(new 
i=0i<MAX_VEHICLES;i=i+1)
{
if(
IsTrailerAttachedToVehicle(i) == 1)
{
TrailerID GetVehicleTrailer(i);
TrailerIsFree[TrailerID] = false;
}
}
for(new 
i=0i<MAX_VEHICLES;i=i+1)
{
if(
TrailerIsFree[i] == true)
{
if(
GetVehicleModel(i) == 435 || GetVehicleModel(i) == 450 || GetVehicleModel(i) == 584 || GetVehicleModel(i) == 591)
{
SetVehicleToRespawn(i);
}
}
}
}
return 
0;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)