Changing the timer [HELP ASAP]
#1

How to change the timer so it can detect if the weapon is shooting in 2 milliseconds or lest


pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(Lrapid_oldticks[playerid] == 0) Lrapid_oldticks[playerid] = GetTickCount();
    else {
        new Lrapid_intervals,
            Lrapid_checkreturn = 1;
        if((Lrapid_intervals = GetTickCount() - Lrapid_oldticks[playerid]) <= 35 &&(GetPlayerWeapon(playerid) != 38
            && GetPlayerWeapon(playerid) != 28 && GetPlayerWeapon(playerid) != 32 && GetPlayerWeapon(playerid) != 31)) { //Submachines such as 32, 28 and minigun got a higher fire rate.
            Lrapid_checkreturn = CallLocalFunction("OnPlayerRapidFire", "iii", playerid, weaponid, Lrapid_intervals);
        }
        else if((Lrapid_intervals = GetTickCount() - Lrapid_oldticks[playerid]) <= 370 && (GetPlayerWeapon(playerid) == 34 ||
        GetPlayerWeapon(playerid) == 33)) {
            Lrapid_checkreturn = CallLocalFunction("OnPlayerRapidFire", "iii", playerid, weaponid, Lrapid_intervals);
        }
        Lrapid_oldticks[playerid] = GetTickCount();
        if(!Lrapid_checkreturn) return 0; //Doesn't allow to call the rest 'OnPlayerWeaponShot' works anymore.
    }
    #if defined LRAPID_OnPlayerWeaponShot
    return LRAPID_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
    #else
    return 1;
    #endif
}
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)