Find and remove specific tag
#1

Hi,

I cant figure out how i would remove.. for example the tag: [LOL] from a players name when they join.
I could easily do it but it wouldnt work if they joined for example:

Player[LOL]name or Playername[LOL]

So basically what i need is a code or explanation on how i can find and remove the tag [LOL]
Hope i explained it properly :P
Reply
#2

pawn Код:
stock RemoveTag(p,tag[] = "[LOL]")
{
    new n[24],pos,bool:found,len = strlen(tag);
    GetPlayerName(p,n,24);
    while((pos = strfind(n,tag,true,pos+1)) != (-1))
    {
        strdel(n,pos,(pos+len));
        found = true;
    }
    if(found)
        SetPlayerName(p,n);
}
hm but what if player nick = [LOL] ? xD
Reply
#3

Sorry for bump but there is no point in creating a new topic for the same thing..

The code you posted does not work.
Reply
#4

what about

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //create the string we store the name in
    GetPlayerName(playerid, name, sizeof(name)); //store the players name
    new start = strfind(name, "["); //check if it has an opening bracket, if it does it will store the starting position in here, if not it will return -1 which is fine
    if(strfind(name, "[LOL]")) //check if it's [LOL]
    {
        format(name, sizeof(name), "%s", strdel(name,start,start+4)); //store our new name in here delete [ + 4 (hopefully [LOL])
        SetPlayerName(playerid, name); //set their name to our new name string
    }
    return 1;
}
untested though, not sure if it will work
Reply
#5

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
what about

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    new start = strfind(name, "[");
    if(strfind(name, "[LOL]"))
    {
        format(name, sizeof(name), "%s", strdel(name,start,start+4));
        SetPlayerName(playerid, name);
    }
    return 1;
}
untested though, not sure if it will work
That wont work lol

This might
pawn Код:
if(strfind(name, "[LOL]") != -1) // If it WAS found
    {
        strdel(name,0,4) // Deletes characters 0,1,2,3,4
                         //                    [ L O L ]
        SetPlayerName(playerid, name);
    }
Reply
#6

You should also check if(strlen(name)-5 < 3) because the minimum name is 3. If their name is only [LOL] or hi[LOL] it won't set.
Reply
#7

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
That wont work lol

This might
pawn Код:
if(strfind(name, "[LOL]") != -1) // If it WAS found
    {
        strdel(name,0,4) // Deletes characters 0,1,2,3,4
                         //                    [ L O L ]
        SetPlayerName(playerid, name);
    }
read the first post

EDIT: i commented elaborating more on what I posted is theoretically going to do
Reply
#8

Antonio's code didn't work.
Vincent's did however, but if someone was to, lets say.. join as namehere[LOL], it would cut off the first part of their name.
Reply
#9

Quote:
Originally Posted by iTorran
Посмотреть сообщение
Antonio's code didn't work.
Vincent's did however, but if someone was to, lets say.. join as namehere[LOL], it would cut off the first part of their name.
I realized that too as soon as I wrote it. I'm currently looking at through the string.inc for a possible fix.
You could just compare their name with their clan player info, and if they aren't a part of the clan, then kick them, while telling them to change their name.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)