OnPlayerKeyStateChange
#1

Hey guys, I've been trying to let zombies infect with a punch but I couldn't make it work, I wonder how I could make it actually work.
The codes

under OnPlayerKeyStateChange
pawn Код:
if((newkeys < oldkeys) && PlayerInfo[playerid][pZombie] == 1)
    {
    if(oldkeys - newkeys == KEY_FIRE)
    {
        new playerb;
        new string[128];
        if(PlayerInfo[playerb][pZombie] == 1) return 1;
        if(Infected[playerb] == 1) return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}This player is already infected.");
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
        if(!IsPlayerNearPlayer(playerid, playerb, 1.0))
        {
        GameTextForPlayer(playerb,"~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~Infected~n~~w~Get An ~g~Antidote",3000,4);
        Infected[playerb] = 1;
        PlayerInfo[playerid][pInfects] += 1;
        SetTimerEx("InfectedPlayer", 3000, true, "i", playerb);
        format(string, sizeof(string), "* %s scratches %s, infecting them with the zombie virus.", RPN(playerid), RPN(playerb));
        ProxDetector(30, playerid, string, COLOR_PURPLE);
        }
    }
    }
Reply
#2

Код:
if(oldkeys - newkeys == KEY_FIRE)
You need to use bitwise AND here:

Код:
if (newkeys & KEY_FIRE)
Use the Wiki for reference: https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Reply
#3

Yea, I replaced the codes but it's still not working. Is there something wrong with the rest?
Reply
#4

Код:
if((newkeys < oldkeys) && PlayerInfo[playerid][pZombie] == 1)
The first check is unneeded and, most likely, wrong.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)