How to know if this timer will lag?
#1

I have an anti-cheat timer, that does alot of things.. I've tried to implement using foreach, but my script has never had an ammount of +10 players, so I'd like to know if this code is stable.
It runs every 500 ms.
pawn Код:
public AntiCheat()
{
    if (ServerConfig[AntiCheatEnabled] == 0) { return 0; }
    else
    foreach (Player, i)
    {
        if (IsSpawned(i))
        {
            // Anti jetpack hack
            if(GetPlayerSpecialAction(i) == SPECIAL_ACTION_USEJETPACK)
            {
                if (PlayerInfo[i][pAdminLevel] == 0)
                {
                    new ban[128], name[40];
                    GetPlayerName(i,name,40);
                    format(ban,sizeof(ban),"AdmWarn: %s has been banned by ALLIGATOR [Reason: jetpack hacks]",i);
                    SendClientMessageToAll(COLOR_RED,ban);
                    PlayerInfo[i][pAccountLocked] = 1;
                    print(ban);
                    BanEx(i,"JETPACK HACKS");
                    return 1;
                }
                else return 1;
            }
            // Anti forbidden weapons
            new w = GetPlayerWeapon(i);
            if (w == WEAPON_MINIGUN || w == WEAPON_ROCKETLAUNCHER || w == 43 || w == 42
            || w == WEAPON_MOLTOV || w == WEAPON_HEATSEEKER || w == 45 || w == 41
            || w == WEAPON_FLAMETHROWER || w == WEAPON_SATCHEL || w == 46 || w == 9)
            {
                if (PlayerInfo[i][pAdminLevel] == 0 && IsSpawned(i))
                {
                    new ban[128], name[40];
                    GetPlayerName(i,name,40);
                    format(ban,sizeof(ban),"AdmWarn: %s has been banned by ALLIGATOR [Reason: weapon hacks]",name);
                    SendClientMessageToAll(COLOR_RED,ban);
                    print(ban);
                    PlayerInfo[i][pAccountLocked] = 1;
                    BanEx(i,"WEAPON HACKS");
                }
            }
            // Anti weapon hack
            new wepon = GetPlayerWeapon(i);
            if(wepon > 0 && Weapons[i][wepon] == false && IsSpawned(i))
            {
                RemovePlayerWeapon(i, wepon);
                new kick[128], name[40];
                GetPlayerName(i,name,40);
                format(kick,sizeof(kick),"AdmWarn: %s has been kicked by ALLIGATOR [Reason: suspicious weapon hacks]",name);
                SendClientMessageToAll(COLOR_RED,kick);
                print(kick);
                Kick(i);
            }
            // Anti money hack
            if(GetPlayerMoney(i) != PlayerInfo[i][pMoney])
            {
                ResetPlayerMoney(i);
                GivePlayerMoney(i, PlayerInfo[i][pMoney]);
            }
            // Anti armour hack
            new Float:armour;
            GetPlayerArmour(i, armour);
            if (armour > 99.0 && Godmode[i] == 0)
            {
                new ban[128], name[40];
                GetPlayerName(i,name,40);
                format(ban,sizeof(ban),"AdmWarn: %s has been banned by ALLIGATOR [Reason: armour hacks]",name);
                SendClientMessageToAll(COLOR_RED,ban);
                print(ban);
                PlayerInfo[i][pAccountLocked] = 1;
                BanEx(i,"ARMOUR HACKS");
            }
            // Anti vehicle health hack
            new Float:health, veh;
            veh = GetPlayerVehicleID(i);
            GetVehicleHealth(veh, health);
            if(health >= 1000.00)
            {
                new ban[128], name[40];
                GetPlayerName(i,name,40);
                format(ban,sizeof(ban),"AdmWarn: %s has been banned by ALLIGATOR [Reason: vehicle health hacks]",name);
                SendClientMessageToAll(COLOR_RED,ban);
                print(ban);
                PlayerInfo[i][pAccountLocked] = 1;
                BanEx(i,"VEHICLE HEALTH");
            }
        }
    }
    return 1;
}
Reply
#2

It seems to don't lags, and a timer with 500 ms delay is OK.
Reply
#3

Ah well, I think.. I hope it goes stable I don't want the script to crash with +30 players.
Thanks.
Reply
#4

Quote:
Originally Posted by admantis
Посмотреть сообщение
Ah well, I think.. I hope it goes stable I don't want the script to crash with +30 players.
Thanks.
No problem - Why do you think it will crash with more than 30 players?
Reply
#5

I think a 1000ms(1 sec) is good enough, there is not much that a player can do to avoid something in one second, but I think 500ms is good, I doubt it will cause any problems, as MrDeath537 mentioned.
Reply
#6

Quote:
Originally Posted by MrDeath537
Посмотреть сообщение
No problem - Why do you think it will crash with more than 30 players?
Well, the code itself look quite large, and I sometimes kinda exagerate with the CPU usage. Thought I think foreach will save me ALOT of usage as well, no?
Reply
#7

Quote:
Originally Posted by admantis
Посмотреть сообщение
Well, the code itself look quite large, and I sometimes kinda exagerate with the CPU usage. Thought I think foreach will save me ALOT of usage as well, no?
Definitely.
Reply
#8

I see, thank for your replies.
Reply
#9

Quote:
Originally Posted by admantis
Посмотреть сообщение
Well, the code itself look quite large, and I sometimes kinda exagerate with the CPU usage. Thought I think foreach will save me ALOT of usage as well, no?
A code can be as long as you want but not lagging . Did you read the scripting optimizations topic made by ******?
If you don't it's quite interesting, you should read it.




Quote:
Originally Posted by admantis
Посмотреть сообщение
I see, thank for your replies.
You're welcome
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)