Maybe someone have /changename command?
#1

Hello!
I tried find at ****** /changename command which change me name and save it. Bat it was not succeed find it at all
Reply
#2

below you can see similar threads!

https://sampforum.blast.hk/showthread.php?tid=521185
Reply
#3

I need this command without admin system. Like regular player can use it for him self.
Reply
#4

How about you try to learn to script it yourself? And No, I'm not just putting you in the middle of no where with this post. I'm just trying to say that it's actually very easy to script this cmd.
It'd be better if you'd actually try to script it yourself and after you've done it you could ask us to help you out!
Reply
#5

Quote:
Originally Posted by henkas
View Post
I need this command without admin system. Like regular player can use it for him self.
for a change, try it yourself.

first you think about what you want to do
-> i want to change a player name

then you ckeck your includes for stuff you'll be using for this
-> SetPlayerName, just what i needed

now you're finally ready to start, so you think about how to put your idea into code
-> so i'll be changing the name using SetPlayerName... gotta also do the same in the account file/db obviously
-> should also do error-checks using the return value of SetPlayerName e.g. if -1 then name already taken
-> hm... but that'll only check for the current(online) Player names, gotta also check every single account(offline), don't want any duplicates!
-> after checking for duplicates, i should also validate the new name... it shouldn't be longer than 24
-> it also better not contain any weird chars like '\' or '^', ill use strfind for that, or something fancier?

done, hope this rough explantation helped.


i mean you can't just come here every day,
ask for stuff and copy-paste. you won't learn anything from that.
The wiki, even though sometimes inaccurate & in some cases deprecated,
is a good place to research stuff & find what you need. Plus there's always the search function here
Reply
#6

PHP Code:
CMD:changename(playeridparams[])
{
    new  
string[126], oldname[126];
    if(
isnull(params)) return SendClientMessage(playeridCOLOR_GREEN"USAGE: /changename [new name]");
        
GetPlayerName(playeridoldnamesizeof(oldname));
    
SetPlayerName(playeridparams);
    
format(stringsizeof(string), "* You changed your name from %s to %s"oldnameparams);
    
SendClientMessage(playeridCOLOR_GREENstring);
    return 
1;

simple ^^
Reply
#7

Also you have to save it in server database!
Reply
#8

Quote:
Originally Posted by Yaa
View Post
PHP Code:
CMD:changename(playeridparams[])
{
    new  
string[126], oldname[126];
    if(
isnull(params)) return SendClientMessage(playeridCOLOR_GREEN"USAGE: /changename [new name]");
    
format(oldnamesizeof(oldname), "%s"GetPlayersName(playerid));
    
SetPlayerName(playeridparams);
    
format(stringsizeof(string), "* You changed your name from %s to %s"oldnameparams);
    
SendClientMessage(playeridCOLOR_GREENstring);
    return 
1;

simple ^^
Its doesn't change at all
Reply
#9

Quote:
Originally Posted by Yaa
View Post
PHP Code:
CMD:changename(playeridparams[])
{
    new  
string[126], oldname[126];
    if(
isnull(params)) return SendClientMessage(playeridCOLOR_GREEN"USAGE: /changename [new name]");
    
format(oldnamesizeof(oldname), "%s"GetPlayersName(playerid));
    
SetPlayerName(playeridparams);
    
format(stringsizeof(string), "* You changed your name from %s to %s"oldnameparams);
    
SendClientMessage(playeridCOLOR_GREENstring);
    return 
1;

simple ^^
GetPlayersName? I think you pulled it out of a gm haha, the stock is missing.
Reply
#10

Quote:
Originally Posted by BrianFaria
View Post
GetPlayersName? I think you pulled it out of a gm haha, the stock is missing.
Its not a big deal i made this stock by my self
Reply
#11

Quote:
Originally Posted by BrianFaria
View Post
GetPlayersName? I think you pulled it out of a gm haha, the stock is missing.
ops misktake.

fixed btw
Reply
#12

Well i find one bat its work very weird first of all its lets use that name if its have taken second bug its if i have created two account in me library Like Name And Name2 and i login as Name and type command /changename Test this system delete Name2 acc and create Test acc. Its so weird.
Code:
stock StripNewLine(string[])
{
	new len = strlen(string);
	if(string[0] == 0) return;
	if((string[len - 1] == '\n') || (string[len - 1] == '\r'))
	{
		string[len - 1] = 0;
		if(string[0]==0) return ;
		if((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
	}
}

stock frename(oldname[], newname[])
{
	if(!fexist(oldname)) return false;
	new string[128], File:old, File:neww;
	old = fopen(oldname, io_read);
	neww = fopen(newname, io_write);
	while(fread(old, string))
	{
		StripNewLine(string);
		format(string, sizeof(string), "%s\r\n", string);
		fwrite(neww, string);
	}
	fclose(old);
	fclose(neww);
	fremove(oldname);
	return true;
}
Code:
CMD:changename(playerid, params[])
{
    new newname[MAX_PLAYER_NAME], file1[128], file2[128];
    if(sscanf(params, "s[24]", newname)) return SendClientMessage(playerid, GREY, "Usage: /changename [New Username]");
    if(strlen(newname) < 3 || strlen(newname) > MAX_PLAYER_NAME) return SendClientMessage(playerid, GREY, "Invalid username length.");
    format(file2, sizeof(file2), "/Users/%s.ini", newname);
    if(fexist(file2)) return SendClientMessage(playerid, GREY, "The specified username is already taken.");
    format(file1, sizeof(file1), "/ZMA/Users/%s.ini", pName(playerid));
    format(file2, sizeof(file2), "/ZMA/Users/%s.ini", newname);
    frename(file1, file2);
    SetPlayerName(playerid, newname);
    format(file1, sizeof(file1), "You have changed your name to %s.", newname);
    SendClientMessage(playerid, COLOR_WHITE, file1);
    return 1;
}
Reply
#13

up up up
Reply
#14

PHP Code:
    CMD:changename(playeridparams[])
    {
        new 
name[24];
        new 
string[128];
        
        if(
sscanf("s[24]"name)) return SCM(playerid, -1"USAGE:/changename [Name]");
        
        
SetPlayerName(playeridname);
        
format(stringsizeof(string), "INFO: You changed your name to: %s"name);
        
SendClientMessage(playerid, -1string);
        return 
1;
    } 
Reply
#15

Quote:
Originally Posted by RayBiH
View Post
PHP Code:
    CMD:changename(playeridparams[])
    {
        new 
name[24];
        new 
string[128];
        
        if(
sscanf("s[24]"name)) return SCM(playerid, -1"USAGE:/changename [Name]");
        
        
SetPlayerName(playeridname);
        
format(stringsizeof(string), "INFO: You changed your name to: %s"name);
        
SendClientMessage(playerid, -1string);
        return 
1;
    } 
Command i have already its just bugged
Reply
#16

Quote:
Originally Posted by henkas
View Post
Command i have already its just bugged
How, give me your code.
Reply
#17

Well i find one bat its work very weird first of all its lets use that name if its have taken second bug its if i have created two account in me library Like Name And Name2 and i login as Name and type command /changename Test this system delete Name2 acc and create Test acc. Its so weird.
Code:
stock StripNewLine(string[])
{
new len = strlen(string);
if(string[0] == 0) return;
if((string[len - 1] == '\n') || (string[len - 1] == '\r'))
{
string[len - 1] = 0;
if(string[0]==0) return ;
if((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
}
}

stock frename(oldname[], newname[])
{
if(!fexist(oldname)) return false;
new string[128], Fileld, File:neww;
old = fopen(oldname, io_read);
neww = fopen(newname, io_write);
while(fread(old, string))
{
StripNewLine(string);
format(string, sizeof(string), "%s\r\n", string);
fwrite(neww, string);
}
fclose(old);
fclose(neww);
fremove(oldname);
return true;
}
Code:
CMD:changename(playerid, params[])
{
new newname[MAX_PLAYER_NAME], file1[128], file2[128];
if(sscanf(params, "s[24]", newname)) return SendClientMessage(playerid, GREY, "Usage: /changename [New Username]");
if(strlen(newname) < 3 || strlen(newname) > MAX_PLAYER_NAME) return SendClientMessage(playerid, GREY, "Invalid username length.");
format(file2, sizeof(file2), "/Users/%s.ini", newname);
if(fexist(file2)) return SendClientMessage(playerid, GREY, "The specified username is already taken.");
format(file1, sizeof(file1), "/ZMA/Users/%s.ini", pName(playerid));
format(file2, sizeof(file2), "/ZMA/Users/%s.ini", newname);
frename(file1, file2);
SetPlayerName(playerid, newname);
format(file1, sizeof(file1), "You have changed your name to %s.", newname);
SendClientMessage(playerid, COLOR_WHITE, file1);
return 1;
}
Reply
#18

up up up
Reply
#19

up up up
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)