Remote the _ From a roleplay name and send the firstname to chat only!
#1

Hi guys, is there any way to remove the underscore from a name and send the text from before it only?

Example,

Lewis_Ryan

from the above name, all I need sending to chat is

Lewis Without the _ and ryan

Is this possible? Thanks =]
Reply
#2

pawn Код:
RPName(playerid)
{

    new
    sz_playerName[MAX_PLAYER_NAME],
    i_pos;

    GetPlayerName(playerid, sz_playerName, MAX_PLAYER_NAME);
    while ((i_pos = strfind(sz_playerName, "_", false, i_pos)) != -1) sz_playerName[i_pos] = ' ';
    return sz_playerName;
}
This will remove your underscore
Reply
#3

Quote:
Originally Posted by RenSoprano
Посмотреть сообщение
pawn Код:
RPName(playerid)
{

    new
    sz_playerName[MAX_PLAYER_NAME],
    i_pos;

    GetPlayerName(playerid, sz_playerName, MAX_PLAYER_NAME);
    while ((i_pos = strfind(sz_playerName, "_", false, i_pos)) != -1) sz_playerName[i_pos] = ' ';
    return sz_playerName;
}
This will remove your underscore
Nice rip from the NGRP script.
Reply
#4

Okay, thanks. How can I get the first half, before the underscore only. E.g Lewis_Ryan and I need Lewis ?

=]
Reply
#5

Try this.
pawn Код:
stock returnFirstName(playerid)
{
    new name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));

    new pos = strfind(name, '_');

    if(pos != -1) {
        strdel(name, pos, strlen(name));
        return name;
    }
    return 0;
}
The name HAS to be in Firstname_Lastname format that, or this won't work well.
Reply
#6

Thank you so much! But there are 2 errors

Код:
C:\Users\Lewis\Desktop\CityRP-EvoCity0.1\filterscripts\HelpBox.pwn(166) : error 035: argument type mismatch (argument 2)
C:\Users\Lewis\Desktop\CityRP-EvoCity0.1\filterscripts\HelpBox.pwn(172) : error 079: inconsistent return types (array & non-array)
Reply
#7

Sorry about that.
pawn Код:
stock returnFirstName(playerid)
{
    new name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));

    new pos = strfind(name, "_");

    if(pos != -1) {
        strdel(name, pos, strlen(name));
        return name;
    }

    else {
        name = "NULL";
    }
    return name;
}
Tested and works in-game.
Reply
#8

wow, fantastic! thank you so much!
Reply
#9

1 Last thing, I think the script may be able to detect if the player has got an underscore or not:

Код:
                                            GetPlayerName(playerid, sendername, sizeof(sendername));
	        	                    new namestring = strfind(sendername, "_", true);
					    if(namestring == -1)
					    {
					        SendClientMessage(playerid, COLOR_YELLOW, "Your name is not acceptable.");
					        SendClientMessage(playerid, COLOR_YELLOW, "Hint: Your name must be in the format Firstname_Lastname.");
					        SendClientMessage(playerid, COLOR_YELLOW, "Please pick a different name from the list given.");
				        	
					        return 1;
					    }
How can I integrate the above code, with the code that VincentDunn made for me?
Reply
#10

Never mind, I managed to do it:
Код:
 stock returnFirstName(playerid)
{
    new name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
    //
    new namestring = strfind(name, "_", true);
    if(namestring == -1)
    {
   		return name;
    }
	//
	
    new pos = strfind(name, "_");

    if(pos != -1) {
        strdel(name, pos, strlen(name));
        return name;
    }

    else {
        name = "NULL";
    }
    return name;
}
Thanks for all your help =]
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)