Hi, how can i create a private message system for my samp server like this:
1. If player type /pm in chat to show this dialog /pm command - http://www.imgx.ro/fullview.php?id=241038 dialog - http://www.imgx.ro/fullview.php?id=241039 2. else if player type /pm and player id or name in chat to show this: command - http://www.imgx.ro/fullview.php?id=241040 dialog - http://www.imgx.ro/fullview.php?id=241041 3. else if player type /pm and player and message the message will be sent successfully to player like this: command: - http://www.imgx.ro/fullview.php?id=241043 dialog - http://www.imgx.ro/fullview.php?id=241044 |
#define DIALOG_MESSAGE_PM 1234 #define DIALOG_MESSAGE_REPLY_PM 1235 new LastMessage[MAX_PLAYERS]; //This will remember the playerid who sended u the last message.
hook OnPlayerConnect(playerid) { LastMessage[playerid] = -1; return 1; } hook OnPlayerDisconnect(playerid) { LastMessage[playerid] = -1; return 1; }
forward SendDialogMessage(playerid, id, message[]); public SendDialogMessage(playerid, id, message[]) { new titleString[60]; new stringInfo[100]; format(titleString, sizeof(titleString), "New PM from %s (%d)", GetPlayerName(playerid), playerid); format(stringInfo, sizeof(stringInfo), "You have received a new PM from %s\n%s", GetPlayerName(playerid), message); ShowPlayerDialog(id, DIALOG_MESSAGE_PM, DIALOG_STYLE_MSGBOX, "titleString, stringInfo, "Reply", "Close"); LastMessage[id] = playerid; return 1; }
hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == DIALOG_MESSAGE_PM) { if(response) // If they clicked 'Reply' or pressed enter { ShowPlayerDialog(playerid, DIALOG_MESSAGE_REPLY_PM, DIALOG_STYLE_INPUT, "Replay PM", "Enter your message gere:", "Send Reply", "Close"); } return 1; } if(dialogid == DIALOG_MESSAGE_REPLY_PM) { if(response) // If they clicked 'Reply' or pressed enter { SendDialogMessage(playerid, LastMessage[playerid], inputtext); } return 1; } return 0; // You MUST return 0 here! Just like OnPlayerCommandText. }
You can make a function to show up the message in a dialog.
Ex: Код:
#define DIALOG_MESSAGE_PM 1234 #define DIALOG_MESSAGE_REPLY_PM 1235 new LastMessage[MAX_PLAYERS]; //This will remember the playerid who sended u the last message. Код:
hook OnPlayerConnect(playerid) { LastMessage[playerid] = -1; return 1; } hook OnPlayerDisconnect(playerid) { LastMessage[playerid] = -1; return 1; } Код:
forward SendDialogMessage(playerid, id, message[]); public SendDialogMessage(playerid, id, message[]) { new titleString[60]; new stringInfo[100]; format(titleString, sizeof(titleString), "New PM from %s (%d)", GetPlayerName(playerid), playerid); format(stringInfo, sizeof(stringInfo), "You have received a new PM from %s\n%s", GetPlayerName(playerid), message); ShowPlayerDialog(id, DIALOG_MESSAGE_PM, DIALOG_STYLE_MSGBOX, "titleString, stringInfo, "Reply", "Close"); LastMessage[id] = playerid; return 1; } Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == DIALOG_MESSAGE_PM) { if(response) // If they clicked 'Reply' or pressed enter { ShowPlayerDialog(playerid, DIALOG_MESSAGE_REPLY_PM, DIALOG_STYLE_INPUT, "Replay PM", "Enter your message gere:", "Send Reply", "Close"); } return 1; } if(dialogid == DIALOG_MESSAGE_REPLY_PM) { if(response) // If they clicked 'Reply' or pressed enter { new message = strlen(inputtext); SendDialogMessage(playerid, LastMessage[playerid], message); } return 1; } return 0; // You MUST return 0 here! Just like OnPlayerCommandText. } I didn't test the code, sorry if i wrong something |
CMD:pm(playerid, params[]) { if(IsPlayerAdmin(playerid)) //Check if is player admin { new id, message[150]; if(sscanf(params, "us[150]", id, message)) return SendClientMessage(playerid, COLOR_WHITE,"Usage: /pm [PlayerID] [Message]"); SendDialogMessage(playerid, id, message); } return 1; }
Код:
CMD:pm(playerid, params[]) { if(IsPlayerAdmin(playerid)) //Check if is player admin { new id, message[150]; if(sscanf(params, "us[150]", id, message)) return SendClientMessage(playerid, COLOR_WHITE,"Usage: /pm [PlayerID] [Message]"); SendDialogMessage(playerid, id, message); } return 1; } |
new message[150]; format(message, sizeof(message), "%s", inputtext);
SendDialogMessage(playerid, LastMessage[playerid], inputtext);