Removing the " _ " symbol from name
#1

How can I remove the "_" from names? I mean, in /me /do etc


Firstname_Lastname takes out a cellphone. --> Firstname Lastname takes out a cellphone.




Thank you.
Reply
#2

This works perfect:
pawn Код:
new
   pName[MAX_PLAYER_NAME],
   i
;
GetPlayerName(playerid, pName, sizeof(pName));
while((i = strfind(pName, "_", true)) != -1)
   pName[i] = ' ';
Reply
#3

use strfind and strdel
Reply
#4

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
This works perfect:
pawn Код:
new
   pName[MAX_PLAYER_NAME],
   i
;
GetPlayerName(playerid, pName, sizeof(pName));
while((i = strfind(pName, "_", true)) != -1)
   pName[i] = ' ';
Where should I add this?
Reply
#5

Just add it for example in your command (at the top) and use pName in your string.
Reply
#6

You can turn it into a stock function
pawn Код:
stock Remove_FromName(playerid)
{
    new
       pName[MAX_PLAYER_NAME],
       i
    ;
    GetPlayerName(playerid, pName, sizeof(pName));
    while((i = strfind(pName, "_", true)) != -1)
    pName[i] = ' ';
    return pName;
}
Reply
#7

I tried both of them but still, it shows the "_" symbol.

That's my /me command.
pawn Код:
if(strcmp(cmd, "/me", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You havent logged in yet !");
                return 1;
            }
            if(PlayerInfo[playerid][pMuted] == 1)
            {
                SendClientMessage(playerid, TEAM_CYAN_COLOR, "You cannot speak, you have been silenced");
                return 1;
            }
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[128];
            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: /me [action]");
                return 1;
            }
            if(PlayerInfo[playerid][pAdminDuty] == 1)
            {
                format(string, sizeof(string), "* Admin %s", result);
            }
            if(PlayerInfo[playerid][pMaskuse] == 1 && PlayerInfo[playerid][pAdminDuty] == 0)
            {
                format(string, sizeof(string), "* Stranger %s", result);
            }
            if(PlayerInfo[playerid][pAdminDuty] == 0 && PlayerInfo[playerid][pMaskuse] == 0)
            {
                format(string, sizeof(string), "* %s %s", sendername, result);
            }
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            new y, m, d;
            new h,mi,s;
            getdate(y,m,d);
            gettime(h,mi,s);
            format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] [/ME] %s: %s",d,m,y,h,mi,s,sendername,giveplayer, result);
            ActionLog(string);
        }
        return 1;
    }
Reply
#8

pawn Код:
if(strcmp(cmd, "/me", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You havent logged in yet !");
                return 1;
            }
            if(PlayerInfo[playerid][pMuted] == 1)
            {
                SendClientMessage(playerid, TEAM_CYAN_COLOR, "You cannot speak, you have been silenced");
                return 1;
            }
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[128];
            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: /me [action]");
                return 1;
            }
            new
                pName[MAX_PLAYER_NAME],
                i
            ;
            GetPlayerName(playerid, pName, sizeof(pName));
            while((i = strfind(pName, "_", true)) != -1)
                pName[i] = ' ';
               
            if(PlayerInfo[playerid][pAdminDuty] == 1)
            {
                format(string, sizeof(string), "* Admin %s", result);
            }
            if(PlayerInfo[playerid][pMaskuse] == 1 && PlayerInfo[playerid][pAdminDuty] == 0)
            {
                format(string, sizeof(string), "* Stranger %s", result);
            }
            if(PlayerInfo[playerid][pAdminDuty] == 0 && PlayerInfo[playerid][pMaskuse] == 0)
            {
                format(string, sizeof(string), "* %s %s", pName, result);
            }
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            new y, m, d;
            new h,mi,s;
            getdate(y,m,d);
            gettime(h,mi,s);
            format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] [/ME] %s: %s",d,m,y,h,mi,s,sendername,giveplayer, result);
            ActionLog(string);
        }
        return 1;
    }
This should work. But I recommend you to use strtok in a function because all your command will be long like this.
Reply
#9

It worked. Thank you very much. But, is there any general function to remove the whole "_" symbols?
Reply
#10

The code I gave works perfect. Just change the pName to your string an delete GetPlayerName.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)