Changing the timer [HELP ASAP]
#2

This
pawn Код:
else if((Lrapid_intervals = GetTickCount() - Lrapid_oldticks[playerid]) <= 370 && (GetPlayerWeapon(playerid) == 34 ||
        GetPlayerWeapon(playerid) == 33)) {
            Lrapid_checkreturn = CallLocalFunction("OnPlayerRapidFire", "iii", playerid, weaponid, Lrapid_intervals);
        }
}
will never get called since the conditions for having a rifle/sniper rifle are already fulfilled for the previous one. You should also assign GetTickCount to a variable so you don't have to keep calling that function. Also no need for GetPlayerWeapon when you have the weaponid already as a parameter.

I've optimized your code below. See the comments for explanation.

pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    new
        tickcount = GetTickCount();

    if(Lrapid_oldticks[playerid] == 0) Lrapid_oldticks[playerid] = tickcount;
    else {

        if (weaponid != 28 && weaponid != 31 && weaponid != 32 && weaponid != 38) {
            // Not a submachine or minigun
            new
                Lrapid_checkreturn = 1,
                Lrapid_intervals = tickcount - Lrapid_oldticks[playerid]; // Set only once instead of multiple times

            if ((weaponid != 33 && weaponid != 34 && Lrapid_intervals < 36) || Lrapid_intervals < 371) {
                // pass if interval is less than 36ms, UNLESS weapon is (sniper) rifle then interval can be less than 371ms
                // This will already detect if the interval is 2ms or less, but you can lower the value (36) if needed
                Lrapid_checkreturn = CallLocalFunction("OnPlayerRapidFire", "iii", playerid, weaponid, Lrapid_intervals);
            }
            Lrapid_oldticks[playerid] = tickcount; // Placed here since no need to save tickcount for submachine or minigun
            if(!Lrapid_checkreturn) return 0; // WeaponShot damage cancelled if OnPlayerRapidFire returns 0
        }
    }
    #if defined LRAPID_OnPlayerWeaponShot
    return LRAPID_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
    #else
    return 1;
    #endif
}
Also I should add that 36 milliseconds is low enough to detect rapid fire cheats for non-submachine/non-highrate guns.
Reply


Messages In This Thread
Changing the timer [HELP ASAP] - by [Cali]ChrOnic_T - 24.06.2014, 02:44
Re: Changing the timer [HELP ASAP] - by Corekt - 24.06.2014, 10:48

Forum Jump:


Users browsing this thread: 1 Guest(s)