SA-MP Forums Archive
Temporary Name - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Temporary Name (/showthread.php?tid=403757)



Temporary Name - Xlithan - 31.12.2012

When the player goes on admin duty, I want their name to change to something temporary.

I've added AdminName and NormalName variables into the user file. I've got the admin duty command but the server crashes when it tries to change the players name.

Here's my code:
Код:
CMD:aduty(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playerid, -1, "This is an admin only command!");
	if(PlayerInfo[playerid][pAdminDuty] == 0)
	{

		SendClientMessageEx(playerid, COLOR_YELLOW, "You are now on administrative duty! Remember to check /reports!");
		if(strlen(PlayerInfo[playerid][pAdminName]) > 0)
		{
			SetPlayerName(playerid, PlayerInfo[playerid][pAdminName]);
		}
		PlayerInfo[playerid][pAdminDuty] = 1;
		SetPlayerHealth(playerid, 1000);
		SetPlayerArmour(playerid, 1000);
		//SetPlayerSkin(playerid, 294);
		new string[128];
		format(string, sizeof(string), "Administrator %s is now on Admin Duty! (/report for assistance)", GetPlayerNameEx(playerid));
		SendClientMessageToAllEx(COLOR_YELLOW, string);
	}
	else
	{
			SendClientMessageEx(playerid, COLOR_RED, "You are now off admin duty!");
			SetPlayerName(playerid, PlayerInfo[playerid][pNormalName]);
			SetPlayerHealth(playerid, 100);
			SetPlayerArmour(playerid, 100);
			//SetPlayerSkin(playerid, 299);
			PlayerInfo[playerid][pAdminDuty] = 0;
	}
    return 1;
}



Re: Temporary Name - Xlithan - 03.01.2013

bump


Re: Temporary Name - Flyfishes - 03.01.2013

Код:
if(strlen(PlayerInfo[playerid][pAdminName]) > 0)
		{
.. should be ..
Код:
if(PlayerInfo[playerid][pAdminName][0] == EOS )
		{
.. I guess.


Re: Temporary Name - Xlithan - 07.01.2013

Unfortunately did not solve the problem.


Re: Temporary Name - zSuYaNw - 07.01.2013

use this:
pawn Код:
#define GetPlayerTemporaryName(%0) Temporary[%0]
#define SetPlayerTemporaryName(%0,%1) format(Temporary[%0], 24, %1)
#define IsPlayerHaveTempName(%0)  Temporary[%0] != '\0'


new Temporary[ MAX_PLAYERS ] [ 24 ];


// OnPlayerConnect:
Temporary[playerid] = '\0';



pawn Код:
// Getting player temporary name
        new name[24]; GetPlayerName(playerid, name, 24);
        SetPlayerTemporaryName(playerid, name);
       

// set player name
        SetPlayerName(playerid, "Other Name");
       

// Set player old name
        SetPlayerName(playerid, GetPlayerTemporaryName(playerid));



Re: Temporary Name - fanta291327 - 07.01.2013

Yes i did the same thing in my old server and did as garfiel said to fix it so that should solve the problem so make sure you say "Thx" to garfield


Re: Temporary Name - Xlithan - 07.01.2013

Actually, the problem is that it's not loading the data of AdminName and NormalName from the user file.

It saves them just fine, but doesn't load them when the player logs in. So it's trying to set the name as a null string, in turn crashes the server.


Re: Temporary Name - Xlithan - 09.01.2013

bump?


Re: Temporary Name - u3ber - 09.01.2013

Quote:
Originally Posted by Xlithan
Посмотреть сообщение
bump?
code?


Re: Temporary Name - Xlithan - 10.01.2013

Код:
CMD:aduty(playerid, params[]) // Go on/off admin duty
{
	if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playerid, -1, "This is an admin only command!");
	new string[128];
	if(PlayerInfo[playerid][pAdminDuty] == 0)
	{

		SendClientMessageEx(playerid, COLOR_YELLOW, "You are now on administrative duty! Remember to check /reports!");
		// Change to admin name
		new name[MAX_PLAYER_NAME];
		format(name, MAX_PLAYER_NAME, PlayerInfo[playerid][pAdminName]);
		if(strlen(name) > 0)
		{
		    SetPVarInt(playerid, "TempName", 1);
			if(!doesAccountExist(name))
			{
			    format(string, sizeof(string), "Your name was changed to %s.", name);
				SendClientMessageEx(playerid, COLOR_YELLOW, string);
				SetPlayerName(playerid, name);
			}
			else
			{
			    SendClientMessageEx(playerid, COLOR_RED, "This name is already in use. Contact the Executive Director.");
			}
		}
		///////////////////////
		PlayerInfo[playerid][pAdminDuty] = 1;
		SetPlayerHealth(playerid, 10000);
		SetPlayerArmour(playerid, 10000);
		//SetPlayerSkin(playerid, 294);
		//new string[128];
	}
	else
	{
			SendClientMessageEx(playerid, COLOR_RED, "You are now off admin duty!");
            // Change to admin name
            if(GetPVarInt(playerid, "TempName") == 1)
            {
				new name[MAX_PLAYER_NAME];
				format(name, MAX_PLAYER_NAME, PlayerInfo[playerid][pNormalName]);
	      		SetPVarInt(playerid, "TempName", 0);
	      		if(strlen(name) == 0)
	      		{
					SendClientMessageEx(playerid, COLOR_YELLOW, "Name contained no characters.");
				}
				else
				{
		   			format(string, sizeof(string), "Your name was set back to %s.", name);
					SendClientMessageEx(playerid, COLOR_YELLOW, string);
					SetPlayerName(playerid, name);
				}
			}
			///////////////////////
			SetPlayerHealth(playerid, 100);
			SetPlayerArmour(playerid, 100);
			//SetPlayerSkin(playerid, 299);
			PlayerInfo[playerid][pAdminDuty] = 0;
	}
    return 1;
}