[Tutorial] Simple Ban System Tutorial
#1

Hey Guys....

I Will Show You How To Create A Simple Ban System By Rcon Admins

Add This In The Top Of The Script if you don't have one like it
pawn Код:
#define PATH "/Users/%s.ini"
Step One:

pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <YSI\y_ini>
//Note: Gonna Give You Includes Link In The End Of The Post [Don't Copy This Note BTW lol]
Step Two:

pawn Код:
enum PlayerInfo
{
    Banned
};
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Banned",SInfo[playerid][Banned]);
    return 1;
}
//Note: Here So We Can Make The Banned To Save The Stats ;)
//Note: Put This Above The Command That I'll Show Below[Don't Copy This Note BTW lol]
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}//Thats Also To Read And Load The Player Stats (we Added only ban) so it will load only ban
Step Three:

pawn Код:
command(ban, playerid, params[])
{
    if(IsPlayerAdmin(playerid))//RCON
    {
        new ID, R[25], string[100];//R = Reason
        new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
        if(sscanf(params, "is", ID, R)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /ban [ID] [Reason]");                                                    
        {
            if(ID != INVALID_PLAYER_ID)
            {
                SInfo[ID][Banned]=1;//To Make Player Banned When He Connect It Kick Him
                GetPlayerName(playerid, name, sizeof(name));
                GetPlayerName(ID, name2, sizeof(name2));
                format(string, sizeof(string), "%s[%d] has been banned By The Admin %s[%d] - %s", ID,name2, playerid, name, R);
                SendClientMessageToAll(0xFF1493FF, string);
                Kick(ID);
            }
            else SendClientMessage(playerid, 0xFF0000AA, "ID Not Connected.");
        }
    }
    else SendClientMessage(playerid, 0xFF0000AA, "Only Admins Can Use This COmmand.");
Step 4:
We Added
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
Before the if(SInfo[playerid][banned]) because first it loads the stats then check if player is banned
pawn Код:
public OnPlayerConnect(playerid)
{
    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);//Thats Hard To Explain, Just To Load The Data
    if(SInfo[playerid][Banned]==1)
    {
        SendClientMessage(playerid, 0xFF1493FF, "You Are Banned From The Server, Kicked!!!.");
        Kick(playerid);
    }
    return 1;
}
Step 5:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    INI_WriteInt(File,"Banned",SInfo[playerid][Banned]);
    return 1;
}
If You Found Any Bug. Inform Me

To UnBan A Playeer goto the scriptfile - playeruser then PlayerBanned = 0

SSCANF = https://sampforum.blast.hk/showthread.php?tid=120356

ZCMD = https://sampforum.blast.hk/showthread.php?tid=91354

YINI = https://sampforum.blast.hk/showthread.php?tid=175565
Reply
#2

Nice tutorial, thanks. Helped me out, I'm pretty shit at scripting :P
Reply
#3

Quote:
Originally Posted by Havak
Посмотреть сообщение
Nice tutorial, thanks. Helped me out, I'm pretty shit at scripting :P
No Problem Bro
Reply
#4

The tutorial was a cool idea but it simply wouldn't work. You're just preventing a certain playerid from joining which means that every person under that playerid will be kicked on connect rather than a name being banned. Just use the ban function or save names into a file / database and check it when a player connects.
Reply
#5

so ill change OnPlayerConnect to OnPlayerRequestClass

and tommorow when i wake up (going to sleep now) im gonna make little edits and add another include so i remove all it's bugs

thanks to make me remember TheKillr

Good Night Guys
Reply
#6

When doing the ban command you are setting playerid as banned not I'd also you can shorten this down to about 10 lines and save a lot of space plus looks neater
Reply
#7

Should explain everything more.
Reply
#8

Quote:
Originally Posted by GoldZoroGrab
Посмотреть сообщение
so ill change OnPlayerConnect to OnPlayerRequestClass
You obviously don't get him.
Reply
#9

Quote:
Originally Posted by Mr_DjolE
Посмотреть сообщение
You obviously don't get him.
I Think I Did Know, Please If there is other bugs, you can inform me also :P
Reply
#10

Quote:
Originally Posted by GoldZoroGrab
Посмотреть сообщение
I Think I Did Know, Please If there is other bugs, you can inform me also :P
They shall not inform you because you made a tutorial and you have to find out what's the problem is and fix them by your self ! You had to explain everything more . It is not good explained .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)