OnPlayerKeyStateChange
#1

Hi alll..
I need somehelp with OnPlayerKeyStateChange public, when i use if(newkeys & KEY_FIRE), lets take example and i'll explain:

if(newkeys & KEY_FIRE) // /tow command
then the code under it, then after new one using if(newkeys & KEY_FIRE):

if(newkeys & KEY_FIRE) // /untow command
under it code bla bla bla

On game - first press ctrl/fire button the towtruck tows the vehicle but on second time to untow the vehicle doesn't respond

means /untow command key doesn't work, can someone explain me why and tell me what's wrong with that?
Reply
#2

pawn Код:
if((newkeys & KEY_FIRE) || (oldkeys & KEY_FIRE))
{
    if(PlayerInfo[playerid][Towing] == 1)
    {
        if(PlayerInfo[playerid][TowingCar] == 1)
        {
            // untow
            PlayerInfo[playerid][TowingCar] = 0;
        }
        else
        {
            // tow
            PlayerInfo[playerid][TowingCar] = 1;
        }
    }
}
Change it for your code to fit in.
Reply
#3

Correction:
pawn Код:
if(newkeys & KEY_FIRE)
{
    if(!PlayerInfo[playerid][TowingCar])
    {
        // tow
        PlayerInfo[playerid][TowingCar] = 1;
    }
    else if(PlayerInfo[playerid][TowingCar])
    {
        // untow
        PlayerInfo[playerid][TowingCar] = 0;
    }
}
Reply
#4

can you help with those brackets? i dont have time for them
+REP if works perfect

Код:
if((newkeys & KEY_FIRE) || (oldkeys & KEY_FIRE)) // tow command
	{
 	if(IsACop(playerid))
	if(I!sTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
	{
   		if(IsPlayerInAnyVehicle(playerid))
     	{
			new
				carid = GetPlayerVehicleID(playerid);

			if(IsATowTruck(carid))
			{
   				new
					closestcar = GetClosestCar(playerid, carid);

       			if(GetDistanceToCar(playerid,closestcar) <= 8 && !IsTrailerAttachedToVehicle(carid)) {
					foreach(Player, i) {
						if(GetPlayerVehicle(i, closestcar) != -1) {
						    if(ProxDetectorS(30.0,playerid,i))
								SendClientMessageEx(i, COLOR_LIGHTBLUE, "Someone is attempting to tow your vehicle away!");

							arr_Towing[playerid] = closestcar;
						    SendClientMessageEx(playerid, COLOR_GRAD2, "This player owned vehicle is available for impounding.");
      						return AttachTrailerToVehicle(closestcar,carid);
						}
					}
					SendClientMessageEx(playerid, COLOR_GRAD2, "This vehicle has no registration, it is available for impounding.");
					AttachTrailerToVehicle(closestcar,carid);
					arr_Towing[playerid] = closestcar;
					return 1;
     			}
			}
			else SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to tow with this vehicle.");
   		}
     	else SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be inside a vehicle to use this command!");
	}
   	else SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
	}
	else if(IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
	{
      	SendClientMessageEx(playerid, COLOR_GRAD1,"You have unhooked the vehicle that you were towing.");
		arr_Towing[playerid] = INVALID_VEHICLE_ID;
		DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
     	}
      	else
       	{
        	SendClientMessageEx(playerid, COLOR_GRAD1,"You are currently not towing anything.");
        }
  	}
   	else
	{
 		SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
	}
	return 1;
}
Reply
#5

No way anyone will write the script for you.
You gonna have to do it yourself buddy.
Reply
#6

I guess so..

pawn Код:
if(newkeys & KEY_FIRE) // tow command
{
    if(IsACop(playerid))
    {
        if(GetPlayerState(playerid, PLAYER_STATE_DRIVER)
        {
            new carid = GetPlayerVehicleID(playerid);
            if(!IsTrailerAttachedToVehicle(carid))
            {
                if(IsATowTruck(carid))
                {
                    new closestcar = GetClosestCar(playerid, carid);
                    if(GetDistanceToCar(playerid, closestcar) <= 8.0)
                    {
                        foreach(Player, i)
                        {
                            if(GetPlayerVehicle(i, closestcar) == -1) continue;
                            if(ProxDetectorS(30.0, playerid, i))
                            {
                                SendClientMessageEx(i, COLOR_LIGHTBLUE, "Someone is attempting to tow your vehicle away!");
                                arr_Towing[playerid] = closestcar;
                                SendClientMessageEx(playerid, COLOR_GRAD2, "This player owned vehicle is available for impounding.");
                                return AttachTrailerToVehicle(closestcar,carid);
                            }
                        }
                        SendClientMessageEx(playerid, COLOR_GRAD2, "This vehicle has no registration, it is available for impounding.");
                        AttachTrailerToVehicle(closestcar,carid);
                        arr_Towing[playerid] = closestcar;
                        return 1;
                    }
                }
                else SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to tow with this vehicle.");
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_GRAD1,"You have unhooked the vehicle that you were towing.");
                arr_Towing[playerid] = INVALID_VEHICLE_ID;
                DetachTrailerFromVehicle(carid);
            }
        }
        else SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be the driver of a vehicle to use this command!");
    }
    else SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)