Get name before underscore
#1

How do I get the name before the underscore in roleplay names?
Eg. Michelle_Rodriguez

Is there a way to put the "Michelle" in a variable, without the characters after the underscore from GetPlayerName?
Reply
#2

This will help you out buddy:
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;
}
Reply
#3

Thanks. Worked for me.

pawn Код:
new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        SetPlayerName(playerid, getFirstName(name));
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)