SA-MP Forums Archive
key state change 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)
+--- Thread: key state change problem (/showthread.php?tid=665550)



key state change problem - bosmania - 08.04.2019

I have this under if "(newkeys & KEY_NO)" and when im pressing the key N nothing happens,its like this part of the script isn't even there

if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new Float, Float:y, Float:z;
GetVehiclePos(RentedVehicle[playerid], Float, Float:y, Float:z);

if(IsPlayerInRangeOfPoint(playerid, Float:5, Float, Float:y, Float:z))
{
if(LockedVeh[RentedVehicle[playerid]] == 0)
{
LockedVeh[RentedVehicle[playerid]] = 1;
SendClientMessage(playerid, -1, "Locked");
}
else {
LockedVeh[RentedVehicle[playerid]] = 0;
SendClientMessage(playerid, -1, "Unlocked");
}
}
}
}
}


Re: key state change problem - MP2 - 08.04.2019

Before getting onto your problem can I just share some tips and advice..

1. Use [ pawn ] tags. You have smileys in your code...
2. Indent your code so we can read it more easily.
3.
pawn Code:
if(IsPlayerInAnyVehicle(playerid))
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
Using both conditional statements is redundant. Just use the second one. If their state isn't driver they aren't in a vehicle, are they?

4.
pawn Code:
Float:5
That's just strange. Use 5.0.

5. Use bool: for true/false variables (LockedVeh).

6. Finally on to your actual problem:
Add debug messages after each conditional statement so you can visualise how the code is executing and where it is failing.