Show only first name
#1

Is there any script so it shows the Players First name only and not the Lastname?

If yes then can you tell me how it can be?
Reply
#2

you need a script or code huh ?

if only FirstName only
just disable Firstname_Lastname in your script./
Reply
#3

I dont want to Disable it i want the Script.
I dont want to Disable on everything. I want to Disable it on OnPlayerConnect. So the message will come Welcome to my server Firstname
Reply
#4

I just made this function for you, though I haven't had a chance to properly test it.

pawn Код:
stock getFirstName(szPlayerName[]) {
    new
        _tmpSzPlayerName[MAX_PLAYER_NAME],
        iCh = strfind(szPlayerName, "_", true);
       
    if(iCh != -1) {
        strcat(_tmpSzPlayerName, szPlayerName, MAX_PLAYER_NAME);
        strdel(_tmpSzPlayerName, iCh, strlen(szPlayerName));
    } else {
        format(_tmpSzPlayerName, sizeof(_tmpSzPlayerName), "Nameless");
    }

    return _tmpSzPlayerName;
}
This will only get the name before the first underscore.

Usage:
pawn Код:
new szName[MAX_PLAYER_NAME], szMessage[128];
GetPlayerName(playerid, szName, MAX_PLAYER_NAME);
format(szMessage, sizeof(szMessage), "Hi, %s. How are you?", getFirstName(szName));
Reply
#5

pawn Код:
stock GetFirstName(playerid){
 new PlayerName[128], Split[3][128];
 GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
 split(PlayerName, Split, '_');
 return Split[0];
}
Reply
#6

You need the split function for that code, CoaPsyFactor.
Reply
#7

pawn Код:
stock split(const strsrc[], strdest[][], delimiter)
{
    GetPlayerName(
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
        if(strsrc[i] == delimiter || i == strlen(strsrc))
        {
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
    return 1;
}
Reply
#8

You just could do it like that

pawn Код:
stock getFirstName(name[]) {
    new
        dest[MAX_PLAYER_NAME];
    dest[1] = strfind(name, "_", false);
    if(dest[1] != -1) {
        strcat(dest, name, dest[1]);
    } else {
        strcat(dest, name, sizeof dest);
    }
    return dest;
}
Reply
#9

as you wish
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)