27.07.2011, 09:26
Hello
In this dialog by Mo3 theres a problem. if u insert a bad ID or the player isnt connected it sends the message too
Do u know how to restrict to send the PM is the ID is invalid or the player isnt connected?
In this dialog by Mo3 theres a problem. if u insert a bad ID or the player isnt connected it sends the message too
Do u know how to restrict to send the PM is the ID is invalid or the player isnt connected?
pawn Код:
/*
This dialog PM system has been developed by Mo3.
Please keep these credits.
*/
#include <a_samp>
new ReceiverID[MAX_PLAYERS];
new PMfrom[MAX_PLAYERS];
new reply[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
reply[playerid] = 0;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/pm", true))
{
ShowPlayerDialog(playerid,755,DIALOG_STYLE_INPUT,"Private Message System","Enter the receiverґs ID","Done","Cancel");
return 1;
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new s1[264],s2[264],name[24];
if(dialogid == 755)
{
ReceiverID[playerid] = strval(inputtext);
ShowPlayerDialog(playerid,756,DIALOG_STYLE_INPUT,"Private Message System","Enter the text you want to send:","Send","Cancel");
return 1;
}
if(dialogid == 756)
{
if(response == 1)
{
if(reply[playerid] == 0)
{
PMfrom[ReceiverID[playerid]] = playerid;
GetPlayerName(playerid, name, sizeof(name));
format(s1, sizeof(s1), "You have received a new PM from %s\n\n%s",name,inputtext);
format(s2, sizeof(s2), "New PM from %s (%d)",name,playerid);
ShowPlayerDialog(ReceiverID[playerid],757,DIALOG_STYLE_MSGBOX,s2,s1,"Reply","Close");
PlayerPlaySound(ReceiverID[playerid], 1052, 0.0, 0.0, 0.0);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
}
else if(reply[playerid] == 1)
{
PMfrom[ReceiverID[playerid]] = playerid;
GetPlayerName(playerid, name, sizeof(name));
format(s1, sizeof(s1), "You have received a new PM from %s\n\n%s",name,inputtext);
format(s2, sizeof(s2), "New PM from %s (%d)",name,playerid);
ShowPlayerDialog(PMfrom[playerid],757,DIALOG_STYLE_MSGBOX,s2,s1,"Reply","Close");
reply[playerid] = 0;
PlayerPlaySound(PMfrom[playerid], 1052, 0.0, 0.0, 0.0);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
}
}
return 1;
}
if(dialogid == 757)
{
if(response == 1)
{
ShowPlayerDialog(playerid,756,DIALOG_STYLE_INPUT,"Private Message System","Enter the text you want to send:","Done","Cancel");
reply[playerid] = 1;
return 1;
}
}
return 0;
}
stock GetPlayerID(const Name[])
{
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(i, pName, sizeof(pName));
if(strcmp(Name, pName, true)==0)
{
return i;
}
}
}
return -1;
}