Temporary Name
#1

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;
}
Reply
#2

bump
Reply
#3

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

Unfortunately did not solve the problem.
Reply
#5

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));
Reply
#6

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
Reply
#7

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.
Reply
#8

bump?
Reply
#9

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

Код:
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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)