how to check players
#1

i'm makink an anti cheat script, everything is okey but how do i need check players for functions like if player has a baned wepon in his hands, but i need to check it by not lagging server, onplayerupdate is not good
Reply
#2

"It depends how many players you'll have on the server.. If very few it might be preferable to use OnPlayerUpdate.. because using a timer with a loop within it would be inefficient.

However if you had a server that was near capacity (198/200) You would want to stay well clear of OnPlayerUpdate, as it would be being called hundreds of times a second.. Every time a player changed their weapon, or moved, or did anything it would be called.."

To make it into a timer, do this:

pawn Код:
SetTimer("AntiCheatTimer", 5000, true); //add to OnGameModeInit

forward AntiCheatTimer();
public AntiCheatTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerWeapon(i) == 38) //minigun
            {
                Ban(i);
            }
        }
    }
    return 1;
}
Reply
#3

no any other soulutions without timer?
Reply
#4

You could use OnPlayerUpdate, but this is update a lot. I am not sure how many times a second, but if you build a anti-cheat out of it. That's a lot of checks the server has to do, and could cause some serious lag, specially if you have a lot of other stuff going on in the background.
Reply
#5

I think iGetty's solution is bang on perfect but I would make it an include like this and probably have a more advanced ban function.

pawn Код:
#include <YSI\y_hooks>

hook OnGameModeInit()
{
    SetTimer("AntiCheatTimer", 5000, true); //add to OnGameModeInit
    return 1;
}

forward AntiCheatTimer();
public AntiCheatTimer()
{
    foreach(new i : Player)
    {
        switch(GetPlayerWeapon(i))
        {
            case 38, 34: { Ban(i); }
        }
    }
    return 1;
}
If your worried about this lagging yourself get a better host.
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
I think iGetty's solution is bang on perfect but I would make it an include like this and probably have a more advanced ban function.

pawn Код:
#include <YSI\y_hooks>

hook OnGameModeInit()
{
    SetTimer("AntiCheatTimer", 5000, true); //add to OnGameModeInit
    return 1;
}

forward AntiCheatTimer();
public AntiCheatTimer()
{
    foreach(new i : Player)
    {
        switch(GetPlayerWeapon(i))
        {
            case 38, 34: { Ban(i); }
        }
    }
    return 1;
}
If your worried about this lagging yourself get a better host.
Thank you for that buddy, 5am here too tired to go into depth lol. Great coding above, most useful one IMO. Great work Pottus.
Reply
#7

Thank-you, I really think using includes is the way to go it's only a few lines and sure you could jam it into your gamemode but this way if there is a problem it's as simple as commenting out one line and there is absolutely no confusion over what the code actually does by far the best approach and really the only approach I would consider taking to create any system.
Reply
#8

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Thank-you, I really think using includes is the way to go it's only a few lines and sure you could jam it into your gamemode but this way if there is a problem it's as simple as commenting out one line and there is absolutely no confusion over what the code actually does by far the best approach and really the only approach I would consider taking to create any system.
I completely agree with you here. It makes the code more easy to read by the human-eye, then you can resolve any bugs/issues that you may be facing, then fix it as you said by commenting out one line at a time, to find the real problem. As long as the includes are working as they should, you'd have no issues with them so that means any coding error must be in what you (the original creator of any script that uses includes(which is more or less everyone, besides the a_samp and SA-MP includes that come with the server package), not you ).

It's all tit-for-tat, everything falls together in the end with help from others, but making it easier to read, not only for yourself but for the people helping will also make sure that the forum members can see the code clearly and if I was to look at some code that was neatly presented that had an issue, I'd more than likely be able to resolve it 100 times quicker than I would with messed up, unindented code.

Sorry for the wee rant there, had to be done tonight because I felt like I was going to explode for some strange reason, I've got my tappity tap fingers out, typing galore! Haha.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)