Replacing "_" with " "
#1

As subject says... I would like to replace "_" with " " in chat lines, any help?
Reply
#2

Use the strfind function on the name of the person, for example:

pawn Код:
new name[24];
GetPlayerName(playerid,name,24);
name[strfind(name,"_")] = ' ';
After that code is executed, the name variable will now contain a space where there used to be an _.

This is only an example, you likely need to adapt it for your script.
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Use the strfind function on the name of the person, for example:

pawn Код:
new name[24];
GetPlayerName(playerid,name,24);
name[strfind(name,"_")] = ' ';
After that code is executed, the name variable will now contain a space where there used to be an _.

This is only an example, you likely need to adapt it for your script.
I might have little problems with that...
Reply
#4

Quote:
Originally Posted by 77ther
Посмотреть сообщение
It's LARP edit, could you adapt it to that?
And where to put it? under ongamemodeinit or not?
Try to put it under:
pawn Код:
public OnPlayerText(playerid, text[])
Reply
#5

Quote:
Originally Posted by Unknown123
Посмотреть сообщение
Try to put it under:
pawn Код:
public OnPlayerText(playerid, text[])
no, it should be adapted, I guess...
Reply
#6

My suggestion is to put it under OnPlayerConnect,right after you check for RP name
Why there?
1.You will use it just once and no need to edit anything
2.It will save/read player file with " " (space)
Reply
#7

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
My suggestion is to put it under OnPlayerConnect,right after you check for RP name
Why there?
1.You will use it just once and no need to edit anything
2.It will save/read player file with " " (space)
It accualy doesn't work..

EDIT:
I found this, maybe I have to do something with it?
Код:
 new namestring = strfind(plname, "_", true);
Reply
#8

Quote:
Originally Posted by 77ther
Посмотреть сообщение
It accualy doesn't work..

EDIT:
I found this, maybe I have to do something with it?
Код:
 new namestring = strfind(plname, "_", true);
If their name doesn't have any underscore, it'll crash your server...

Try the code below.

pawn Код:
stock
    Name( playerid )
{
    new
        ply_name [ 24 ]
    ;
    GetPlayerName ( playerid , ply_name , sizeof ( ply_name ) ) ;
    if ( playerid != 0xFFFF ) {
        if ( strfind ( ply_name , "_" , true ) != -1 ) {
            name [ strfind ( ply_name , "_" ) ] = ' ';
            return ply_name;
        }
    }
    return -1;
}
Reply
#9

pawn Код:
stock GPN(playerid)
{
    new string[24];
    GetPlayerName(playerid,string,24);
    new str[24];
    strmid(str,string,0,strlen(string),24);
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if (str[i] == '_') str[i] = ' ';
    }
    return str;
}
Reply
#10

Quote:
Originally Posted by Shadow™
Посмотреть сообщение
pawn Код:
stock GPN(playerid)
{
    new string[24];
    GetPlayerName(playerid,string,24);
    new str[24];
    strmid(str,string,0,strlen(string),24);
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if (str[i] == '_') str[i] = ' ';
    }
    return str;
}
I keep getting 26 errors after I put it under OnPlayerText
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)