Vehicle won't repair. (OnPlayerKeyStateChange) - 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)
+--- Thread: Vehicle won't repair. (OnPlayerKeyStateChange) (
/showthread.php?tid=424202)
Vehicle won't repair. (OnPlayerKeyStateChange) -
rangerxxll - 21.03.2013
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;
}
Re: Vehicle won't repair. (OnPlayerKeyStateChange) -
Scenario - 21.03.2013
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.
Re: Vehicle won't repair. (OnPlayerKeyStateChange) -
rangerxxll - 21.03.2013
It works perfectly now. Could you explain to me what I was misunderstanding? Thank you buddy.
Re: Vehicle won't repair. (OnPlayerKeyStateChange) -
Scenario - 21.03.2013
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