Is there a way - rep ++ question
#1

Is there a way to destroy a trailer or do something when the trailer deataches from truck ?
Thanks,
buburuzu19.
Reply
#2

There isn't.
Reply
#3

I think you can work with that callback:
https://sampwiki.blast.hk/wiki/OnTrailerUpdate
And this function:
https://sampwiki.blast.hk/wiki/IsTrailerAttachedToVehicle
Reply
#4

But if i make a global timer , how to check if trailer is not attached to any truck , the trailer is created by addstaticvehicleex , because my cars are created in Mysql db and the trailers are created when a player selects a route.
Reply
#5

pawn Код:
public OnTrailerUpdate(playerid, vehicleid)
{
      Trailer[vehicleid] = GetVehicleTrailer(vehicleid);
      return 1;
}

public OnPlayerUpdate(playerid)
{
      new vehicleid = GetPlayerVehicleID(playerid);
      if(IsPlayerInAnyVehicle(playerid) && !IsTrailerAttachedToVehicle(vehicleid))
      {
          if(Trailer[vehicleid] != INVALID_PLAYER_ID)
          {
                 CallLocalFunction("OnTrailerDetach", "id", playerid, vehicleid, Trailer[vehicleid]);
                 Trailer[vehicleid] = INVALID_VEHICLE_ID;
                 return true;
          }
     }
     return true;
}
Then you can:
pawn Код:
public OnTrailerDetach(playerid, vehicleid, trailer)
{
       DestroyVehicle(trailer);
       return 1;
}
Reply
#6

I think I have better way to do it:
Код:
public OnTrailerUpdate(playerid, vehicleid)
{
	for(new x, y = MAX_VEHICLES; x < y; x++)
	{
	    if(IsTrailerAttachedToVehicle(x) && GetVehicleTrailer(x) == vehicleid))
	    {
	        //trailer is attached
	        return 1;
	    }
	}
	//trailer not attached
	return 1;
}
Reply
#7

Quote:
Originally Posted by Abagail
Посмотреть сообщение
pawn Код:
public OnTrailerUpdate(playerid, vehicleid)
{
      Trailer[vehicleid] = GetVehicleTrailer(vehicleid);
      return 1;
}

public OnPlayerUpdate(playerid)
{
      new vehicleid = GetPlayerVehicleID(playerid);
      if(IsPlayerInAnyVehicle(playerid) && !IsTrailerAttachedToVehicle(vehicleid))
      {
          if(Trailer[vehicleid] != INVALID_PLAYER_ID)
          {
                 CallLocalFunction("OnTrailerDetach", "id", playerid, vehicleid, Trailer[vehicleid]);
                 Trailer[vehicleid] = INVALID_VEHICLE_ID;
                 return true;
          }
     }
     return true;
}
Then you can:
pawn Код:
public OnTrailerDetach(playerid, vehicleid, trailer)
{
       DestroyVehicle(trailer);
       return 1;
}
Nothing happens ...
Reply
#8

Quote:
Originally Posted by Raweresh
Посмотреть сообщение
I think I have better way to do it:
Код:
public OnTrailerUpdate(playerid, vehicleid)
{
	for(new x, y = MAX_VEHICLES; x < y; x++)
	{
	    if(IsTrailerAttachedToVehicle(x) && GetVehicleTrailer(x) == vehicleid))
	    {
	        //trailer is attached
	        return 1;
	    }
	}
	//trailer not attached
	return 1;
}
I get some erros, first i get assumed 0 cuz () i put them to [] and now i have:
pawn Код:
forward OnTrailerUpdate(playerid, vehicleid);
public OnTrailerUpdate(playerid, vehicleid)
{
    for(new x, y = MAX_VEHICLES; x < y; x++)
    {
        if(IsTrailerAttachedToVehicle[x] && GetVehicleTrailer[x] == vehicleid))
        {
            return 1;
        }
    }
    DestroyVehicle(trucker[playerid]);
    return 1;
}
And errors :
pawn Код:
C: x(2328) : error 028: invalid subscript (not an array or too many subscripts): "IsTrailerAttachedToVehicle"
C: x(2328) : warning 215: expression has no effect
C: x(2328) : error 001: expected token: ";", but found "]"
C: x(2328) : error 029: invalid expression, assumed zero
C: x(2328) : fatal error 107: too many error messages on one line
Reply
#9

Why you change ( to [?
Okay, use my version but you need SAMP 0.3z R4 version, here is windows pack:
http://files.sa-mp.com/samp03z_svr_R4_win32.zip
Reply
#10

0.3z R4 on linux i have ..my server is hosted
EDIT: So how to fix ur code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)