04.12.2016, 14:06
Hi,
I don't know if some of you have tried this already but I found a problem when creating a trailer and immediately after it, attach it to my vehicle.
I've created a graphical menu (using selectable textdraws) to select a vehicle.
It also puts me inside the vehicle.
That's working fine.
Now, when I'm inside a vehicle that can pull a trailer, the menu shows me the trailer I can attach to my vehicle.
It spawns the trailer and attaches it to my vehicle, but it isn't attached.
I had to resort to a timer to attach the trailer to my vehicle after some time.
Instead of this (this fails to attach the trailer to my vehicle):
I need to do this:
I find no other way to deal with this.
I guess using AttachTrailerToVehicle immediately after creating the trailer fails because the trailer hasn't streamed in yet and thus, it cannot be attached yet.
Is this the only way?
I don't know if some of you have tried this already but I found a problem when creating a trailer and immediately after it, attach it to my vehicle.
I've created a graphical menu (using selectable textdraws) to select a vehicle.
It also puts me inside the vehicle.
That's working fine.
Now, when I'm inside a vehicle that can pull a trailer, the menu shows me the trailer I can attach to my vehicle.
It spawns the trailer and attaches it to my vehicle, but it isn't attached.
I had to resort to a timer to attach the trailer to my vehicle after some time.
Instead of this (this fails to attach the trailer to my vehicle):
PHP код:
new trailerid = CreateVehicle(model, x, y, z, a, random(126), random(126), 300);
AttachTrailerToVehicle(trailerid, GetPlayerVehicleID(playerid));
PHP код:
// Inside a function
new trailerid = CreateVehicle(model, x, y, z, a, random(126), random(126), 300);
SetTimerEx("Vehicle_AttachTimer", 100, false, "ii", playerid, trailerid);
forward Vehicle_AttachTimer(playerid, trailerid);
public Vehicle_AttachTimer(playerid, trailerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
SendClientMessage(playerid, 0xFFFFFFFF, "Running attach timer");
// If the trailer has streamed in, attach it to the player's vehicle
if (IsVehicleStreamedIn(trailerid, playerid))
AttachTrailerToVehicle(trailerid, vehicleid);
else // The trailer hasn't streamed in yet, so run the timer again
SetTimerEx("Vehicle_AttachTimer", 100, false, "ii", playerid, trailerid);
}
I guess using AttachTrailerToVehicle immediately after creating the trailer fails because the trailer hasn't streamed in yet and thus, it cannot be attached yet.
Is this the only way?