Keys - 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: Keys (
/showthread.php?tid=486653)
Keys -
SKAzini - 09.01.2014
Basically, my script doesn't register the upkey correctly, I believe.
pawn Код:
if(!IsPlayerNPC(playerid) && PlayerLogged[playerid])
{
if(!IsPlayerInAnyVehicle(playerid))
{
new
keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr);
if((keys & KEY_SPRINT) && (keys & KEY_UP))
{
SendClientMessage(playerid, COLOR_LIGHTGREY, "1");
Noise[playerid] = 4;
}
else if(keys & KEY_WALK)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, "2");
Noise[playerid] = 1;
}
else if(keys & KEY_UP)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, "3");
Noise[playerid] = 2;
}
else Noise[playerid] = 0;
} else Noise[playerid] = 5;
switch(Noise[playerid])
{
case 0: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: none");
case 1: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: quiet");
case 2: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: noticable");
case 3: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: moderate");
case 4: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: loud");
case 5: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: very loud");
}
}
I can press ALT (KEY_WALK) for it to output 2 (debug) and if I press ALT (KEY_WALK) + Space (KEY_SPRINT) it outputs 1, why? It's supposed to output 1 when pressing Space + W.
The last KEY_UP doesn't work either.
Re: Keys - Patrick - 09.01.2014
This should work, or put it on a 1 second timer, it depends on you and how you use
OnPlayerUpdate
pawn Код:
public OnPlayerUpdate(playerid)
{
if(!IsPlayerNPC(playerid) && !IsPlayerInAnyVehicle(playerid) && PlayerLogged[playerid])
{
new
keys,
ud,
lr
;
GetPlayerKeys(playerid, keys, ud, lr);
if(keys == KEY_SPRINT && ud == KEY_UP)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, "1"), Noise[playerid] = 4;
}
else if(keys == KEY_WALK)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, "2"), Noise[playerid] = 1;
}
else if(ud == KEY_UP)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, "3"), Noise[playerid] = 2;
}
else
{
SendClientMessage(playerid, COLOR_LIGHTGREY, "4"), Noise[playerid] = 0;
}
////else Noise[playerid] = 5;
switch(Noise[playerid])
{
case 1: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: quiet");
case 2: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: noticable");
case 3: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: moderate");
case 4: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: loud");
case 5: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: very loud");
default: PlayerTextDrawSetString(playerid, StatsTextdraw2[playerid], "noise: none");
}
}
return true;
}
Re: Keys -
Vince - 09.01.2014
Beware of players with joypads. Updown and leftright can range from -128 to 128 and they also don't have to push a button to walk.