[HELP] NAME SURNAME without _
#1

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 _
Reply
#2

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

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;
}
Reply
#4

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
Reply
#5

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;
}
Reply
#6

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

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!
Reply
#8

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;
    }
Reply
#9

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 ?
Reply
#10

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"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)