PM problem
#1

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.
Reply
#2

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

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

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.
Reply
#5

show us the PMLog() function
Reply
#6

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

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

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
Reply
#9

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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)