SA-MP Forums Archive
[FIXED]Mapping key to repair vehicle - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [FIXED]Mapping key to repair vehicle (/showthread.php?tid=122872)



[FIXED]Mapping key to repair vehicle - biltong - 23.01.2010

I've got my /r command that repairs the player's vehicle no problem, but now I'm trying to get my walk key to repair my vehicle, which is in this case, Alt.

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(IsPlayerInAnyVehicle(playerid))
	{
		new nos = GetPlayerVehicleID(playerid);
		if(Nitro(nos) && (oldkeys & 1 || oldkeys & 4))
		{
			RemoveVehicleComponent(nos, 1010);
			AddVehicleComponent(nos, 1010);
			return 1;
		}
	}
	if(IsPlayerInAnyVehicle(playerid))
	{
	  new vehicleid = GetPlayerVehicleID(playerid);
	  if((GetPlayerState(playerid) == PLAYER_STATE_DRIVER),((newkeys & 1024) && !(oldkeys & 1024))); // I keep getting an "empty statement" error on this line
		{
		  RepairVehicle(vehicleid);
		  SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
			return 1;
		}
	}
	return 1;
}
I tried to do it like so:
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(IsPlayerInAnyVehicle(playerid))
	{
		new nos = GetPlayerVehicleID(playerid);
		if(Nitro(nos) && (oldkeys & 1 || oldkeys & 4))
		{
			RemoveVehicleComponent(nos, 1010);
			AddVehicleComponent(nos, 1010);
			return 1;
		}
	}
	if(IsPlayerInAnyVehicle(playerid))
	{
	  new vehicleid = GetPlayerVehicleID(playerid);
	  if((GetPlayerState(playerid) == PLAYER_STATE_DRIVER),((newkeys & 1024) && !(oldkeys & 1024))) RepairVehicle(vehicleid),SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
		{
			return 1;
		}
	}
	return 1;
}
That eliminates the empty statement error, but it does absolutely nothing when I press alt in game, no message telling me my vehicle was repaired.
Any ideas?

EDIT: it now looks like this:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new nos = GetPlayerVehicleID(playerid);
        if(Nitro(nos) && (oldkeys & 1 || oldkeys & 4))
        {
            RemoveVehicleComponent(nos, 1010);
            AddVehicleComponent(nos, 1010);
            return 1;
        }
    }
    if(IsPlayerInAnyVehicle(playerid))
    {
      new vehicleid = GetPlayerVehicleID(playerid);
      if((GetPlayerState(playerid) == PLAYER_STATE_DRIVER),((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))) RepairVehicle(vehicleid),SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
      else SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle");
        {
            return 1;
        }
    }
    return 1;
}
But now whenever I press any key in a vehicle it tells me I'm not in a vehicle and doesn't repair my vehicle.


Re: Mapping key to repair vehicle - biltong - 24.01.2010

Bump

EDIT: Fixed it. It now looks like this:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new nos = GetPlayerVehicleID(playerid);
        if(Nitro(nos) && (oldkeys & 1 || oldkeys & 4))
        {
            RemoveVehicleComponent(nos, 1010);
            AddVehicleComponent(nos, 1010);
            return 1;
        }
    }
    if(IsPlayerInAnyVehicle(playerid))
    {
      new vehicleid = GetPlayerVehicleID(playerid);
      if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
      {
        if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
        {
          RepairVehicle(vehicleid);
          SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
          return 1;
            }
        }
        else(SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!"));
    }
    return 1;
}



Re: [FIXED]Mapping key to repair vehicle - bluray - 24.01.2010

word advice might make ur thing a little shorter. The guy cannot have player_state_driver. if he is not in a vehicle, so the:
Код:
if(IsPlayerInAnyVehicle(playerid)) //this line here
	{
	  new vehicleid = GetPlayerVehicleID(playerid);
	  if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	  {
that isnt really needed. so just cut that off.


Re: [FIXED]Mapping key to repair vehicle - biltong - 24.01.2010

But then anybody in the car would be able to use the command, and I don't want that. That's why it's there. Although it doesn't tell me I'm not in a vehicle if I try use it out of a vehicle