SA-MP Forums Archive
OnPlayerKeyStateChange Problem - 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: OnPlayerKeyStateChange Problem (/showthread.php?tid=98366)



OnPlayerKeyStateChange Problem - Mrkrabz - 20.09.2009

Okey, i have OnPlayerKeyStateChange Problem, I am trying to have Nitro on Click (Fire key) And Flip on ALT. Somehow this dosn't work, I can see how but i don't know how to fix.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) // AGAIN! fix indentation <3 - mikkel.
{
    if ((newkeys & (KEY_FIRE)) == (KEY_FIRE))
    {
    new vehicleid;
    vehicleid = GetPlayerVehicleID(playerid);
    if(!IsPlayerInInvalidNosVehicle(playerid, GetPlayerVehicleID(playerid)))
    {
        AddVehicleComponent(vehicleid, 1010);
        }
    }
    if ((newkeys & (4)) == (4))
    {
  if(IsPlayerInAnyVehicle(playerid))
  {
    {
      new Float:ZAngle,Float:X,Float:Y,Float:Z,vehicleid;
      vehicleid = GetPlayerVehicleID(playerid);
      GetVehiclePos(vehicleid,X,Y,Z);
      GetVehicleZAngle(vehicleid,ZAngle);
      SetVehicleZAngle(vehicleid,ZAngle);
      SetVehiclePos(vehicleid,X,Y,Z+2);
    }
  }
  }
    return 1;
}

Something smells nice, Brb.


Re: OnPlayerKeyStateChange Problem - Backwardsman97 - 20.09.2009

KEY_FIRE on foot isn't the same as in a vehicle. And you did several unnecessary things. I fixed the nos one but I don't know what the alt key is while in a vehicle. You will need to find that one out.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if ((newkeys & 1) == (1))
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(!IsPlayerInInvalidNosVehicle(playerid, vehicleid))
        {
            AddVehicleComponent(vehicleid, 1010);
            return 1;
        }
    }
    if ((newkeys & (4)) == (4))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new Float:ZAngle,vehicleid = GetPlayerVehicleID(playerid);
            GetVehicleZAngle(vehicleid,ZAngle);
            SetVehicleZAngle(vehicleid,ZAngle);
            return 1;
        }
    }
    return 1;
}




Re: OnPlayerKeyStateChange Problem - Mrkrabz - 20.09.2009

That kinda messed it up more, Thanks anyway


Re: OnPlayerKeyStateChange Problem - brett7 - 20.09.2009

what bits dont work then?


Re: OnPlayerKeyStateChange Problem - Backwardsman97 - 20.09.2009

Oops. I messed up when putting it in. I edited in the fixed version.


Re: OnPlayerKeyStateChange Problem - Mrkrabz - 20.09.2009

It all works It just that

When you press Fire it Gives you nos AND Flips your vehicle

if you press alt it gives you nos and flips your vehicle

:<


Re: OnPlayerKeyStateChange Problem - Backwardsman97 - 20.09.2009

Try the one I just put in there.


Re: OnPlayerKeyStateChange Problem - Mrkrabz - 20.09.2009

Works, but the point was i wanted it to lift them up when fliping, to stop them getting stuck and also it still does the same

You click, It Flips you and nos

And now its CTRL ? for nos?


Re: OnPlayerKeyStateChange Problem - Mrkrabz - 20.09.2009

Anyone? This is what i have so far

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((newkeys & 1) == (1))
{
new vehicleid = GetPlayerVehicleID(playerid);
if(!IsPlayerInInvalidNosVehicle(playerid, vehicleid))
{
AddVehicleComponent(vehicleid, 1010);
            return 1;
}
}
if ((newkeys & (4)) == (4))
{
if(IsPlayerInAnyVehicle(playerid))
{
      new Float:ZAngle,vehicleid = GetPlayerVehicleID(playerid);
      GetVehicleZAngle(vehicleid,ZAngle);
      SetVehicleZAngle(vehicleid,ZAngle);
            return 1;
}
    }
return 1;
}
Just now Alt Flips it and does NOS, CTRL just does nos, And fire does both.

I want it Fire to do NOS and ALT to do Flip.


Re: OnPlayerKeyStateChange Problem - Mrkrabz - 20.09.2009

Quote:
Originally Posted by Y_Leѕѕ
You should really use the named defines, not the numbers. It a) makes your code easier to read and b) means that if the values ever change in future versions you won't need to edit all your code.
Thanks for that, But i guess i can do that later, But i don't see why this is doing this.