SA-MP Forums Archive
Show only first name - 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: Show only first name (/showthread.php?tid=266858)



Show only first name - Harry_Sandhu - 06.07.2011

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?


Re: Show only first name - SwatOwner - 06.07.2011

you need a script or code huh ?

if only FirstName only
just disable Firstname_Lastname in your script./


Re: Show only first name - Harry_Sandhu - 06.07.2011

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


Re: Show only first name - Calgon - 06.07.2011

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



Re: Show only first name - CoaPsyFactor - 06.07.2011

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



Re: Show only first name - Calgon - 06.07.2011

You need the split function for that code, CoaPsyFactor.


Re: Show only first name - CoaPsyFactor - 06.07.2011

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



AW: Show only first name - Nero_3D - 06.07.2011

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



Re: Show only first name - CoaPsyFactor - 06.07.2011

as you wish