Trailer detection. Detach function is not getting called.
#1

I had posted for a help regarding these functions way back. These functions should get called right after player attach/detach a trailer from their truck.

In the previous thread, I got this idea from Vince. But for some reason only the attached function is getting called and not the detached one. I tried changing the statements but didn't help in anyway, can someone tell me what's the problem here?

PHP код:
PlayerAttachedTrailer(vehicleidplayeridtrailerid)
{
    
printf("Player %d attached the trailer id %d to vehicle id %d"playeridtraileridvehicleid);
    return 
1;
}
PlayerDetachedTrailer(vehicleidplayeridoldtrailerid)
{
    
printf("Player %d detached the trailer id %d from vehicleid %d"playeridoldtraileridvehicleid);
    return 
1;
}
public 
OnTrailerUpdate(playeridvehicleid)
{
    new 
vid GetPlayerVehicleID(playerid);
    if (
vid)
    {
        new 
attached_trailer GetVehicleTrailer(vid);
        if (
attached_trailer == vehicleid && g_AttachedTrailer[vid] == 0)
        {
            
PlayerAttachedTrailer(vidplayeridvehicleid);
            
g_AttachedTrailer[vid] = vehicleid;
        }
        else if (
attached_trailer == && g_AttachedTrailer[vid] == vehicleid// Tried changing statements inside this but didn't work.
        
{
            
PlayerDetachedTrailer(vidplayeridvehicleid);
            
g_AttachedTrailer[vid] = 0;
        }
    }
    return 
1;

Reply
#2

Use a timer to check if the vehicle has a trailer attached.
Код:
if(!IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
also, a variable like : IsAttached[MAX_PLAYERS] with 0 value;

When a trailer will be attached use : IsAttached[playerid] = 1;

The code could be like:

Код HTML:
forward TrailerTimer(playerid);
public TrailerTimer(playerid)
{
   if(!IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
  {
    if(IsAttached[playerid] == 1)
    {
     IsAttached[playerid] = 2;  
    }
  }
}
Now, verify into another timer to check if IsAttached[playerid] == 2; If it is, you can write a message there or something.
Reply
#3

I already know what you mean, but that's not what I am looking for.

If I'm not wrong, OnTrailerUpdate also gets called frequently. What I have right now just works fine for the "attached" function, I posted this to find out why the PlayerDetachedTrailer isn't getting called as the statements seems fine to me.
Reply
#4

Tested out of curiosity and in the last call of OnTrailerUpdate, GetVehicleTrailer always return the "vehicle" before detaching and not 0.

A timer (or OPU) would be needed to detect this unfortunately.
Reply
#5

Oh well, alright then. Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)