#1

OK i want a car to attach another car as it's trailer. I've seen it done before and i wanted to do it myself.

Here is my script:

Quote:

if(strcmp(cmd, "/attach", true) == 0) {


if(IsPlayerInAnyVehicle(playerid))
{


new vehid;
new vehid2;
vehid = GetPlayerVehicleID(playerid);
vehid2 = GetClosestCar(playerid);

AttachTrailerToVehicle(vehid,vehid2);


}
}

I have the stocks for the getclosestcar. But when i go into the game adn type /attach it says UNKNOWN COMMAND
Reply
#2

pawn Код:
if(strcmp(cmd, "/attach", true) == 0)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new vehid;
        new vehid2;
        vehid = GetPlayerVehicleID(playerid);
        vehid2 = GetClosestCar(playerid);
        AttachTrailerToVehicle(vehid,vehid2);
    }
    return 1;
}
Reply
#3

Right it dosent come up with UNKNOWN command but it dosen't do anything when i type /attach.


I did some searching and found some stocks to put in but it still dosent work.



Scripit:

Quote:

if(strcmp(cmd, "/attach", true) == 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
new vehid;
new vehid2;
vehid = GetPlayerVehicleID(playerid);
vehid2 = GetClosestVehicle(playerid);
AttachTrailerToVehicle(vehid,vehid2);
}
return 1;
}
Stocks

Quote:

stock GetClosestVehicle(playerid)
{
new vehicle = -1, Float:dis = 2000.0;
for(new i = 0; i < MAX_VEHICLES; i++)
{
new Float:dis2 = GetPlayerDistanceToVehicle(playerid, i);
if(dis2 > dis)
{
dis = dis2;
vehicle = i;
}
}
return vehicle;
}

stock Float:GetPlayerDistanceToVehicle(playerid, vehicleid)
{
new Floatos[3];
GetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
return GetPlayerDistanceToPoint(playerid, pos[0], pos[1], pos[2]);
}

stock Float:GetPlayerDistanceToPoint(playerid, {Float,_}:...)
{
new num = numargs(), Floatos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
if(num == 3) return floatsqroot(floatpower(floatabs(floatsub(pos[0], Float:getarg(1))), 2) + floatpower(floatabs(floatsub(pos[1], Float:getarg(2))), 2));
else if(num == 4) return floatsqroot(floatpower(floatabs(floatsub(pos[0], Float:getarg(1))), 2) + floatpower(floatabs(floatsub(pos[1], Float:getarg(2))), 2) + floatpower(floatabs(floatsub(pos[2], Float:getarg(3))), 2));
return -1.0;
}

Please help. I have done this before so don't say it's not possible.

Or give me a tow script but without a certain vehilce

Thanks in advance
Reply
#4

Bump
Reply
#5

I know the problem. When you want to attach the "trailer-car", it dosen't move. The solution: You should use the PutPlayerInVehicle() function, like this:

Код:
if(strcmp(cmd, "/attach", true) == 0)
{
  if(IsPlayerInAnyVehicle(playerid))
  {
   new vehid;
   new vehid2;
   vehid = GetPlayerVehicleID(playerid);
   vehid2 = GetClosestVehicle(playerid);
   PutPlayerInVehicle ( playerid, vehid2, 0 );
   PutPlayerInVehicle ( playerid, vehid, 0 );
   AttachTrailerToVehicle(vehid2,vehid); //vehid2 is the "trailer"! This must be the first!
  }
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)