Jump to content
  • 0

BrianL's Name Change NPC - check for spaces at the beginning/end of name


Question

Posted

The problem is players uses space in the beginning of name which is hard to recall or ban them, is there a way to disable the spacebar at the start of the name?

// http://www.eathena.ws/board/index.php?showtopic=216929

poring_c01,100,100,0 script NameChange 910,{
// CONFIG - copy these settings from ../conf/char_athena.conf
set .@char_name_option, 1;
set .@char_name_letters$, "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";


mes "Input the name you want to change to:";
input .@name$;

// check name length
if (getstrlen(.@name$)<4) {
mes "Names must be at least^FF0000 4^000000 characters long.";
close;
} else if (getstrlen(.@name$)>24) {
mes "Names can be up to^FF0000 24^000000 characters long.";
close;
}
// check allowed characters
if (.@char_name_option == 1) {
// only letters/symbols in 'char_name_letters' are allowed
for (set .@i,0; .@i<getstrlen(.@name$); set .@i,.@i+1) {
if (!compare(.@char_name_letters$, charat(.@name$,.@i))) {
mes "Invalid character: " + charat(.@name$,.@i);
close;
}
}
} else if (.@char_name_option == 2) {
// letters/symbols in 'char_name_letters' option are forbidden
for (set .@i,0; .@i<getstrlen(.@name$); set .@i,.@i+1) {
if (compare(.@char_name_letters$, charat(.@name$,.@i))) {
mes "Invalid character: " + charat(.@name$,.@i);
close;
}
}
}

// confirm
mes "Change your name from";
mes strcharinfo(0)+" -->^0000FF "+.@name$+"^000000 ?";
mes "^FF0000After you confirm, you will be logged out. Please wait 10 seconds before logging back in!";
if(select("Yes, change my name:No, thanks")==2) close;

if (getcharid(1)) {
mes "Please leave your party before requesting a name change.";
close;
} else if (getcharid(2)) {
mes "Please leave your guild before requesting a name change.";
close;
}
// check if name exists
query_sql "SELECT COUNT(char_id) FROM `char` WHERE `name`='"+escape_sql(.@name$)+"'", .@name_exists;
if (.@name_exists) {
mes "Sorry, that name is already taken ";
close;
}

// Zeny/Item cost goes here
// if(countitem(13962) < 5) {
// mes "[Namechange Service]";
// mes "It appears that you're lacking some Donation Credit Boxes.";
// close;
// }
// delitem 13962,5;

set .@char_id, getcharid(0); // save their Char ID
atcommand "@kick "+strcharinfo(0);
// sleep 500; // (usually not necessary) give the server time to save their char to SQL
query_sql "UPDATE `char` SET `name`='"+escape_sql(.@name$)+"' WHERE char_id="+.@char_id;
end;
}
[/codeBOX]

7 answers to this question

Recommended Posts

  • 1
Posted

Since the script is already using 'charat', you can use that to check for spaces at the beginning/end:

Add this before the // check allowed characters section:

// check for spaces at the beginning/end
if (charat(.@name$,0)==" " || charat(.@name$,getstrlen(.@name$)-1)==" ") {
mes "You can not put a space at the beginning or end of your name";
close;
}

  • Upvote 2
Posted

Hmm try a compare command

 if(compare(.@name$," "+.@name$) == 1) {
mes "You can't use a space at the beginning of your new name.";
close;
}

Something lke this. Untested o.o > Scratch :I

Regards,

Chris

Posted

Compare() can do this too (but not with ||chris|| method):

if ( compare( "x1" + .@name$, "x1 " ) || compare( .@name$ + "x1", " x1" ) ) {
mes "You can not put a space at the beginning or end of your name";
close;
}

Posted

Compare() can do this too (but not with ||chris|| method):

if ( compare( "x1" + .@name$, "x1 " ) || compare( .@name$ + "x1", " x1" ) ) {
mes "You can not put a space at the beginning or end of your name";
close;
}

@Off-Topic: My name contains 2 small L o.o each.

@Topic: What is x1 ;)?

Posted

Spaces are easy, enters are the worst prob.

In case you don't see why try this:



XX

Yes, copy with the 2 enters and make a char with the pasted text lol It will bypass the 4 chars limit because it has in fact 4 but you will only see 2 =p

Abusing this fact will just make some people go nuts trying to check how the heck is the nick typed when combo'd with other stuff.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...