SA-MP Forums Archive
What's up here? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What's up here? (/showthread.php?tid=549253)



What's up here? - LeXuZ - 05.12.2014

Hello, i've been making an anticheat, and it kicks after getting 3 dections but it spams the screen when it kicks someone
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(hInfo[playerid][MoneyHackWarn] == 3)
    {
        new str[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, 24);
        format(str, sizeof(str), "%s Has been kicked for Money Hacks", name);
        SendClientMessageToAll(-1, str);
        SetTimerEx("KickTimer", 1000, false, "d", playerid);
        return 1;
    }
    if(hInfo[playerid][WeaponHackWarn] == 3)
    {
        new str[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, 24);
        format(str, sizeof(str), "%s Has been kicked for Weapon hacks", name);
        SendClientMessageToAll(-1, str);
        SetTimerEx("KickTimer", 1000, false, "d", playerid);
        return 1;
    }
    return 1;
}
Does anyone know how to fix it?


Re: What's up here? - iFiras - 05.12.2014

OnPlayerUpdate is called very frequently per second per player.
That's why it sends many messages.
You can place your code somewhere else. Otherwise, remove the message.


Re: What's up here? - LeXuZ - 05.12.2014

Hm, should i put it on a timer then? or would that course lag?


Re: What's up here? - iFiras - 05.12.2014

You should use a timer or stock, as far as I know.


Re: What's up here? - PowerPC603 - 05.12.2014

Since the player will be kicked, just reset the variable to 0:
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(hInfo[playerid][MoneyHackWarn] == 3)
    {
        new str[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, 24);
        format(str, sizeof(str), "%s Has been kicked for Money Hacks", name);
        SendClientMessageToAll(-1, str);
        SetTimerEx("KickTimer", 1000, false, "d", playerid);
        hInfo[playerid][MoneyHackWarn] = 0; // Reset the variables
        return 1;
    }
    if(hInfo[playerid][WeaponHackWarn] == 3)
    {
        new str[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, 24);
        format(str, sizeof(str), "%s Has been kicked for Weapon hacks", name);
        SendClientMessageToAll(-1, str);
        SetTimerEx("KickTimer", 1000, false, "d", playerid);
        hInfo[playerid][WeaponHackWarn] = 0; // Reset the variables
        return 1;
    }
    return 1;
}



Re: What's up here? - LeXuZ - 05.12.2014

Ahh, thank you PowerPC! once again you've helped me


Re: What's up here? - HY - 05.12.2014

Well, OnPlayerUpdate() it's very faster, and it's spamming all chat. You can try yourself.

pawn Код:
new Updates;

public OnPlayerUpdate(playerid)
{
    Updates++;
    return 1;
}

CMD:updates(playerid, params[])
{
    new string[50];
    format(string, sizeof(string), "Here are curently %d updates!", Updates);
    SendClientMessage(playerid, -1, string);
    return 1;
}
With this simple filescript, you will see how many updates are per second. More faster, I think it's 30 ms.

Anyway, you should use a timer wich checks every second how many warns it's having that player.

Edit: Again, I didn't saw the guy above me.


Re: What's up here? - Vince - 05.12.2014

That variable doesn't jut increment by itself! Don't use OnPlayerUpdate for stuff that is entirely within your control. Somewhere within your code you're doing

pawn Код:
hInfo[playerid][MoneyHackWarn]++
It is there you need to catch it, definitely not in OnPlayerUpdate.


Re: What's up here? - LeXuZ - 05.12.2014

So It's better to use a timer?


Re: What's up here? - LeXuZ - 05.12.2014

Ah, timer works perfectly, thank you guys!