Tow a 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: Tow a car. (
/showthread.php?tid=591418)
Tow a car. -
GuitarMan - 11.10.2015
Hey.
I'm failing to attach someones car to Tow car. The idea is simple, Mechanic attaches someones car to his own truck and then pulls it to where it should be.
Код:
CMD:towcar(playerid, params[])
{
if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 525) return SendClientMessage(playerid, COLOR_GREY, "You have to be in TowCar to use this command.");
new TowCar = GetPlayerVehicleID(playerid);
new CarToBeTowed = GetPlayerVehicleID(params[0]);
AttachTrailerToVehicle(CarToBeTowed, TowCar);
return 1;
}
So, what am i doing wrong here?
Re: Tow a car. -
Dusan01 - 12.10.2015
you are doing all wrong, try like this:
PHP код:
CMD:towcar(playerid, params[]){
if (GetVehicleModel(GetPlayerVehicleID(playerid)) != 525) return SendClientMessage(playerid, COLOR_GREY, "You have to be in TowCar to use this command.");
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))) {
Found = 1;
if (IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid))) {
DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
}
AttachTrailerToVehicle(vid, GetPlayerVehicleID(playerid));
SendClientMessage(playerid, 0xFFFF00AA, "Car towed!");
}
}
if (!Found) {
SendClientMessage(playerid, 0xFFFF00AA, "There is no car in range.");
}
return 1;
}
Re: Tow a car. -
GuitarMan - 12.10.2015
It's basicly the same thing, it just checks if the car is in the range....