Adding names
#1

How would I make it so if your admin level is 1 or above you have Admin in your name

Example:
[Admin]Ditch: Hi.

Also,
How would I stop someone comming on the server with admin in there name..

So if you joined with the name AdminDitch or something, it would kick you.
Reply
#2

pawn Код:
new szName[25];
GetPlayerName(playerid, szName, sizeof(szName));
new string[40];
format(string, sizeof(string), "[ADMIN]%s", szName);
SetPlayerName(playerid, string);
Use that for the first part. Untested.

And for the second, use this under OnPlayerConnect.

pawn Код:
new szName[25];
GetPlayerName(playerid, szName, sizeof(szName));
if(strfind(szName, "admin", true) != -1) Kick(playerid);
Untested. I may have messed up the strfind syntax- I don't use that function very often.
Reply
#3

1) You can do something like this to get player name and add [Admin] to the front of it.

pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 1) //Change to your admin variable
{
    new pname[MAX_PLAYER_NAME], string[128];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(string, sizeof(string), "[Admin] %s", pname);
    SetPlayerName(playerid, string);
}
This simply states you create two variables, string and pname. pname receives the players name, then formats it into a string after the [Admin] name in front of it. Then it simply sets the name to the string.

Untested, but it's worth a shot.

Not quite sure how to do the second thing.

You could try to use strfind.

pawn Код:
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
if(strfind(pname, "[Admin]", true) != -1)
{
    if(!PlayerInfo[playerid][pAdmin] >= 1) //Again,change to your admin variable
    {
        Kick(playerid);
        SendClientMessage(playerid, -1, "Please remove the [Admin] in your name, as you are not an admin");
        return 1;
    }
}
Never used something like this but if not correct, this would check the pname for [Admin] in it and would return with a kick and a sendclientmessage if he isn't an admin. If he is, it would continue.

EDIT: Beat me to it, Realcop T.T
Reply
#4

@RealCop
thats not so good
what if the username was already 20 char?

then the name would be cut!

best to override the OnPlayerText and just add to the name at that point.
Reply
#5

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
@RealCop
thats not so good
what if the username was already 20 char?

then the name would be cut!

best to override the OnPlayerText and just add to the name at that point.
There is nothing wrong with the code, the max amount of characters a player can enter sa-mp with is 20. So his code is just fine.
Reply
#6

yes but hes adding 7 char "[ADMIN]"
making it a total of 27 and it can only be 24.....

edit:
not that anyone needs 20char name but it could be a problem in a rare case.
if you use OnPlayerText you can avoid this.

dont send the default string
and format a new string with [ADMIN] in front.
Reply
#7

@Kindred,
Tag mismatch
pawn Код:
if(strfind(GetName(playerid), "Admin", true) != -1)
        {
            if(!PlayerInfo[playerid][pAdminLevel] >= 1) // HERERHERHEHREHREHREHRHERHEHRHE
            {
                Kick(playerid);
                SendClientMessage(playerid, -1, "Please remove the [Admin] in your name, as you are not an admin");
                return 1;
            }
        }
Reply
#8

Use this
pawn Код:
if(strfind(GetName(playerid), "Admin", true) != -1)
        {
            if(PlayerInfo[playerid][pAdminLevel] <= 1)
            {
                Kick(playerid);
                SendClientMessage(playerid, -1, "Please remove the [Admin] in your name, as you are not an admin");
                return 1;
            }
        }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Windows32
Посмотреть сообщение
Use this
pawn Код:
if(strfind(GetName(playerid), "Admin", true) != -1)
        {
            if(PlayerInfo[playerid][pAdminLevel] <= 1)
            {
                Kick(playerid);
                SendClientMessage(playerid, -1, "Please remove the [Admin] in your name, as you are not an admin");
                return 1;
            }
        }
    return 1;
}
Thanks!
Reply
#10

here is what i meant
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1) //Change to your admin variable
    {
        new str[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof (name));
        format(str, sizeof (str), "[ADMIN]%s: %s", name, text);
        SendClientMessageToAll( -1, str);
        return 0; // ignore the default text and send the custom one
    }

//all other players will just send as normal...
    return 1;
}
now you wont cut the name and even use inline colors if you like to stand out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)