Help with CAR TOW
#1

I want the car to be towed everytime I press "Caps Lock"
And when I press it again, it UnTows the car..

For UnTowing it when I press Caps Lock again, what do I have to change here ?


Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
	{
	if ((newkeys==KEY_CROUCH)&&(IsPlayerInAnyVehicle(playerid))&&(GetPlayerState(playerid)==PLAYER_STATE_DRIVER))
	  {
	  if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 525)
	    {
	    SendClientMessage(playerid,COLOR_WHITE,"trying to tow a car");
			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,COLOR_WHITE,"Car towed!");
 				  }
   			}
			if (!Found)
			  {
			  SendClientMessage(playerid,COLOR_GREY,"There is no car in range.");
			  }
		  }
	  }
	}
Reply
#2

Can anyone help me ??
Reply
#3

There are possible just theese keys:

Код:
#define KEY_ACTION				(1)
#define KEY_CROUCH				(2)
#define KEY_FIRE				(4)
#define KEY_SPRINT				(8)
#define KEY_SECONDARY_ATTACK	(16)
#define KEY_JUMP				(32)
#define KEY_LOOK_RIGHT			(64)
#define KEY_HANDBRAKE			(128)
#define KEY_LOOK_LEFT			(256)
#define KEY_SUBMISSION			(512)
#define KEY_LOOK_BEHIND			(512)
#define KEY_WALK				(1024)
#define KEY_ANALOG_UP			(2048)
#define KEY_ANALOG_DOWN			(4096)
#define KEY_ANALOG_RIGHT		(16384)
#define KEY_ANALOG_LEFT			(8192)

#define KEY_UP					(65408)
#define KEY_DOWN				(128)
#define KEY_LEFT				(65408)
#define KEY_RIGHT				(128)
This is from "a_samp.inc"
Reply
#4

Hm.. ok, this is not the answer I'm looking for.
I know the keys.
But I dont know how to untow the car...
Reply
#5

just first check if the car is already towwing something with IsTrailerAttachedToVehicle(GetPlayerVehicleID(play erid)),
and if so, DetachTrailerFromVehicle(vid,GetPlayerVehicleID(pl ayerid)); and return 1;

Then start the attaching procedure.
Reply
#6

i have this problem too
Reply
#7

http://pawn.pastebin.com/f4b4c5045

Try that. (didn't test)

Put the..
pawn Код:
new Trailer[MAX_VEHICLES] = 0;
..on the top of the script.

When you TOW a car, Trailer[vehicleid] gets the car's ID, and when you press the button again, it checks if Trailer[vehicleid] equals to 0. If it does, script continues, otherwise it detaches the car, sets the Trailer[vehicleid] to 0 and returns 1 to stop the script from proceeding(without the return it will attach the same car again, since Trailer[vehicleid] is 0).

I'd also suggest to replace...
pawn Код:
if ((floatabs(pX-vX)<7.0)&&(floatabs(pY-vY)<7.0)&&(floatabs(pZ-vZ)<7.0)&&(vid!=GetPlayerVehicleID(playerid)))
...with...
pawn Код:
if (IsPlayerInRangeOfPoint(playerid, 7.0, vX, vY, vZ) && vid != GetPlayerVehicleID(playerid))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)