How to tow a car?
#1

Problem,the car is not towed.
AttachTrailerToVehicle not work.

Code:

Код:
if (newkeys == KEY_CTRL_BACK)
   {
        if(PlayerInfo[playerid][pJob] == 8)
  		{
  		    if(GetPlayerState(playerid) != 2 && GetPlayerVehicleID(playerid) != 525) return SCM(playerid, -1, "Nu esti in masina de mecanici.");
			new Float:pX,Float:pY,Float:pZ;
			GetPlayerPos(playerid,pX,pY,pZ);
			new Float:vX,Float:vY,Float:vZ;
			new Found=0;
			new vid=0;
			while((vid<MAX_VEHICLES)&&(!Found))
			{
				vid++;
				GetVehiclePos(vid,vX,vY,vZ);
				if ((floatabs(pX-vX)<7.0)&&(floatabs(pY-vY)<7.0)&&(floatabs(pZ-vZ)<7.0)&&(vid!=GetPlayerVehicleID(playerid)))
				{
					if(IsABike(vid) || GetVehicleModel(vid) == 448 ||  GetVehicleModel(vid) == 525 || GetVehicleModel(vid) == 461 || GetVehicleModel(vid) == 462 || GetVehicleModel(vid) == 463 || GetVehicleModel(vid) == 468 || GetVehicleModel(vid) == 471 || GetVehicleModel(vid) == 521 || GetVehicleModel(vid) == 522 || GetVehicleModel(vid) == 523)
					{
	    				return SCM(playerid, -1, "Nu poti tracta acest tip de vehicul.");
					}
					if(IsAnOwnableCar(vid))
					{
	    				SCM(playerid,COLOR_WHITE,"Nu ai voie sa tractezi masini personale.");
	    				return 1;
					}
					if(TowAcc[playerid] == 1) return SendClientMessage(playerid, COLOR_GREY, "Nu poti tracta atat de repede o masina, trebuie sa astepti 2 minute.");
	    			Found=1;
    				if(IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
					{
    					DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
 						DisablePlayerCheckpoint(playerid);
     					gPlayerCheckpointStatus[playerid] = CHECKPOINT_NONE;
      				}
         			else
           			{
 						AttachTrailerToVehicle(vid,GetPlayerVehicleID(playerid));
   						new rand;
						rand = random(sizeof(TowCarCk));
  						SetPlayerCheckpoint(playerid, TowCarCk[rand][0],TowCarCk[rand][1],TowCarCk[rand][2], 6);
  						CP[playerid] = 34;
					}
				}
			}
		}
   }
Reply
#2

You should write it more like that:

PHP код:
if (newkeys KEY_CTRL_BACK)
{
    if(
PlayerInfo[playerid][pJob] != 8) return 1;
    new 
veh GetPlayerVehicleID(playerid);
    if(
GetPlayerState(playerid) != && GetVehicleModel(veh) != 525) return SCM(playerid, -1"Nu esti in masina de mecanici.");
    if(
IsTrailerAttachedToVehicle(veh)) return DetachTrailerFromVehicle(veh),DisablePlayerCheckpoint(playerid),gPlayerCheckpointStatus[playerid] = CHECKPOINT_NONE;
    new 
trailer GetNearestTrailerFromPlayer(playerid,veh);
    if(!
CanBeTowed(trailer)) return SCM(playerid, -1"Nu poti tracta acest tip de vehicul.");
    if(
IsAnOwnableCar(trailer)) return SCM(playerid,COLOR_WHITE,"Nu ai voie sa tractezi masini personale.");
    if(
TowAcc[playerid] == 1) return SendClientMessage(playeridCOLOR_GREY"Nu poti tracta atat de repede o masina, trebuie sa astepti 2 minute.");
                
    
AttachTrailerToVehicle(trailerveh);
    new 
rand random(sizeof(TowCarCk));
    
SetPlayerCheckpoint(playeridTowCarCk[rand][0],TowCarCk[rand][1],TowCarCk[rand][2], 6);
    
CP[playerid] = 34;
    return 
1;
}
stock CanBeTowed(trailer)
{
    if(
IsABike(trailer) || trailer == INVALID_VEHICLE_ID) return 0;
    switch(
GetVehicleModel(trailer))
    {
        case 
448,525,461,462,463,468,471,521,522,523: return 0;
    }
    return 
1;
}
stock GetNearestVehicleFromPlayer(playeridvFloat:range=7.0)
{
    new 
Float:x,Float:y,Float:z;
    
GetPlayerPos(playeridx,y,z);
    for(new 
i=GetVehiclePoolSize(); i!=0i--)
    {
        if(
i!=&& GetVehicleDistanceFromPoint(ix,y,z) < range) return i;
    }
    return 
INVALID_VEHICLE_ID;

Reply
#3

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
You should write it more like that:

PHP код:
if (newkeys KEY_CTRL_BACK)
{
    if(
PlayerInfo[playerid][pJob] != 8) return 1;
    new 
veh GetPlayerVehicleID(playerid);
    if(
GetPlayerState(playerid) != && GetVehicleModel(veh) != 525) return SCM(playerid, -1"Nu esti in masina de mecanici.");
    if(
IsTrailerAttachedToVehicle(veh)) return DetachTrailerFromVehicle(veh),DisablePlayerCheckpoint(playerid),gPlayerCheckpointStatus[playerid] = CHECKPOINT_NONE;
    new 
trailer GetNearestTrailerFromPlayer(playerid,veh);
    if(!
CanBeTowed(trailer)) return SCM(playerid, -1"Nu poti tracta acest tip de vehicul.");
    if(
IsAnOwnableCar(trailer)) return SCM(playerid,COLOR_WHITE,"Nu ai voie sa tractezi masini personale.");
    if(
TowAcc[playerid] == 1) return SendClientMessage(playeridCOLOR_GREY"Nu poti tracta atat de repede o masina, trebuie sa astepti 2 minute.");
                
    
AttachTrailerToVehicle(trailerveh);
    new 
rand random(sizeof(TowCarCk));
    
SetPlayerCheckpoint(playeridTowCarCk[rand][0],TowCarCk[rand][1],TowCarCk[rand][2], 6);
    
CP[playerid] = 34;
    return 
1;
}
stock CanBeTowed(trailer)
{
    if(
IsABike(trailer) || trailer == INVALID_VEHICLE_ID) return 0;
    switch(
GetVehicleModel(trailer))
    {
        case 
448,525,461,462,463,468,471,521,522,523: return 0;
    }
    return 
1;
}
stock GetNearestVehicleFromPlayer(playeridvFloat:range=7.0)
{
    new 
Float:x,Float:y,Float:z;
    
GetPlayerPos(playeridx,y,z);
    for(new 
i=GetVehiclePoolSize(); i!=0i--)
    {
        if(
i!=&& GetVehicleDistanceFromPoint(ix,y,z) < range) return i;
    }
    return 
INVALID_VEHICLE_ID;

And GetNearestTrailerFromPlayer?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)