SA-MP Forums Archive
[HELP] NAME SURNAME without _ - 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: [HELP] NAME SURNAME without _ (/showthread.php?tid=340334)



[HELP] NAME SURNAME without _ - KaioBourne - 06.05.2012

Hello, I wanted to know a tutorial, I add in my Roleplay gamemode, a system that removes the "_" of all names Surnames that way.
And I Duffy_Pendleton queri remove _ to be Duffy Pendleton without _


Re: [AJUDA] NOME SOBRENOME sem o _ - Catalyst- - 06.05.2012

pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
new pos = strfind(name, "_");
if(pos != -1)
    name[pos] = ' ';



Re: [AJUDA] NOME SOBRENOME sem o _ - SuperViper - 06.05.2012

Quote:
Originally Posted by Catalyst-
Посмотреть сообщение
pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
new pos = strfind(name, "_");
if(pos != -1)
    name[pos] = ' ';
Will only replace 1 '_', this will work if the person has more than one:

pawn Код:
GetPlayersName(playerid)
{
    new playersName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playersName, MAX_PLAYER_NAME);
    for(new i = 0; i < strlen(playersName); i++)
    {
        if(playersName[i] == '_') playersName[i] = ' ';
    }
    return playersName;
}



Re: [HELP] NAME SURNAME without _ - KaioBourne - 06.05.2012

pawn Код:
C:\DOCUME~1\Caio\Desktop\COMPAC~1\GAMEMO~1\CORP.pwn(44378) : warning 203: symbol is never used: "GetPlayersName"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase

Header size:           9488 bytes
Code size:          1630440 bytes
Data size:         10376104 bytes
Stack/heap size:      16384 bytes; estimated max. usage=4466 cells (17864 bytes)
Total requirements:12032416 bytes

1 Warning.
There was a warning


Re: [HELP] NAME SURNAME without _ - blewert - 06.05.2012

You're not using the function. The function needs to be used in order for it to compile correctly.

The way to fix this is by using stock, which doesn't return warnings if the function is not used in the script:

pawn Код:
stock GetPlayersName(playerid)
{
    new playersName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playersName, MAX_PLAYER_NAME);
    for(new i = 0; i < strlen(playersName); i++)
    {
        if(playersName[i] == '_') playersName[i] = ' ';
    }
    return playersName;
}



Re: [HELP] NAME SURNAME without _ - KaioBourne - 06.05.2012

Now compiled without warning, but is still showing the "_".


Re: [HELP] NAME SURNAME without _ - JaTochNietDan - 06.05.2012

Quote:
Originally Posted by KaioBourne
Посмотреть сообщение
Now compiled without warning, but is still showing the "_".
Well show us the code where you are using the newly provided function to strip the underscores from the names!


Re: [HELP] NAME SURNAME without _ - KaioBourne - 07.05.2012

pawn Код:
if(strcmp(cmd, "/do", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You havent logged in yet !");
                return 1;
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /do [action]");
                return 1;
            }
            if(PlayerInfo[playerid][pMaskuse] == 1)
            {
                format(string, sizeof(string), "* %s (( Stranger ))", result);
            }
            else
            {
                format(string, sizeof(string), "* %s (( %s ))", result, sendername);
            }
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            printf("%s", string);
        }
        return 1;
    }



Re: [AJUDA] NOME SOBRENOME sem o _ - Kudoz - 07.05.2012

Quote:
Originally Posted by Catalyst-
Посмотреть сообщение
pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
new pos = strfind(name, "_");
if(pos != -1)
    name[pos] = ' ';
Thats going OnPlayerText ?


Re: [HELP] NAME SURNAME without _ - iggy1 - 07.05.2012

Here's a replace char func i haven't tested it, but it should be better than calling strlen ever iteration.

pawn Код:
stock ReplaceChar( szString[] , chReplace = '_', chReplaceWith = ' ' )
{
    new _itr = 0;
       
    while( szString[ _itr ] != EOS )
    {
   
        if( szString[ _itr ] == chReplace ) szString[ _itr ] = chReplaceWith;
       
        ++_itr;
   
    }

}
szString is passed by reference.

pawn Код:
new szStr[ 32 ] = "replace_underscores_pliz";

ReplaceChar( szStr );

printf( szStr );//should print "replace underscore please"
You could use it to replace other chars too.

pawn Код:
new szStr[ 64 ] = "replace*asterix*pliz*with*underscore";

ReplaceChar( szStr, '*', '_' );

printf( szStr );//should print "replace_asterix_pliz_with_underscore"