SA-MP Forums Archive
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(playeridparams[]){
    if (
GetVehicleModel(GetPlayerVehicleID(playerid)) != 525) return SendClientMessage(playeridCOLOR_GREY"You have to be in TowCar to use this command.");
    new 
Float:pXFloat pYFloat pZ;
    
GetPlayerPos(playeridpXpYpZ);
    new 
Float:vXFloat vYFloat vZ;
    new 
Found 0;
    new 
vid 0;
    while ((
vid<MAX_VEHICLES) && (!Found)) {
        
vid++;
        
GetVehiclePos(vidvXvYvZ);
        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(vidGetPlayerVehicleID(playerid));
            
SendClientMessage(playerid0xFFFF00AA"Car towed!");
        }
    }
    if (!
Found) {
        
SendClientMessage(playerid0xFFFF00AA"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....