#1

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.
Reply
#2

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;
}
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)