SA-MP Forums Archive
PullVehicleIntoDirection pulls my car.... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: PullVehicleIntoDirection pulls my car.... (/showthread.php?tid=350911)



PullVehicleIntoDirection pulls my car.... - iWhite - 14.06.2012

Function:
Код:
stock PullVehicleIntoDirection(vehicleid, Float:x, Float:y, Float:z, Float:speed)
{
new
Float:distance,
Float:vehicle_pos[3];

GetVehiclePos(vehicleid, vehicle_pos[0], vehicle_pos[1], vehicle_pos[2]);
SetVehicleZAngle(vehicleid, atan2VehicleZ(vehicle_pos[0], vehicle_pos[1], x, y));
x -= vehicle_pos[0];
y -= vehicle_pos[1];
//z -= vehicle_pos[2];
distance = floatsqroot((x * x) + (y * y)/* + (z * z)*/);
x = (speed * x) / distance;
y = (speed * y) / distance;
//z = (speed * z) / distance;
GetVehicleVelocity(vehicleid, z, z, z);
SetVehicleVelocity(vehicleid, x, y, z);
}
forward Float:atan2VehicleZ(Float:Xb,Float:Yb,Float:Xe,Float:Ye);// Dunno how to name it...
stock Float:atan2VehicleZ(Float:Xb,Float:Yb,Float:Xe,Float:Ye)
{
        new Float:a = floatabs(360.0 - atan2( Xe-Xb,Ye-Yb));
        if(360 > a > 180)return a;
        return a-360.0;
}
Command to create the car:

Код:
    if(!strcmp(cmdtext, "/car1", true))
    {
	   GetPlayerPos(playerid, xs, ys, zs);
	   car1 = AddStaticVehicleEx(411, xs, ys, zs, 0, 1, 1, 15000);
	   return 1;
	}
And Command to drive to my position:

Код:
    if(!strcmp(cmdtext, "/go", true))
    {
	   SetTimerEx("Drive", 1000, true, "i", playerid);
       return 1;
	}
In "Drive" public:

   GetVehiclePos(GetPlayerVehicleID(playerid), xs, ys, zs);
   PullVehicleIntoDirection(car1, xs, ys, zs, 1);
   PullVehicleIntoDirection(car2, xs, ys, zs, 1);
Pulls my vehicle, but "car1" not moving....

Any ideas?


Re: PullVehicleIntoDirection pulls my car.... - Vince - 14.06.2012

As far as I know the car must be occupied for SetVehicleVelocity to work.


Re: PullVehicleIntoDirection pulls my car.... - Faisal_khan - 14.06.2012

Why don't just make a bot and let him be seated in your car for only the process of moving.


Re: PullVehicleIntoDirection pulls my car.... - darkowner - 14.06.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
As far as I know the car must be occupied for SetVehicleVelocity to work.
Agreed