SA-MP Forums Archive
Replacing "_" with " " - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Replacing "_" with " " (/showthread.php?tid=223108)



Replacing "_" with " " - 77ther - 08.02.2011

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


Re: Replacing "_" with " " - JaTochNietDan - 08.02.2011

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.


Re: Replacing "_" with " " - 77ther - 08.02.2011

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...


Re: Replacing "_" with " " - Unknown123 - 08.02.2011

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[])



Re: Replacing "_" with " " - 77ther - 08.02.2011

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


Re: Replacing "_" with " " - DRIFT_HUNTER - 08.02.2011

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)


Re: Replacing "_" with " " - 77ther - 13.02.2011

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



Re: Replacing "_" with " " - California - 13.02.2011

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



Re: Replacing "_" with " " - Shadow™ - 13.02.2011

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



Re: Replacing "_" with " " - 77ther - 13.02.2011

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