Message to all players when doing /ban
#1

------
Reply
#2

You have to use

Код:
ID = ReturnUser(cmdtext[6]);
And at the
Код:
format(str, 64, "%s has been banned from the server for: %s", pName,rest);
Take the ",rest" out.
Here is the code, i think it should work
pawn Код:
else if(strcmp(cmdtext, "/ban", true, 5)==0)
{
  if(!IsPlayerAdmin(playerid)) return 0;
  if(!strlen(cmdtext[6]))
  {
    SendClientMessage(playerid, COLOR_ORED, "Usage: /ban [playerid] [reason]");
    return 1;
  }
  new ID = ReturnUser(cmdtext[6]);
  new pName[24], str[64];
  if(IsPlayerConnected(ID))
  {
    GetPlayerName(ID, pName, 24);
    format(str, 64, "%s has been banned from the server for: ", pName);
    SendClientMessageToAll(COLOR_ORED, str);
    print("Player banned");
    Ban(ID);
  }
  return 1;
}
Reply
#3

Quote:
Originally Posted by matrix_smq
You have to use

Код:
ID = ReturnUser(cmdtext[6]);
And at the
Код:
format(str, 64, "%s has been banned from the server for: %s", pName,rest);
Take the ",rest" out.
Here is the code, i think it should work
Код:
else if(strcmp(cmdtext, "/ban", true, 5)==0)
{
  if(!IsPlayerAdmin(playerid)) return 0;
  if(!strlen(cmdtext[6]))
  {
    SendClientMessage(playerid, COLOR_ORED, "Usage: /ban [playerid] [reason]");
    return 1;
  }
  new ID = ReturnUser(cmdtext[6]);
  new pName[24], str[64];
  if(IsPlayerConnected(ID))
  {
    GetPlayerName(ID, pName, 24);
    format(str, 64, "%s has been banned from the server for: ", pName);
    SendClientMessageToAll(COLOR_ORED, str);
    print("Player banned");
    Ban(ID);
  }
  return 1;
}
Thank you. I try
Reply
#4

Quote:
Originally Posted by matrix_smq
You have to use

Код:
ID = ReturnUser(cmdtext[6]);
And at the
Код:
format(str, 64, "%s has been banned from the server for: %s", pName,rest);
Take the ",rest" out.
Here is the code, i think it should work
Код:
else if(strcmp(cmdtext, "/ban", true, 5)==0)
{
  if(!IsPlayerAdmin(playerid)) return 0;
  if(!strlen(cmdtext[6]))
  {
    SendClientMessage(playerid, COLOR_ORED, "Usage: /ban [playerid] [reason]");
    return 1;
  }
  new ID = ReturnUser(cmdtext[6]);
  new pName[24], str[64];
  if(IsPlayerConnected(ID))
  {
    GetPlayerName(ID, pName, 24);
    format(str, 64, "%s has been banned from the server for: ", pName);
    SendClientMessageToAll(COLOR_ORED, str);
    print("Player banned");
    Ban(ID);
  }
  return 1;
}
Nope

Код:
C:\Users\Jani.Kannettava.000\Desktop\TEST\pawno\paapaaof.pwn(1139) : error 017: undefined symbol "ReturnUser"
C:\Users\Jani.Kannettava.000\Desktop\TEST\pawno\paapaaof.pwn(3890) : warning 203: symbol is never used: "GetId"
C:\Users\Jani.Kannettava.000\Desktop\TEST\pawno\paapaaof.pwn(3890) : warning 203: symbol is never used: "strvalfixed"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#5

pawn Код:
#include <utils>
if you don't have it, make a file utils.inc and in it write
pawn Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) // Strip out leading spaces
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) // Check whole passed string
    {
        // If they have a numeric name you have a problem (although names are checked on id failure)
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid))
            {
                /*if (playerid != INVALID_PLAYER_ID)
                {
                    SendClientMessage(playerid, 0xFF0000AA, "User not connected");
                }*/

                userid = INVALID_PLAYER_ID;
            }
            else
            {
                return userid; // A player was found
            }
        }
        /*else
        {
            if (playerid != INVALID_PLAYER_ID)
            {
                SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
            }
            userid = INVALID_PLAYER_ID;
        }
        return userid;*/

        // Removed for fallthrough code
    }
    // They entered [part of] a name or the id search failed (check names just incase)
    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
            {
                if (len == strlen(name)) // Exact match
                {
                    return i; // Return the exact player on an exact match
                    // Otherwise if there are two players:
                    // Me and MeYou any time you entered Me it would find both
                    // And never be able to return just Me's id
                }
                else // Partial match
                {
                    count++;
                    userid = i;
                }
            }
        }
    }
    if (count != 1)
    {
        if (playerid != INVALID_PLAYER_ID)
        {
            if (count)
            {
                SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
            }
            else
            {
                SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
            }
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid; // INVALID_USER_ID for bad return
}
Hope it helps!
EDIT: Place it in the pawno\include\ folder
Reply
#6

Quote:
Originally Posted by matrix_smq
pawn Код:
#include <utils>
if you don't have it, make a file utils.inc and in it write
pawn Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) // Strip out leading spaces
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) // Check whole passed string
    {
        // If they have a numeric name you have a problem (although names are checked on id failure)
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid))
            {
                /*if (playerid != INVALID_PLAYER_ID)
                {
                    SendClientMessage(playerid, 0xFF0000AA, "User not connected");
                }*/

                userid = INVALID_PLAYER_ID;
            }
            else
            {
                return userid; // A player was found
            }
        }
        /*else
        {
            if (playerid != INVALID_PLAYER_ID)
            {
                SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
            }
            userid = INVALID_PLAYER_ID;
        }
        return userid;*/

        // Removed for fallthrough code
    }
    // They entered [part of] a name or the id search failed (check names just incase)
    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
            {
                if (len == strlen(name)) // Exact match
                {
                    return i; // Return the exact player on an exact match
                    // Otherwise if there are two players:
                    // Me and MeYou any time you entered Me it would find both
                    // And never be able to return just Me's id
                }
                else // Partial match
                {
                    count++;
                    userid = i;
                }
            }
        }
    }
    if (count != 1)
    {
        if (playerid != INVALID_PLAYER_ID)
        {
            if (count)
            {
                SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
            }
            else
            {
                SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
            }
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid; // INVALID_USER_ID for bad return
}
Hope it helps!
Kick with this system works, not ban
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)