AFK And SetName Command
#1

The code works fine but it wont change the players name to '[AFK] <name>' it just says there away and leaves the name as it was:

pawn Код:
if(strcmp("/afk",cmdtext,true)==0)
{
  if(!IsPlayerConnected(playerid)) return SysMsg(playerid,"Please wait until you are fully connected!");       
    if(IsAFK[playerid] == 0)
    {
        format(string,sizeof(string),"[AFK] %s",Name(playerid));
        SetPlayerName(playerid,string);
        IsAFK[playerid] = 1;
        format(string,sizeof(string),"%s is now Away From Keyboard (AFK)",Name(playerid));
        SendClientMessageToAll(COLOUR_GREEN,string);
        printf("[Cmd] %s Is Now AFK",Name(playerid));
         
        }else{
           
        new nName[256],nFile[128];
        nFile = GetPlayersFile(playerid);
        nName = dini_Get(File,"Account Name");
        SetPlayerName(playerid,nName);
        format(string,sizeof(string),"%s is no longer Away From Keyboard (AFK)",Name(playerid));
        SendClientMessageToAll(COLOUR_GREEN,string);
        IsAFK[playerid] = 0;
        printf("[Cmd] %s Is No Longer AFK",Name(playerid));
    }      
    return 1;
}
Reply
#2

Try with no space.
Reply
#3

Or
Код:
"[AFK]_%s"
Reply
#4

Ok now it will change the name to [AFK] but when i try to /afk again to remove the [AFK] it says that samp-server.exe has crashed?
Reply
#5

Ok no problem its fixed, i just added 'UserName[MAX_PLAYERS][24]' instead of using dini to get the name:

OnPlayerConnect: UserName[playerid] = Name(playerid);

pawn Код:
if(strcmp("/afk",cmdtext,true)==0)
    {
        if(!IsPlayerConnected(playerid)) return SysMsg(playerid,"Please wait until you are fully connected!");
       
        //SysMsg(playerid,"Currently Disabled.");

        if(IsAFK[playerid] == 0)
        {
          format(string,sizeof(string),"%s is now Away From Keyboard (AFK)",Name(playerid));
          SendClientMessageToAll(COLOUR_GREEN,string);
            format(string,sizeof(string),"[AFK]%s",Name(playerid));
            SetPlayerName(playerid,string);
          IsAFK[playerid] = 1;
          printf("[Cmd] %s Is Now AFK",Name(playerid));
         
            }else{

            SetPlayerName(playerid,UserName[playerid]);
          format(string,sizeof(string),"%s is no longer Away From Keyboard (AFK)",Name(playerid));
          SendClientMessageToAll(COLOUR_GREEN,string);
          IsAFK[playerid] = 0;
          printf("[Cmd] %s Is No Longer AFK",Name(playerid));
        }
       
        return 1;
    }
Reply
#6

Waste of memory, just delete the first 5 characters of the name.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)