Quick reply to PM's
#1

Hey,

I've had a PM command for a while, and I found that it would be easier if people could reply to the last person who PM'd or the last person who they had PM'd. And if the last person who they PM'd had disconnected, it would tell them that the player has disconnect. And if they had not PM'd anyone or received any PM's it would say that there is no one to reply to. But I'm not sure how to make it. Here is my PM command,

pawn Код:
CMD:pm(playerid, params[])
{
    new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
    if(sscanf(params, "us", id, str2))
    {
        SendUsageError( playerid, "/pm [ID] [Message]" );
        return 1;
    }

    if( playerid == id )
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} You cannot send a PM to yourself!");

    if( id == INVALID_PLAYER_ID )
        return InvalidPlayerError(playerid);

    if( NOPM{ id } == true)
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} This person has turned off their PM's");

    GetPlayerName(playerid, Name1, sizeof(Name1));
    GetPlayerName(id, Name2, sizeof(Name2));
    format(str, sizeof(str), "PM sent to %s[%d]: %s", Name2, id, str2);
    SendClientMessage(playerid, 0xFFF700FF, str);
    format(str, sizeof(str), "PM from %s[%d]: %s", Name1, playerid, str2);
    SendClientMessage(id, 0xFFF700FF, str);
    return 1;
}
Thanks,

FunnyBear
Reply
#2

pawn Код:
new LastPMed[MAX_PLAYERS] = INVALID_PLAYER_ID;
CMD:pm(playerid, params[])
{
    new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
    if(sscanf(params, "us", id, str2))
    {
        SendUsageError( playerid, "/pm [ID] [Message]" );
        return 1;
    }

    if( playerid == id )
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} You cannot send a PM to yourself!");

    if( id == INVALID_PLAYER_ID )
        return InvalidPlayerError(playerid);

    if( NOPM{ id } == true)
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} This person has turned off their PM's");

    GetPlayerName(playerid, Name1, sizeof(Name1));
    GetPlayerName(id, Name2, sizeof(Name2));
    format(str, sizeof(str), "PM sent to %s[%d]: %s", Name2, id, str2);
    SendClientMessage(playerid, 0xFFF700FF, str);
    format(str, sizeof(str), "PM from %s[%d]: %s", Name1, playerid, str2);
    SendClientMessage(id, 0xFFF700FF, str);
    LastPMed[id] = playerid;
    return 1;
}

CMD:reply(playerid, params[])
{
    if(LastPMed[playerid] != INVALID_PLAYER_ID)
    {
        if(isnull(params)) return SendClientMessage(playerid, -1, "USAGE: /reply [text]");
        new id = LastPMed[playerid];
        new Name1[MAX_PLAYER_NAME];
        GetPlayerName(playerid, Name1, sizeof(Name1));
        format(str, sizeof(str), "PM from %s[%d]: %s", Name1, playerid, id);
        SendClientMessage(id, 0xFFF700FF, str);
        return 1;
    }
    else
    {
        SendClientMessage(playerid, -1, "No one has PMed you.");
        return 1;
    }
}
Your welcome.
Reply
#3

Using 256 cells is useless here, 144 would be pretty enough. If you're following Abagail's code, you have to either check if player is connected while replying or else set the array to INVALID_PLAYER_ID.

Based on the latter one;
pawn Код:
public OnPlayerDisconnect(playerid)
{
    for(new i = 0, j = GetMaxPlayers(); i< j; i++)
    {
        if(LastPMed[playerid] != i) continue;
        LastPMed[playerid] = INVALID_PLAYER_ID;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)