SA-MP Forums Archive
PM problem - 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: PM problem (/showthread.php?tid=319961)



PM problem - Max_Coldheart - 21.02.2012

pawn Код:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new pID, Message[60], SenderName[MAX_PLAYER_NAME], RecieverName[MAX_PLAYER_NAME], string[128], string2[128];
        if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, COLOR_ORANGE, "SYNTAX: /pm [PlayerID/PlayerName] [Message]");
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid Player");
        if(PMEnabled == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
        GetPlayerName(pID, RecieverName, sizeof(RecieverName));
        GetPlayerName(playerid, SenderName, sizeof(SenderName));
        format(string, sizeof(string), "Private message from %s: %s", SenderName, Message);
        format(string2, sizeof(string2), "Private message to %s: %s", RecieverName, Message);
        PMLog(string2);
        PMLog(string);
    }
    return 1;
}
So this is my PM code. The problem is that it isn't sending the PM. Everything works fine without parameters, but when I input parameters, it doesn't do anything.

pawn Код:
new PMEnabled = 1;
Yes, PMEnabled is set to 1.


Re: PM problem - YoungWildFree - 21.02.2012

Doesn't look like anything is wrong but it seems that it doesn't work you say? O.o


Re: PM problem - ReneG - 21.02.2012

Umm, maybe it's not sending because no where in your command are you SendClientMessage'ing the strings.


Re: PM problem - Max_Coldheart - 21.02.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Umm, maybe it's not sending because no where in your command are you SendClientMessage'ing the strings.
shit I forgot to add those
Well, everyone makes mistakes. Thanks man.


Re: PM problem - chrism11 - 21.02.2012

show us the PMLog() function


Re: PM problem - ReneG - 21.02.2012

Quote:
Originally Posted by CookieJar
Посмотреть сообщение
shit I forgot to add those
Well, everyone makes mistakes. Thanks man.
Lmao, simple mistake.


Re: PM problem - Max_Coldheart - 21.02.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Lmao, simple mistake.
I guess I'm getting tired as it's 5 AM here.


Re: PM problem - JhnzRep - 21.02.2012

pawn Код:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new pID, Message[60], SenderName[MAX_PLAYER_NAME], RecieverName[MAX_PLAYER_NAME], string[128], string2[128];
        if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, COLOR_ORANGE, "SYNTAX: /pm [PlayerID/PlayerName] [Message]");
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid Player");
        if(PMEnabled == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
        GetPlayerName(pID, RecieverName, sizeof(RecieverName));
        GetPlayerName(playerid, SenderName, sizeof(SenderName));
        format(string, sizeof(string), "Private message from %s: %s", SenderName, Message);
        format(string2, sizeof(string2), "Private message to %s: %s", RecieverName, Message);
        PMLog(string2);
        PMLog(string);
        SendClientMessage(playerid, -1, string2);
        SendClientMessage(pID, -1, string);
    }
    return 1;
}
EDIT: I guess you got it


Re: PM problem - ReneG - 21.02.2012

One more thing to consider. You might wanna change
Код:
new PMEnabled = 1;
to a MAX_PLAYERS array
Код:
new PMEnabled[MAX_PLAYERS] = 1;
Because the one you have currently is setting the variable for ALL players, and one player would be able to toggle it for ALL the players online. So I'm assuming you have a togpm command, your toggle pm command should look like this.
pawn Код:
CMD:togpm(playerid,params[])
{
    if(PMEnabled[playerid] == 1)
    {
        PMEnabled = 0;
        SendClientMessage(playerid,color,"PM disabled.");
        return 1;
    }
    else if(PMEnabled[playerid] == 0)
    {
       PMEnabled = 1;
       SendClientMessage(playerid,color,"PM enabled.");
       return 1;
    }
    return 1;
}
and your PM command should look like this.
pawn Код:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new pID, Message[60], SenderName[MAX_PLAYER_NAME], RecieverName[MAX_PLAYER_NAME], string[128], string2[128];
        if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, COLOR_ORANGE, "SYNTAX: /pm [PlayerID/PlayerName] [Message]");
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid Player");
        if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
        GetPlayerName(pID, RecieverName, sizeof(RecieverName));
        GetPlayerName(playerid, SenderName, sizeof(SenderName));
        format(string, sizeof(string), "Private message from %s: %s", SenderName, Message);
        format(string2, sizeof(string2), "Private message to %s: %s", RecieverName, Message);
        PMLog(string2);
        PMLog(string);
        SendClientMessage(playerid, -1, string2);
        SendClientMessage(pID, -1, string);
    }
    return 1;
}
The change I made was this
pawn Код:
if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
notice the [playerid]? So this small change would make your PM command more efficient in a user-interface way.


Re: PM problem - JhnzRep - 21.02.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
One more thing to consider. You might wanna change
Код:
new PMEnabled = 1;
to a MAX_PLAYERS array
Код:
new PMEnabled[MAX_PLAYERS] = 1;
Because the one you have currently is setting the variable for ALL players, and one player would be able to toggle it for ALL the players online. So I'm assuming you have a togpm command, your toggle pm command should look like this.
pawn Код:
CMD:togpm(playerid,params[])
{
    if(PMEnabled[playerid] == 1)
    {
        PMEnabled = 0;
        SendClientMessage(playerid,color,"PM disabled.");
        return 1;
    }
    else if(PMEnabled[playerid] == 0)
    {
       PMEnabled = 1;
       SendClientMessage(playerid,color,"PM enabled.");
       return 1;
    }
    return 1;
}
and your PM command should look like this.
pawn Код:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new pID, Message[60], SenderName[MAX_PLAYER_NAME], RecieverName[MAX_PLAYER_NAME], string[128], string2[128];
        if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, COLOR_ORANGE, "SYNTAX: /pm [PlayerID/PlayerName] [Message]");
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid Player");
        if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
        GetPlayerName(pID, RecieverName, sizeof(RecieverName));
        GetPlayerName(playerid, SenderName, sizeof(SenderName));
        format(string, sizeof(string), "Private message from %s: %s", SenderName, Message);
        format(string2, sizeof(string2), "Private message to %s: %s", RecieverName, Message);
        PMLog(string2);
        PMLog(string);
        SendClientMessage(playerid, -1, string2);
        SendClientMessage(pID, -1, string);
    }
    return 1;
}
The change I made was this
pawn Код:
if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
notice the [playerid]? So this small change would make your PM command more efficient in a user-interface way.
True, but he might want a global /togpm command for admins.