SA-MP Forums Archive
HelpMe #5 [+REP] - 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: HelpMe #5 [+REP] (/showthread.php?tid=295600)



HelpMe #5 [+REP] - NessaHD - 06.11.2011

Hi guys, another "HelpMe", probably gain reputation like for helping me at these posts, lol.

I need help with the ban command, how to make it?
For example:

/ban [playerid]

As i'm not familiar with "targets" then i need some help, fast help could be nice.
Thanks.


Re: HelpMe #5 [+REP] - iNorton - 06.11.2011

pawn Код:
CMD:ban(playerid,params[])
{
    new id,reason,pName[MAX_PLAYER_NAME],string[128];
    if(sscanf(params,"uz[128]",id)) SendClientMessage(playerid,COLOR_YELLOW,"[SYNTAX]: /ban [ID]");
    else
    {
        if(PlayerInfo[playerid][pAdmin] >=1)
        {
            GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
            format(string,sizeof(string),"Player %s was banned by %s Reason: %s",id,pName,reason);
            SendClientMessageToAll(COLOR_RED,string);
            BanEx(id,"reason");
        }
    }
    return 1;
}
Not tested.

I guess? searching helps as well...
Using zcmd & sscanf


Re: HelpMe #5 [+REP] - Sascha - 06.11.2011

using dcmd:
this at the top:
pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
this at "OnPlayerCommandText"
pawn Код:
dcmd(ban, 3, cmdtext);
and this somewhere out of any callback:
pawn Код:
dcmd_ban(playerid, params[])
{
  if(strlen(params)) return SendClientMessage(playerid, 0x99999AA, "Useage: /ban id");
  new id = strval(params);
  if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0x999999AA, "Invalid player");
  if(id == playerid) return SendClientMessage(playerid, 0x99999AA, "you can't ban yourself");
  new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[100];
  GetPlayerName(playeird, name, sizeof(name));
  GetPlayerName(id, name2, sizeof(name2));
  format(string, sizeof(string), "%s is banned by %s", name2, name);
  SendClientMessageToAll(0x999999AA, string);
  Ban(id);
  return 1;
}



Re: HelpMe #5 [+REP] - NessaHD - 06.11.2011

iNorton's was better, sorry but dcmd sux..


Re: HelpMe #5 [+REP] - Sascha - 06.11.2011

Quote:
Originally Posted by cruteX_modshop
Посмотреть сообщение
iNorton's was better, sorry but dcmd sux..
indeed it does^^ although you asked for an example and you can easily copy that code into any other command processorD:... I just didn't want to use an include or w/e but make it useable by just the code I posted^^


Re: HelpMe #5 [+REP] - antonio112 - 06.11.2011

pawn Код:
CMD:ban(playerid, params[])
{
       if(!IsPlayerAdmin(playerid))
                return SendClientMessage(playerid, -1, "You're not allowed to use this command.");

       new pID, reason[128], string[128], pName[MAX_PLAYER_NAME], pSenderName[MAX_PLAYER_NAME];
       if(sscanf(params,"us[128]",id, string))
               return SendClientMessage(playerid, -1, "Usage: /ban [PlayerID] [Reason]");

       GetPlayerName(pID, pName, MAX_PLAYER_NAME);
       GetPlayerName(playerid, pSenderName, MAX_PLAYER_NAME);
       format(string, sizeof string, "Admin %s banned you for %s.", pSenderName, reason);
       SendClientMessage(pID, -1, string);
       format(string, sizeof string, "You banned %s for %s", pName, reason);
       SendClientMessage(playerid, -1, string;
       Ban(pID, reason);
       return 1;
}



Re: HelpMe #5 [+REP] - iNorton - 06.11.2011

Quote:
Originally Posted by antonio112
Посмотреть сообщение
pawn Код:
CMD:ban(playerid, params[])
{
       if(!IsPlayerAdmin(playerid))
                return SendClientMessage(playerid, -1, "You're not allowed to use this command.");

       new pID, reason[128], string[128], pName[MAX_PLAYER_NAME], pSenderName[MAX_PLAYER_NAME];
       if(sscanf(params,"us[128]",id, string))
               return SendClientMessage(playerid, -1, "Usage: /ban [PlayerID] [Reason]");

       GetPlayerName(pID, pName, MAX_PLAYER_NAME);
       GetPlayerName(playerid, pSenderName, MAX_PLAYER_NAME);
       format(string, sizeof string, "Admin %s banned you for %s.", pSenderName, reason);
       SendClientMessage(pID, -1, string);
       format(string, sizeof string, "You banned %s for %s", pName, reason);
       SendClientMessage(playerid, -1, string;
       Ban(pID, reason);
       return 1;
}
As a advise, use this one, way better, my one was just simple.


Re: HelpMe #5 [+REP] - Sascha - 06.11.2011

Quote:
Originally Posted by iNorton
Посмотреть сообщение
As a advise, use this one, way better, my one was just simple.
or just use all of our posts ans advices and created your own by yourself with the help of the provided codes.
This makes you learn it faster, so you actually learned something by this and did not just copy + pasted^^


Re: HelpMe #5 [+REP] - iNorton - 06.11.2011

Quote:
Originally Posted by Sascha
Посмотреть сообщение
or just use all of our posts ans advices and created your own by yourself with the help of the provided codes.
This makes you learn it faster, so you actually learned something by this and did not just copy + pasted^^
Well in these days people learn in that way :P


Re: HelpMe #5 [+REP] - Sascha - 06.11.2011

copy + paste is not really learning though (and if you learn anything useable with it, it lasts longer to learn..)^^ but well.. just do it in the way you like it most