SA-MP Forums Archive
How to script ban and kick command? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to script ban and kick command? (/showthread.php?tid=255955)



How to script ban and kick command? - Hitman-97- - 18.05.2011

Guys? I don't know how to script a ban and a kick command, with dcmd, can someone give me an example?
I need it for my server, it has an admin system in the gamemode script, but there is no ban or kick, the prefix for admin is
pawn Код:
if(IsPlayerAdmin3(playerid))
.

This is an example of an admin command in my server.
pawn Код:
dcmd_makeadmin(playerid, params[])
{
    new tmp[256], tmp2[256], idx;
    tmp = strtok(params, idx);      // get player id parameter
    new id;
    tmp2 = strtok(params, idx);     // get admin level parameter
    new status = strval(tmp2);      // admin level to be set

    if(!IsNumeric(tmp))
        id = ReturnPlayerID(tmp);
    else
        id = strval(tmp);

    if(!IsPlayerRootAdmin(playerid)) SendClientMessageEx(playerid, COLOR_GREY, "Error: You need to be root admin to do that!"); // no access
    else if(!strlen(tmp) || !IsNumeric(tmp2) || !strlen(tmp2) || strval(tmp2) > 2 || strval(tmp2) < 0)
    {   // did not use command properly
        SendClientMessageEx(playerid, COLOR_GREY, "Usage: /makeadmin [player id/name] [admin level]");
        SendClientMessageEx(playerid, COLOR_GREEN, "Help - Levels: 0: Regular Player | 1: Administrator | 2: Root Admin");
    }
    else if(!IsPlayerConnected(id))
        return SendClientMessageEx(playerid, COLOR_GREY, "Error: Player not found."); // player doesnt exist
    else if(!Player[id][loggedin])
        return SendClientMessageEx(playerid, COLOR_GREY, "Error: Player not logged in."); // player not logged in
    else
    {
        new pfile[200];
        format(pfile, sizeof(pfile), "combinations/players/%s.ini", nick_encode(PlayerName(id))); // path to target players save file
        new pstatus[200];
        switch(status)
        {
            case 0: // Regular Player (Demotion)
            {
                format(pstatus, sizeof(pstatus), "** Admin %s has changed your account level to 0 (Regular Player)", PlayerName(playerid),GetPlayerLevelName(id));
                SendClientMessageEx(id, COLOR_GREEN, pstatus);
                #if DATA_SYSTEM == 1
                    dini_IntSet(pfile, "AdminLevel", 0);
                #elseif DATA_SYSTEM == 2
                    UpdateSqlUserDataInt(id, "AdminLevel", 0);
                #endif
                Player[id][pLevel] = 0;
                format(pstatus, sizeof(pstatus),"** Changed %s account level to 0 (%s)", PlayerName(id), GetPlayerLevelName(id));
                SendClientMessageEx(playerid, COLOR_GREEN, pstatus);
            }
            case 1: // Regular admin
            {
                #if DATA_SYSTEM == 1
                    dini_IntSet(pfile, "AdminLevel", 1);
                #elseif DATA_SYSTEM == 2
                    UpdateSqlUserDataInt(id, "AdminLevel", 1);
                #endif
                Player[id][pLevel] = 1;
                format(pstatus, sizeof(pstatus), "** Admin %s has changed your account level to 1 (%s)", PlayerName(playerid), GetPlayerLevelName(id));
                SendClientMessageEx(id, COLOR_GREEN, pstatus);
                format(pstatus, sizeof(pstatus),"** Changed %s account level to 1 (%s)", PlayerName(id), GetPlayerLevelName(id));
                SendClientMessageEx(playerid, COLOR_GREEN, pstatus);
                CallRemoteFunction("DC_MakeAdmin", "i", id);
            }
            case 2: // Root Admin
            {
                #if DATA_SYSTEM == 1
                    dini_IntSet(pfile, "AdminLevel", 2);
                #elseif DATA_SYSTEM == 2
                    UpdateSqlUserDataInt(id, "AdminLevel", 2);
                #endif
                Player[id][pLevel] = 2;
                format(pstatus, sizeof(pstatus),"** Admin %s has changed your account level to 2 (%s)", PlayerName(playerid), GetPlayerLevelName(id));
                SendClientMessageEx(id, COLOR_GREEN, pstatus);
                format(pstatus, sizeof(pstatus),"** Changed %s account level to 2 (%s)", PlayerName(id), GetPlayerLevelName(id));
                SendClientMessageEx(playerid, COLOR_GREEN, pstatus);
                CallRemoteFunction("DC_MakeAdmin", "i", id);
            }
        }

    }
    return 1;
}
I didn't make the script



Re: How to script ban and kick command? - BloodMaster - 18.05.2011

Код:
dcmd_kick(playerid,params[]){
new id;
if(IsPlayerAdmin3(playerid)) return SendClientMessage(playerid,-1,"You are not admin");
if(sscanf(params,"u",id)) return SendClientMessage(playerid,-1,"Use: /kick <id>");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,-1,"Wrong player id");
if(id == playerid) return SendClientMessage(playerid,-1,"You can't kick yourself");
Kick(id);
SendClientMessage(playerid,-1,"Player kicked");
return 1;
}
And use sscanf


Re: How to script ban and kick command? - Hitman-97- - 18.05.2011

and the same for ban?
pawn Код:
dcmd_ban(playerid,params[]){
new id;
if(IsPlayerAdmin3(playerid)) return SendClientMessage(playerid,-1,"You are not admin");
if(sscanf(params,"u",id)) return SendClientMessage(playerid,-1,"Use: /ban <id>");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,-1,"Wrong player id");
if(id == playerid) return SendClientMessage(playerid,-1,"You can't ban yourself");
ban(id);
SendClientMessage(playerid,-1,"Player banned");
return 1;
}



Re: How to script ban and kick command? - DeadAhead - 18.05.2011

Yes, Just change the ban to Ban. PAWN is Case Sensitive .


Re: How to script ban and kick command? - Hitman-97- - 19.05.2011

Can you add something like
"DeadAhead Was Banned By An Admin. Reason: Blah Blah"


Re: How to script ban and kick command? - xalith - 19.05.2011

You can easily create the reason, use a string, I'll add it if I come on my computer since I'm on my mobile