Kick high ping players function is heavy
# support-forum
c
Copy code
[23:10:27] [debug] Long callback execution detected (hang or performance issue)
[23:10:27] [debug] AMX backtrace:
[23:10:27] [debug] #0 003abfe4 in public KickHighPingPlayers (i=73) at /home/hiwyn/Documents/sampserver/gamemodes/MM.pwn:21371
[23:10:27] [debug] #1 0037a8d8 in public SEC_5_SVLOOP () at /home/hiwyn/Documents/sampserver/gamemodes/MM.pwn:18366
21371: if(pingwarning[i] > 9) {
Copy code
c++
forward KickHighPingPlayers(i);
public KickHighPingPlayers(i) {
    new string[128];
    if(pingwarning[i] > 9) {
        format(string,sizeof(string),"AdmCmd: %s was Kicked for SERVER. Reason: High Ping.", PlayerName(i));
        SendClientMessageToAll(COLOR_LIGHTRED, string);
        Kick(i);
        pingwarning[i] = 0;
    }
    else if(GetPlayerPing(i) > 700) {
        pingwarning[i] += 2;
        SendClientMessage(i, COLOR_LIGHTRED, "You have exceeded the PING limit, adjust your internet or you will be kicked!");
    }
    else if(pingwarning[i] > 0 && GetPlayerPing(i) <= 700) { pingwarning[i] -= 1; }
}
is anybody got any idea about how to do it better?
w
Copy code
c
forward KickHighPingPlayers(i);
public KickHighPingPlayers(i) {
    if(GetPlayerPing(i) > 700) {
        if(++pingwarning[i] >= 5) { //adjust, don't spam the player with messages, lol
            format(string,sizeof(string),"AdmCmd: %s was Kicked for SERVER. Reason: High Ping.",
                PlayerName(i));
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            Kick(i);
            pingwarning[i] = 0;
        } else {
            SendClientMessage(i, COLOR_LIGHTRED, "You have exceeded the PING limit, adjust your internet or you will be kicked!");
        }
    } else {
        pingwarning[i] = 0;
    }
}
¯⁠\\⁠\_⁠(⁠ツ⁠)⁠_⁠/⁠¯
c
i dont get it @wooden-dusk-70200 where it makes the function more lighter?
w
No need to check pingwarning when the player's ping isn't above 700, except that nothing much, and this probably isn't the issue as you're probably calling the timer wrongly
also we're increasing the pingwarning in a single line