AFK Help
#1

Hey guys. I try to fix this command - /afklist . When get typed the command i want to show the afk'ers.
But when i test it with my friend it shows the player's name. Example: Im Nork and my friend is Garry.
Garry goes afk and Nork type /afklist. But it says: Nork is afk. Actually he isn't.
Here is the AFK system.
pawn Код:
if (strcmp("/afk", cmdtext, true, 10) == 0)
    {
    if(AFK[playerid] == 0)
    {
    new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(string, 280, "%s has gone AFK.", pname);
    SendClientMessageToAll(COLOR_PINK, string);
    TogglePlayerControllable(playerid,0);
    AFK[playerid] = 1;
    }
    else return SendClientMessage(playerid, COLOR_RED, "ERROR: You are already AFK.");
    return 1;
    }
   
    if (strcmp("/back", cmdtext, true, 10) == 0)
    {
    if(AFK[playerid] == 1)
    {
    new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(string, 280, "%s is now back from being AFK.", pname);
    SendClientMessageToAll(COLOR_PINK, string);
    TogglePlayerControllable(playerid,1);
    AFK[playerid] = 0;
    }
    else return SendClientMessage(playerid, COLOR_RED, "ERROR: You aren't AFK.");
    return 1;
    }
And here is what i tried to build to create /afklist .
pawn Код:
if (strcmp("/afklist", cmdtext, true, 10) == 0)
    {
    new pString[MAX_PLAYER_NAME], pName3[MAX_PLAYER_NAME];
    for(new pID = 0; pID < MAX_PLAYERS; pID ++)
    {
    if(IsPlayerConnected(pID))
    {
    if(AFK[pID] == 1)
    {
    SendClientMessage(playerid, COLOR_CYAN, "==============================");
    SendClientMessage(playerid, COLOR_PURPLE, "AFK List:");
    GetPlayerName(playerid, pName3, sizeof(pName3));
    format(pString, sizeof(pString), "%s", pName3);
    SendClientMessage(playerid, COLOR_PINK, pString);
    SendClientMessage(playerid, COLOR_CYAN, "==============================");
    }
    }
    }
    return 1;
    }
+REP for the dude who help me.
Reply
#2

Let's debug a little

pawn Код:
if(!strcmp("/afklist", cmdtext, true, 10))
{
    for(new i = 0; i < MAX_PLAYERS; ++i) {
        printf("Player %d: status %d\n", i, AFK[i]);
    }
    return 1;
}
Run it and show what do you have in console

`e: I think this should do it

pawn Код:
if(!strcmp("/afklist", cmdtext, true, 10)) {
    new pString[MAX_PLAYER_NAME], pName3[MAX_PLAYER_NAME];
    SendClientMessage(playerid, COLOR_CYAN, "==============================");
    SendClientMessage(playerid, COLOR_PURPLE, "AFK List:");
    for(new pID = 0; pID < MAX_PLAYERS; pID ++)
    {
        if(IsPlayerConnected(pID) && AFK[pID] == 1) {
            GetPlayerName(pID, pName3, sizeof(pName3));
            format(pString, sizeof(pString), "%s", pName3);
            SendClientMessage(playerid, COLOR_PINK, pString);
        }
    }
    SendClientMessage(playerid, COLOR_CYAN, "==============================");
    return 1;
}
Reply
#3

I don't understand.
I need only to replace with my command? Or i need to paste your code anywhere in my command?
Reply
#4

Thanks Misiur. +REP for you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)