[Tutorial] Deleting the '_' in RP names.
#1

Hello,

This is my very first tutorial where I want to teach the new RP scripters
to delete the '_' in RP names. Ex. Ihsan_Cingisiz - Ihsan Cingisiz. I wanted
to make this tutorial because I was unable to find a simple tutorial for this
script, and it's so easy, super noob-friendly.

Okay, now i'll give you a example:

pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
     new name[MAX_PLAYER_NAME], str[64];
     GetPlayerName(playerid, name, sizeof(name));
Okay, we've defined the player name into the variable 'name'.
Now we want to delete the '_' in the name, if the player has one.

We'll add this under the GetPlayerName(...));
pawn Код:
if(strfind(name,"_",true) == -1)return SendClientMessage(playerid,0xFF0000FF,"Your name must include an underscore for this command to work. Ex Ihsan_Cingisiz");
name[strfind(name, "_")] = ' ';
So the name was the variable where we defined the players
name in. I gave the name variables a color in case the new scripters
get confused with it.

Okay, so this is the full code for now:
pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
     new name[MAX_PLAYER_NAME, str[64];
     GetPlayerName(playerid, name, sizeof(name));
     if(strfind(name,"_",true) == -1)return SendClientMessage(playerid,0xFF0000FF,"Your name must include an           underscore for this command to work. Ex Ihsan_Cingisiz");
     name[strfind(name,"_")] = ' ';
Now we'll format the string to show the name.
(This is not a tutorial of how to format strings so there's not a
full explain of it.)

pawn Код:
format(str, sizeof(str), "Your name is: %s", name);
Okay, and now end all the script with return and close brackets.

The full code is:

pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
     new name[MAX_PLAYER_NAME, str[64];
     GetPlayerName(playerid, name, sizeof(name));
     name[strfind(name,"_")] = ' ';
     format(str, sizeof(str), "Your name is: %s", name);
     SendClientMessage(playerid, 0xFFFFFFFF, str);
     return 1;
}
This was my first tutorial.
I hope you learned something from it, I know it's not a really big tutorial,
but I didn't want to only follow tutorial but make one.

I hope to see you all on my next tutorial!

- Oh, sorry, the colors didn't work so i must delete them, if you're confused anyway
you're always welcome to leave a reaction/answer.
Reply
#2

pawn Код:
name[strfind(name, "_")] = ' ';
That's smart, but .. If the player does not have an underscore in his name, this code will most likely crash your server. It will try to access name[-1], which obviously does not exist.
Reply
#3

So i think then the command could be like this:

pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
    new name[MAX_PLAYER_NAME, str[64];
    GetPlayerName(playerid, name, sizeof(name));
    if(strfind(name,"_",true) == -1)return SendClientMessage(playerid,0xFF0000FF,"Your name must include an underscore for this command to work. Ex Ihsan_Cingisiz");
    name[strfind(name,"_")] = ' ';
    format(str, sizeof(str), "Your name is: %s", name);
    SendClientMessage(playerid, 0xFFFFFFFF, str);
    return 1;
}
I am not good at strfind, i only used it twice in my server for restricting players to deposit or withdraw negative cash from bank.

Not tested.
Reply
#4

Quote:
Originally Posted by Tee
Посмотреть сообщение
So i think then the command could be like this:

pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
    new name[MAX_PLAYER_NAME, str[64];
    GetPlayerName(playerid, name, sizeof(name));
    if(strfind(name,"_",true) == -1)return SendClientMessage(playerid,0xFF0000FF,"Your name must include an underscore for this command to work. Ex Ihsan_Cingisiz");
    name[strfind(name,"_")] = ' ';
    format(str, sizeof(str), "Your name is: %s", name);
    SendClientMessage(playerid, 0xFFFFFFFF, str);
    return 1;
}
I am not good at strfind, i only used it twice in my server for restricting players to deposit or withdraw negative cash from bank.

Not tested.
Oh, thanks for telling me that.. I never thought of that, i never had players without underscore because
they need to register from website and I must accept their application and then make the name with
underscore so people can't have not underscores in their game. That's why, but thanks for telling me that
i'm gonna make that in my script too.

I edited the new script with the one what Tee said.
Reply
#5

Quote:
Originally Posted by Ihsan-Cingisiz
Посмотреть сообщение
Hello,

This is my very first tutorial where I want to teach the new RP scripters
to delete the '_' in RP names. Ex. Ihsan_Cingisiz - Ihsan Cingisiz. I wanted
to make this tutorial because I was unable to find a simple tutorial for this
script, and it's so easy, super noob-friendly.

Okay, now i'll give you a example:

pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
     new name[MAX_PLAYER_NAME], str[64];
     GetPlayerName(playerid, name, sizeof(name));
Okay, we've defined the player name into the variable 'name'.
Now we want to delete the '_' in the name, if the player has one.

We'll add this under the GetPlayerName(...));
pawn Код:
if(strfind(name,"_",true) == -1)return SendClientMessage(playerid,0xFF0000FF,"Your name must include an underscore for this command to work. Ex Ihsan_Cingisiz");
name[strfind(name, "_")] = ' ';
So the name was the variable where we defined the players
name in. I gave the name variables a color in case the new scripters
get confused with it.

Okay, so this is the full code for now:
pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
     new name[MAX_PLAYER_NAME, str[64];
     GetPlayerName(playerid, name, sizeof(name));
     if(strfind(name,"_",true) == -1)return SendClientMessage(playerid,0xFF0000FF,"Your name must include an           underscore for this command to work. Ex Ihsan_Cingisiz");
     name[strfind(name,"_")] = ' ';
Now we'll format the string to show the name.
(This is not a tutorial of how to format strings so there's not a
full explain of it.)

pawn Код:
format(str, sizeof(str), "Your name is: %s", name);
Okay, and now end all the script with return and close brackets.

The full code is:

pawn Код:
if(strcmp(cmdtext, "/showmyname", true) == 0)
{
     new name[MAX_PLAYER_NAME, str[64];
     GetPlayerName(playerid, name, sizeof(name));
     name[strfind(name,"_")] = ' ';
     format(str, sizeof(str), "Your name is: %s", name);
     SendClientMessage(playerid, 0xFFFFFFFF, str);
     return 1;
}
This was my first tutorial.
I hope you learned something from it, I know it's not a really big tutorial,
but I didn't want to only follow tutorial but make one.

I hope to see you all on my next tutorial!

- Oh, sorry, the colors didn't work so i must delete them, if you're confused anyway
you're always welcome to leave a reaction/answer.
- Thanks for the fix Tee.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn Код:
name[strfind(name, "_")] = ' ';
That's smart, but .. If the player does not have an underscore in his name, this code will most likely crash your server. It will try to access name[-1], which obviously does not exist.
Код:
if(strfind(name,"_",true) == -1)return SendClientMessage(playerid,0xFF0000FF,"Your name must include an           underscore for this command to work. Ex Ihsan_Cingisiz");
This line checked their names have a "_" or not.
If it doesn't exist, the code will return and so there's no problem.
Reply
#7

So easy yet so usefull (Y)

Well done
Reply
#8

Quote:
Originally Posted by leong124
Посмотреть сообщение
This line checked their names have a "_" or not.
If it doesn't exist, the code will return and so there's no problem.
I posted that before he edited his post.
Reply
#9

No Problem Ihsan_Cingisiz, I am so happy because i don't really use strfind.
Reply
#10

Good Tutorial.

Made

pawn Код:
new var = strfind(name,"_",true);
if(var == -1) return SendClientMessage(playerid,0xFF0000FF,"Your name must include an underscore for this command to work. Ex Ihsan_Cingisiz");
name[var] = ' ';
Or

pawn Код:
new iLoop;
for(iLoop = 0; sName[iLoop] != '_'; ++iLoop) {}
sName[iLoop] = ' ';
Hugs
Reply
#11

Or just prepair "RP" name under OnPlayerConnect, store it in PVar and you don't need to loop through it all the time.
Reply
#12

Thank you, it really helped me. I'll be forwarding this to my scripter.
Reply
#13

or you could just use this

Code:
stock GiveNameSpace(nstring[])
{
    new strl;
    strl=strlen(nstring);
    while(strl--) {
    if(nstring[strl]=='_')	nstring[strl]=' ';
    }
    return 0;
}
Example :

Code:
new pName[MAX_PLAYER_NAME];
format(pName, sizeof(pName), "%s",  GetName(playerid));
GiveNameSpace(pName);
Then anything in the following code using pName will check if they have _ if they doo it removes it ...

for example

Code:
new pName[MAX_PLAYER_NAME], string[256];
format(pName, sizeof(pName), "%s", GetName(playerid));
GiveNameSpace(pName);
format(string, sizeof(string), "%s has just died", pName);
SendClientMessageToAll(playerid, RED, string);
Seems alot simpler than yours ...

GetName code >>
Code:
stock GetName(playerid)
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, sizeof name);
	return name;
}
Credits to whoever made that ^^ ( And the GiveNameSpace )
Reply
#14

Shadow-: That will cause an infinite loop becuase 'str1' would go from length to 0 to -1 to -2 and so on, of course, the script would crash before it even hit -2.

Correct:
pawn Code:
stock GiveNameSpace(nstring[])
{
    new strl;
    strl=strlen(nstring)-1;
    while(strl >= 0)
    {
        if(nstring[strl]=='_')
            nstring[strl]=' ';
        str1--;
    }
    return nstring;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)