Remote the _ From a roleplay name and send the firstname to chat only! -
lewismichaelbbc - 25.11.2012
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 =]
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
RenSoprano - 25.11.2012
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
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
Calgon - 25.11.2012
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.
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
lewismichaelbbc - 25.11.2012
Okay, thanks. How can I get the first half, before the underscore only. E.g Lewis_Ryan and I need Lewis ?
=]
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
ReneG - 25.11.2012
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.
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
lewismichaelbbc - 25.11.2012
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)
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
ReneG - 25.11.2012
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.
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
lewismichaelbbc - 25.11.2012
wow, fantastic! thank you so much!
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
lewismichaelbbc - 25.11.2012
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?
Re: Remote the _ From a roleplay name and send the firstname to chat only! -
lewismichaelbbc - 25.11.2012
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 =]