SA-MP Forums Archive
Find and remove specific tag - 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: Find and remove specific tag (/showthread.php?tid=319519)



Find and remove specific tag - iTorran - 19.02.2012

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


Re: Find and remove specific tag - Jefff - 19.02.2012

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


Re: Find and remove specific tag - iTorran - 17.03.2012

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

The code you posted does not work.


Re: Find and remove specific tag - [ABK]Antonio - 17.03.2012

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


Re: Find and remove specific tag - ReneG - 17.03.2012

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);
    }



Re: Find and remove specific tag - MP2 - 17.03.2012

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.


Re: Find and remove specific tag - [ABK]Antonio - 17.03.2012

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


Re: Find and remove specific tag - iTorran - 17.03.2012

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.


Re: Find and remove specific tag - ReneG - 17.03.2012

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.