PM system
#1

Hello,

I'm working on my gamemode and this time a PM system (Private Message)

It gives me the error that the player is not online.. but the player is ALWAYS online when I try.
After the messange is senden I like to save it in my MySQL database.
pawn Code:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid)) // Checks if the Player IS connected
    {
        new pID, Message[60], username[MAX_PLAYER_NAME], targetName[MAX_PLAYER_NAME], string[128], string2[128], query[600];
        if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, COLOR_GOLD, "[REDMIN] PM Error: /pm <playerID or playername> <message>");
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GOLD, "[REDMIN]PM Error: Invalid Player");
        if(PMEnabled == 0) return SendClientMessage(playerid, 0xAFAFAFAA, "PM Is Disabled");
        GetPlayerName(pID, targetName, sizeof(targetName));
        GetPlayerName(playerid, username, sizeof(username));
        format(string, sizeof(string), "PM from %s: %s", username, Message);
        format(string2, sizeof(string2), "PM sent to %s: %s", targetName, Message);
        SendClientMessage(playerid, COLOR_GOLD, string2);
        SendClientMessage(pID, COLOR_GOLD, string);
        new timestamp = gettime()
        format(query, sizeof(query), "INSERT INTO pms (id, sender, reciever, date, message) VALUES ('', '%s', '%s', '%s', '%s')", playerid, pID, timestamp, Message);
        mysql_query(query);
    }
    return 1;
}
The problem:
* Invalid player

Who knows the problem?
Reply
#2

pawn Code:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid)) // Checks if the Player IS connected
    {
        new pID, Message[60], username[MAX_PLAYER_NAME],
            targetName[MAX_PLAYER_NAME], string[128],
            query[600];
        if(!sscanf(params, "us[60]", pID, Message))
        {
            if(pID != INVALID_PLAYER_ID)
            {
                if(PMEnabled == 1)
                {
                    GetPlayerName(pID, targetName, sizeof(targetName));
                    GetPlayerName(playerid, username, sizeof(username));
                    format(string, sizeof(string), "PM from %s: %s", username, Message);
                    format(string2, sizeof(string2), "PM sent to %s: %s", targetName, Message);
                    SendClientMessage(playerid, COLOR_GOLD, string2);
                    SendClientMessage(pID, COLOR_GOLD, string);
                    new timestamp = gettime()
                    format(query, sizeof(query), "INSERT INTO pms (id, sender, reciever, date, message) VALUES ('', '%s', '%s', '%s', '%s')", playerid, pID, timestamp, Message);
                    mysql_query(query);
                }
                else return SendClientMessage(playerid, 0xAFAFAFAA, "PM Is Disabled");
            }
            else return SendClientMessage(playerid, COLOR_GOLD, "[REDMIN]PM Error: Invalid Player");
        }
        else return SendClientMessage(playerid, COLOR_GOLD, "[REDMIN] PM Error: /pm <playerID or playername> <message>");
    }
    return 1;
}
Copy that and try it, maybe it would work. If it didn't, tell me the problem, if it did work great, looking forward your +rep.
Reply
#3

Why would you like to check if the player that is executing the command is online?
Reply
#4

Quote:
Originally Posted by AlonzoTorres
View Post
Why would you like to check if the player that is executing the command is online?
I need to know `Is the ID (player) available to forward an PM`.




Code didn't work #above
Reply
#5

Quote:
Originally Posted by AlonzoTorres
View Post
Why would you like to check if the player that is executing the command is online?
lol yeah!
The player has to be connected if he has to use the command. xD

You could use my script if you want, works!
Code:
COMMAND:pm(playerid,params[])
{
	static id,msg[112],string[128];
	if(sscanf(params,"us[112]",id,msg))
	{
	    return SendClientMessage(playerid,COLOR_GREY,"Usage:/pm [Name/ID] [Message]");
	}
	if(id == playerid)
	    return SendClientMessage(playerid,COLOR_RED,"/pm>>You cannot send a private message to yourself.");
	if (id == INVALID_PLAYER_ID)
		return SendClientMessage(playerid,COLOR_RED,"/pm>>Please give a valid player id/name.");
	if (PlayerAC[id][Alive])
		return SendClientMessage(playerid,COLOR_RED,"/pm>>Player cannot recieve private messages while he isen't spawned.");
    if(PlayerData[id][DoNotRecievePMs])
	    return SendClientMessage(playerid,COLOR_RED,"/pm>>Player has disabled private messages for this session.");
    if(PlayerData[playerid][IgnorePM][id>>5] & (1<<(id & 31)))
        return SendClientMessage(playerid,COLOR_RED,"/pm>>The player is ignoring you.");
	PlayerData[id][LastPMSentBy] = playerid;
	format(msg,sizeof(string),"PM from %s(%d):%s",PlayerData[playerid][Name],playerid,msg);
	SendClientMessage(id,COLOR_YELLOW,string);
	SendClientMessage(id,COLOR_YELLOW,"/reply OR /r for quick reply");
	format(msg,sizeof(string),"PM to %s(%d):%s",PlayerData[id][Name],id,msg);
	SendClientMessage(playerid,COLOR_YELLOW,string);
	return 1;
}
COMMAND:reply(playerid,params[])
{
	static id,msg[112];
	if(sscanf(params,"s[112]",msg))
	{
	    return SendClientMessage(playerid,COLOR_GREY,"Usage:/reply [Message]");
	}
	id = PlayerData[id][LastPMSentBy];
	if (id == INVALID_PLAYER_ID)
		return SendClientMessage(playerid,COLOR_RED,"/reply>>The player has logged out.");
	if (PlayerAC[id][Alive])
		return SendClientMessage(playerid,COLOR_RED,"/reply>>Player cannot recieve private messages while he hasn't spawned yet.");
	if(PlayerData[id][DoNotRecievePMs])
	    return SendClientMessage(playerid,COLOR_RED,"/reply>>Player has disabled private messages for this session.");
    if(PlayerData[playerid][IgnorePM][id>>5] & (1<<(id & 31)))
        return SendClientMessage(playerid,COLOR_RED,"/reply>>The player is ignoring you.");
    if(PlayerData[id][LastPMSentBy] == -1)
		return SendClientMessage(playerid,COLOR_RED,"/r>>You've not recieved any recent private message to use quick reply.");
	PlayerData[id][LastPMSentBy] = playerid;
	format(msg,sizeof(msg),"PM from %s(%d):%s",PlayerData[playerid][Name],playerid,msg);
	SendClientMessage(id,COLOR_YELLOW,msg);
	SendClientMessage(id,COLOR_YELLOW,"/reply OR /r for quick reply");
	format(msg,sizeof(msg),"PM to %s(%d):%s",PlayerData[id][Name],id,msg);
	SendClientMessage(playerid,COLOR_YELLOW,msg);
	return 1;
}
COMMAND:r(playerid,params[])
{
	static id,msg[112];
	if(sscanf(params,"s[112]",msg))
	{
	    return SendClientMessage(playerid,COLOR_GREY,"Usage:/r [Message]");
	}
	id = PlayerData[id][LastPMSentBy];
	if (id == INVALID_PLAYER_ID)
		return SendClientMessage(playerid,COLOR_RED,"/r>>The player has logged out.");
	if (PlayerAC[id][Alive])
		return SendClientMessage(playerid,COLOR_RED,"/r>>Player cannot recieve private messages while he hasn't spawned yet.");
    if(PlayerData[id][DoNotRecievePMs])
	    return SendClientMessage(playerid,COLOR_RED,"/r>>Player has disabled private messages for this session.");
    if(PlayerData[playerid][IgnorePM][id>>5] & (1<<(id & 31)))
        return SendClientMessage(playerid,COLOR_RED,"/r>>The player is ignoring you.");
    if(PlayerData[id][LastPMSentBy] == -1)
		return SendClientMessage(playerid,COLOR_RED,"/r>>You've not recieved any recent private message to use quick reply.");
	PlayerData[id][LastPMSentBy] = playerid;
	format(msg,sizeof(msg),"PM from %s(%d):%s",PlayerData[playerid][Name],playerid,msg);
	SendClientMessage(id,COLOR_YELLOW,msg);
	SendClientMessage(id,COLOR_YELLOW,"/reply OR /r for quick reply");
	format(msg,sizeof(msg),"PM to %s(%d):%s",PlayerData[id][Name],id,msg);
	SendClientMessage(playerid,COLOR_YELLOW,msg);
	return 1;
}
COMMAND:togglepm(playerid,params[])
{
	switch((PlayerData[playerid][DoNotRecievePMs] = !PlayerData[playerid][DoNotRecievePMs]))
	{
	    case true:
	    {
	       	return SendClientMessage(playerid,COLOR_YELLOW,"You've has disabled private messages./togglepm to enable them.");
	    }
	    case false:
	    {
	       	return SendClientMessage(playerid,COLOR_YELLOW,"You've has enabled private messages./togglepm to disable them.");
	    }
	}
	return 1;
}
COMMAND:ignore(playerid,params[])
{
	new id,msg[98+MAX_PLAYER_NAME];
	if(sscanf(params,"u",id))
	{
	    return SendClientMessage(playerid,COLOR_GREY,"Usage>>/ignore [Name/ID]");
	}
	if(id == INVALID_PLAYER_ID)
	    return SendClientMessage(playerid,COLOR_RED,"/ignore:Invalid Player");
	if(id == playerid)
	    return SendClientMessage(playerid,COLOR_RED,"/ignore:You cannot ignore yourself.");
	    
	switch(!!(PlayerData[playerid][IgnorePM][id>>5] ^= 1 << (id & 31)))
	{
		case true:
	    {
	        format(msg,sizeof(msg),"You are ignoring %s(%d)'s private messages./ignore [Name/ID] to stop ignoring.",PlayerData[id][Name],id);
	       	return SendClientMessage(playerid,COLOR_YELLOW,msg);
	    }
	    case false:
	    {
	        format(msg,sizeof(msg),"You are stopped ignoring %s(%d)'s private messages./ignore [Name/ID] to ignore private messages.",PlayerData[id][Name],id);
	       	return SendClientMessage(playerid,COLOR_YELLOW,msg);
	    }
	}
	return 1;
}
Reply
#6

Quote:
Originally Posted by Yashas
View Post
lol yeah!
The player has to be connected if he has to use the command. xD
My WEAK English .
No, but for example, I send id 14 an PM, but the users doesn't exist because there is no one with ID 14 then you would to see that as an error.. I'm right?!
Reply
#7

No we were talking about IsPlayerConnected(playerid) at the beginning.If a player has to send a command he has to be connected.

Code:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid)) // This line
Reply
#8

Quote:
Originally Posted by Yashas
View Post
No we were talking about IsPlayerConnected(playerid) at the beginning.If a player has to send a command he has to be connected.

Code:
CMD:pm(playerid, params[])
{
    if(IsPlayerConnected(playerid)) // This line
Yes, but it ALWAYS returns false (0).
And I want to check if the reciever online is.
Reply
#9

Then check if the receiver is online aka the targetid. At the moment you're checking if the SENDER is online, which he has to be to execute the command.
Reply
#10

that code checks if the sends is online and the sender obviously has to been online if he uses /pm.
Remove that first IsPlayerConnected, its useless.

sscanf returns INVALID_PLAYER_ID if the player is not connected.Your code seems to be doing it.I can't get why your code tells player not connected.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)