Vehicle won't repair. (OnPlayerKeyStateChange)
#1

So for some apparent reason, whenever I press the "2" key on my laptop, my vehicle doesn't repair. Any idea's on what I'm doing wrong? Thank you.

pawn Код:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
//
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SUBMISSION))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            RepairVehicle(vehicleid);
        }
    }
    return 1;
}
Reply
#2

Instead of doing PRESSED(KEY_SUBMISSION) do this: newkeys & KEY_SUBMISSION

Also, doing IsPlayerInAnyVehicle is a redundant check since when you do GetPlayerVehicleID it already runs a similar check and will just return an invalid ID if the player isn't in a vehicle.
Reply
#3

It works perfectly now. Could you explain to me what I was misunderstanding? Thank you buddy.
Reply
#4

Well OnPlayerKeyStateChange has an interesting way of checking which keys you push. You might just want to check the SA:MP Wiki about that callback.

https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)