A question.
#1

Is it somehow possible to create a function that gets called ONCE right when a player attaches a trailer to their truck without having to set a timer to check if the truck has trailer attached or not? As well as calling it right after they detach it?
Reply
#2

Quote:
Originally Posted by Sjn
Посмотреть сообщение
Is it somehow possible to create a function that gets called ONCE right when a player attaches a trailer to their truck without having to set a timer to check if the truck has trailer attached or not? As well as calling it right after they detach it?
There is no any callback for it so impossible..
The only way is a loop with using this IsTrailerAttachedToVehicle
Reply
#3

Oh well, i knew someone would suggest me to use IsTrailerAttachedToVehicle function, but that's not what i was looking for. I know such function doesn't exist but aren't there any ways i can create it myself?

I've seen a server where the trailer light turns on when you attach a trailer and turns off when detach.
Reply
#4

It IS what you are looking for.... There is no any callbacks for it so you need to do what you told not to do...
Create a timer and loop through all players, Check if there is a trailer attached to their car, if yes, get it and set its lights.
Reply
#5

Intriguing question. Something like this might work. Haven't tested it, though.

PHP код:
public OnTrailerUpdate(playeridvehicleid)
{
    
// vehicleid is the id of the trailer
    
new playerVehicle GetPlayerVehicleID(playerid);
    
    if(
playerVehicle
    {
        static 
attachedTrailer[MAX_VEHICLES]; 
        new 
currentTrailer GetVehicleTrailer(playerVehicle);
        
        if(
currentTrailer == vehicleid && attachedTrailer[playerVehicle] == 0)
        {
            
OnVehicleTrailerAttached(playerVehicleplayeridvehicleid);
            
attachedTrailer[playerVehicle] = vehicleid;
        }
        else if(
currentTrailer == && attachedTrailer[playerVehicle] == vehicleid)
        {
            
OnVehicleTrailerDetached(playerVehicleplayeridvehicleid);
            
attachedTrailer[playerVehicle] = 0;
        }
    }
    return 
1;
}
OnVehicleTrailerAttached(vehicleidplayeridtrailerid)
{
    
printf("new trailer with id %d attached to vehicle %d, driven by %d"traileridvehicleidplayerid);
}
OnVehicleTrailerDetached(vehicleidplayeridoldtrailerid)
{
    
printf("old trailer with id %d detached from vehicle %d, driven by %d"oldtraileridvehicleidplayerid);

Important to note is that these custom callbacks will only get called if the player that sends those updates is actually in the driver's cabine. A trailer can also be connected by pushing it but in that case this custom callback will not fire until someone actually enters the driver's cabin.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
Important to note is that these custom callbacks will only get called if the player that sends those updates is actually in the driver's cabine. A trailer can also be connected by pushing it but in that case this custom callback will not fire until someone actually enters the driver's cabin.
So doing it from a vehicle side would work, right ?.. Actually would be very slow and inefficient but just asking out of curiosity.
Like looping through vehicles and checking if there is a trailer attached and bla bla...
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
Intriguing question. Something like this might work. Haven't tested it, though.

PHP код:
public OnTrailerUpdate(playeridvehicleid)
{
    
// vehicleid is the id of the trailer
    
new playerVehicle GetPlayerVehicleID(playerid);
    
    if(
playerVehicle
    {
        static 
attachedTrailer[MAX_VEHICLES]; 
        new 
currentTrailer GetVehicleTrailer(playerVehicle);
        
        if(
currentTrailer == vehicleid && attachedTrailer[playerVehicle] == 0)
        {
            
OnVehicleTrailerAttached(playerVehicleplayeridvehicleid);
            
attachedTrailer[playerVehicle] = vehicleid;
        }
        else if(
currentTrailer == && attachedTrailer[playerVehicle] == vehicleid)
        {
            
OnVehicleTrailerDetached(playerVehicleplayeridvehicleid);
            
attachedTrailer[playerVehicle] = 0;
        }
    }
    return 
1;
}
OnVehicleTrailerAttached(vehicleidplayeridtrailerid)
{
    
printf("new trailer with id %d attached to vehicle %d, driven by %d"traileridvehicleidplayerid);
}
OnVehicleTrailerDetached(vehicleidplayeridoldtrailerid)
{
    
printf("old trailer with id %d detached from vehicle %d, driven by %d"oldtraileridvehicleidplayerid);

Important to note is that these custom callbacks will only get called if the player that sends those updates is actually in the driver's cabine. A trailer can also be connected by pushing it but in that case this custom callback will not fire until someone actually enters the driver's cabin.
Works, but the detach function isn't getting called.

And one question, does OnTrailerUpdate also has a timer running the same way as OnPlayerUpdate? If it does, i think making it with a server sided timer wouldn't make any difference, right? Just asking.

The reason why i am trying to avoid using a timer for this is because my server already has other timer functions and i don't want to add more scripts inside it as it could cause a bit of lag.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)