SA-MP Forums Archive
Quick reply to PM's - 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: Quick reply to PM's (/showthread.php?tid=550726)



Quick reply to PM's - FunnyBear - 14.12.2014

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


Re: Quick reply to PM's - Abagail - 14.12.2014

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.


Re: Quick reply to PM's - Lordzy - 14.12.2014

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;
}