16.10.2012, 19:10
How can i make that Admins can change In game the Playername of a player?
CMD:setname(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
new id, name[24], str[130], newname;
if(sscanf(params, "udd", id,name,newname)) return SendClientMessage(playerid,red,"/SetName [Playerid/Name] [New Name]");
GetPlayerName(id,name,24);
format(str,130,"You Changed %s (%d)'s Name to $%d",name,id,newname);
SendClientMessage(playerid,lightblue,str);
format(str,130, "Admin Changed Your Name to $%d",newname);
SendClientMessage(playerid,lightblue,str);
SetPlayerName(id,name);
PlayerInfo[id][pAdminLevel] = name; // if caused an error check your player info
} else return SendClientMessage(playerid,red,"Your are not autorised to use this cmd);
return 1;
}
CMD:renameaccount(playerid,params[])
{
new oldname[128], newname[128], string[90];
if(sscanf(params,"s[128]s[128]", oldname, newname)) return SendClientMessage(playerid,Yellow, "Correct Usage: /renameaccount [OldName][New name]");
new filestring[128];
new filestring2[128];
format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
if(!fexist(filestring2)) return SendClientMessage(playerid, Yellow, "That account name doesn't exist!");
format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
if(fexist(filestring)) return SendClientMessage(playerid, Yellow, "The new name you've chosen is already taken");
frename(filestring2, filestring);
new INI:File = INI_Open(filestring);
INI_SetTag(File, "data");
INI_WriteString(File,"Name", newname);
INI_Close(File);
format(string, sizeof(string), "You have successfully renamed %s's account to %s" ,oldname, newname);
SendClientMessage(playerid, Lime, string);
return 1;
}
CMD:changename(playerid, params[]) { if(PlayerInfo[playerid][LoggedIn] == 1) { if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: /changename [new Name]"); if(strlen(params) < 4) return SendClientMessage(playerid,red,"ACCOUNT: Incorrect password length"); if (udb_Exists(params)) return SendClientMessage(playerid,red,"This User Name Is Taken!"); if(GetPlayerMoney(playerid) < 50000) return SendClientMessage(playerid, red,"[ERROR]: You need $50000 to change your name!"); new nameee[24]; GetPlayerName(playerid, nameee, 16); new OldName[24],str[128]; GetPlayerName(playerid,OldName,sizeof(OldName)); format(str,sizeof(str),"ladmin/users/%s.sav",OldName); udb_RenameUser(OldName,params); format(str,sizeof(str),"ladmin/users/%s.sav",params); SetPlayerName(playerid,params); PlayerPlaySound(playerid,1057,0.0,0.0,0.0); GivePlayerMoney(playerid, -50000); new string[128]; format(string, sizeof(string),"ACCOUNT: You have successfully changed your Name to \"%s\"",params); return SendClientMessage(playerid,yellow,string); } else return SendClientMessage(playerid,red, "ERROR: You must have an account to use this command"); }
Above is for Y_ini
there goes for Dini Code:
CMD:changename(playerid, params[]) { if(PlayerInfo[playerid][LoggedIn] == 1) { if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: /changename [new Name]"); if(strlen(params) < 4) return SendClientMessage(playerid,red,"ACCOUNT: Incorrect password length"); if (udb_Exists(params)) return SendClientMessage(playerid,red,"This User Name Is Taken!"); if(GetPlayerMoney(playerid) < 50000) return SendClientMessage(playerid, red,"[ERROR]: You need $50000 to change your name!"); new nameee[24]; GetPlayerName(playerid, nameee, 16); new OldName[24],str[128]; GetPlayerName(playerid,OldName,sizeof(OldName)); format(str,sizeof(str),"ladmin/users/%s.sav",OldName); udb_RenameUser(OldName,params); format(str,sizeof(str),"ladmin/users/%s.sav",params); SetPlayerName(playerid,params); PlayerPlaySound(playerid,1057,0.0,0.0,0.0); GivePlayerMoney(playerid, -50000); new string[128]; format(string, sizeof(string),"ACCOUNT: You have successfully changed your Name to \"%s\"",params); return SendClientMessage(playerid,yellow,string); } else return SendClientMessage(playerid,red, "ERROR: You must have an account to use this command"); } |