SA-MP Forums Archive
Seperating name into 2 parts, - 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: Seperating name into 2 parts, (/showthread.php?tid=316565)



Seperating name into 2 parts, - milanosie - 07.02.2012

Hey there, How would I seperate a name?
EXAMPLE:

Someone's name is John_Dalton

I want it to show on a passport like
Name: John
SurName: Dalton


How would I do this


Re: Seperating name into 2 parts, - IceCube! - 07.02.2012

Somthing lie this....

pawn Код:
new string[MAX_PLAYER_NAME];
    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
    new pName[25];
    strmid(pName, string, 0, strlen(string), MAX_PLAYER_NAME);
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if (pName[i] == '_') pName[i] = ' ';
    }
(Ripped from my script


Re: Seperating name into 2 parts, - milanosie - 07.02.2012

Well, I dont see how that will show the sur and first name seperatly


Re: Seperating name into 2 parts, - TheBetaFox - 07.02.2012

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
Somthing lie this....

pawn Код:
new string[MAX_PLAYER_NAME];
    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
    new pName[25];
    strmid(pName, string, 0, strlen(string), MAX_PLAYER_NAME);
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if (pName[i] == '_') pName[i] = ' ';
    }
(Ripped from my script
That won't separate them into two separate strings.. that'll just take out the underscore.
If only we were also allowed to take rep...


Re: Seperating name into 2 parts, - IceCube! - 07.02.2012

Thanks for editing your first post and making me look like a right dick!. and then replying mking me look like a dick! I'll reply when you feel you can stop making me look like a dick!


Re: Seperating name into 2 parts, - TheBetaFox - 07.02.2012

What? The OP did not edit his first post; I saw the message before you replied, and it was the same.


Re: Seperating name into 2 parts, - milanosie - 07.02.2012

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
Thanks for editing your first post and making me look like a right dick!. and then replying mking me look like a dick! I'll reply when you feel you can stop making me look like a dick!
lol?
I never editted it?-.-


Re: Seperating name into 2 parts, - [XST]O_x - 07.02.2012

That should work:
pawn Код:
#include <a_samp>

new name[24],name2[24],surname[24];

public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp(cmdtext,"/test"))
    {
        GetPlayerName(playerid, name, sizeof(name));
        for(new i = 0; i < strlen(name); i++)
        {
            if(name[i] == '_')
            {
                strmid(name2,name,0,i);
                strmid(surname,name,(i+1),strlen(name));
            }
        }
        format(name,sizeof(name),"%s",name2);
        SendClientMessage(playerid, -1, name);
        format(name,sizeof(name),"%s",surname);
        SendClientMessage(playerid, -1, name);
        return 1;
    }
    return 0;
}



Re: Seperating name into 2 parts, - milanosie - 07.02.2012

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
That should work:
pawn Код:
#include <a_samp>

new name[24],name2[24],surname[24];

public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp(cmdtext,"/test"))
    {
        GetPlayerName(playerid, name, sizeof(name));
        for(new i = 0; i < strlen(name); i++)
        {
            if(name[i] == '_')
            {
                strmid(name2,name,0,i);
                strmid(surname,name,(i+1),strlen(name));
            }
        }
        format(name,sizeof(name),"%s",name2);
        SendClientMessage(playerid, -1, name);
        format(name,sizeof(name),"%s",surname);
        SendClientMessage(playerid, -1, name);
        return 1;
    }
    return 0;
}
thanks will try it out


Re: Seperating name into 2 parts, - [XST]O_x - 07.02.2012

Quote:
Originally Posted by milanosie
Посмотреть сообщение
thanks will try it out
A fully working function for further usages: (tested)
pawn Код:
Seperate(src[], res_string1[], res_string2[])
{
    for(new i = 0; i < strlen(src);i++)
    {
        if(src[i] == '_')
        {
            strmid(res_string1,src,0,i,24);
            strmid(res_string2,src,(i+1),strlen(src),24);
        }
    }
    return 1;
}