All pastes #790502 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-11-20 13:00 UTC
rendered paste body
frename(oldname[],newname[]) {
if (!fexist(oldname)) return true;
fremove(newname);
if(!fcopy(oldname,newname)) return true;
fremove(oldname); return true; }
	
fcopy(oldname[],newname[]) {
new File:ohnd,File:nhnd;
if (!fexist(oldname)) return true;
ohnd=fopen(oldname,io_read);
nhnd=fopen(newname,io_write);
new buf2[1]; new i; for (i=flength(ohnd);i>0;i--) {
fputchar(nhnd, fgetchar(ohnd, buf2[0],true),true); }
fclose(ohnd); fclose(nhnd); return true; }


	if(strcmp(cmd, "/setname", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /setname [playerid/PartOfName] [Name]");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			if (PlayerInfo[playerid][pAdmin] >= 1338)
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
			            new plname[MAX_PLAYER_NAME];
						GetPlayerName(playerid, plname, sizeof(plname));
						format(string, sizeof(string), "%s.ini", plname);
						if(fexist(plname))
						{
   							format(string, sizeof(string), "Warning: This Name is Availbe!",tmp);
							SendClientMessage(playerid, COLOR_GRAD1, string);
							format(string, sizeof(string), "Warning: You Changed Your Nick Name to %s!",tmp);
							SendClientMessage(playerid, COLOR_GRAD1, string);
							SetPlayerName(playa, tmp);
							new oldfile[256];
							new newfile[256];
							new plname2[256];
							GetPlayerName(playerid, plname2, 256);
							format(oldfile, 256, "%s.ini", plname2);
							format(newfile, 256, "%s.ini", tmp);
							frename(oldfile, newfile);
						}
						else
						{
							format(string, sizeof(string), "Warning: %s is already an existing name/user!",tmp);
							SendClientMessage(playerid, COLOR_GRAD1, string);
							format(string, sizeof(string), "Warning: This Nick Name is Not Availble!",tmp);
							SendClientMessage(playerid, COLOR_GRAD1, string);
							return 1;
						}

					}
				}
				else
				{
					format(string, sizeof(string), "   %d is not an active player.", giveplayerid);
					SendClientMessage(playerid, COLOR_GRAD1, string);
					return 1;
				}
			}
			else
			{
		   	 	SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
				return 1;
			}
		}
	}