#include <zcmd>
#include <sscanf2>
new PMEnabled[MAX_PLAYER_NAME]; // Defnining PMEnabled with the MAX_PLAYER_NAME
public OnPlayerConnect(playerid)
{
PMEnabled[playerid] = 1; //Putting this will automatically toggles the connected player's PMs ON when he/she connects.
return 1;
}
CMD:pm(playerid, params [ ] ) // The command
{
if(IsPlayerConnected(playerid)) //This one checks if the player is connected to the server or not.
{
new pID, Message[60],playername[MAX_PLAYER_NAME],targetName[MAX_PLAYER_NAME],string[128],string2[128]; // defining the pID which will hold the Player's ID. Message will hold the message and playername will hold the name of the player that sends it, also target to the target
if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /pm [PlayerID/PlayerName] [Message]"); // Checks if the player has filed in both params if not it will return a error message with Color Grey
if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xAFAFAFAA, "Invalid Player"); // Checks if the player he attemps to send to is invalid if not it will send and error message
if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, 0xAFAFAFAA, "PM Is Disabled"); // This checks if the PMs are toggled off
GetPlayerName(pID, targetName, sizeof(targetName)); // Gets the Name of The Target 1st param and stores it in targetName
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "Private Message from %s: %s", playername, Message); // Will format the string the first %s is the name of the guy who sent pm second %s in the Message
format(string2, sizeof(string2), "Private Message sent to %s: %s", targetName, Message); // The same as above but this time it shows the name off the player you sent it to
SendClientMessage(playerid, 0xFFFF00AA, string2); // Sends a message to the player who sent the PM
SendClientMessage(pID, 0xFFFF00AA, string); // Sends a Message to Target
}
return 1; // Returns 1
}
CMD:togpm( playerid, params[ ] )
{
if(isnull(params)) return SendClientMessage(playerid, 0xFFFFFFFF, "CMD: /togpm [on/off]"); //If the player only types /togpm this message shows.
if(strcmp(params, "on", true ) == 0 )//This says if the player wrote "on"
{ //If he wrote "on" Do this:
PMEnabled[playerid] = 1; //Enables or unblocks Personal Messages to arrive.
SendClientMessage(playerid, 0x00FF00FF, "You have unblocked your Personal Messaging arrival."); //The messages that sends when the player toggled on/unblocked his PMs
}
else if( strcmp( params, "off", true ) == 0 ) // This one says, Else if the player types "off"
{ // If he wrote "off" Do this:
PMEnabled[playerid] = 0; //Disables or blocks Personal Messages from arriving.
SendClientMessage(playerid, 0xAA3333AA, "You have blocked Personal Messages from arriving."); //The message that sends when the player toggled off/blocked his PMs
}
else SendClientMessage(playerid, -1,"CMD: /togpm [on/off]"); //This one says like the first line, if the player only types /togpm, this message shows.
return 1;
}
/*
This tutorial was originally written by Guitar.
http://www.guitarhelping.weebly.com
http://www.sa-mp.com
Thank you for looking at my tutorials.
*/
#include <a_samp>
#include <zcmd>
#include <sscanf2>
new PMEnabled[MAX_PLAYER_NAME]; // Defnining PMEnabled with the MAX_PLAYER_NAME
public OnFilterScriptInit()
{
print("\n----------------------------------");
print(" Personal Messaging system has been loaded.");
print("----------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
print("\n----------------------------------");
print(" Personal Messaging system has been unloaded.");
print("----------------------------------\n");
return 1;
}
main()
{
print("\n----------------------------------");
print(" Guitar's tutorial on making a simple Personal Messages with blocking feature.");
print("----------------------------------\n");
}
CMD:pm(playerid, params [ ] ) // The command
{
if(IsPlayerConnected(playerid)) //This one checks if the player is connected to the server or not.
{
new pID, Message[60],playername[MAX_PLAYER_NAME],targetName[MAX_PLAYER_NAME],string[128],string2[128]; // defining the pID which will hold the Player's ID. Message will hold the message and playername will hold the name of the player that sends it, also target to the target
if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /pm [PlayerID/PlayerName] [Message]"); // Checks if the player has filed in both params if not it will return a error message with Color Grey
if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xAFAFAFAA, "Invalid Player"); // Checks if the player he attemps to send to is invalid if not it will send and error message
if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, 0xAFAFAFAA, "PM Is Disabled"); // This checks if the PMs are toggled off
GetPlayerName(pID, targetName, sizeof(targetName)); // Gets the Name of The Target 1st param and stores it in targetName
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "Private Message from %s: %s", playername, Message); // Will format the string the first %s is the name of the guy who sent pm second %s in the Message
format(string2, sizeof(string2), "Private Message sent to %s: %s", targetName, Message); // The same as above but this time it shows the name off the player you sent it to
SendClientMessage(playerid, 0xFFFF00AA, string2); // Sends a message to the player who sent the PM
SendClientMessage(pID, 0xFFFF00AA, string); // Sends a Message to Target
}
return 1; // Returns 1
}
CMD:togpm( playerid, params[ ] )
{
if(isnull(params)) return SendClientMessage(playerid, 0xFFFFFFFF, "CMD: /togpm [on/off]"); //If the player only types /togpm this message shows.
if(strcmp(params, "on", true ) == 0 )//This says if the player wrote "on"
{ //If he wrote "on" Do this:
PMEnabled[playerid] = 1; //Enables or unblocks Personal Messages to arrive.
SendClientMessage(playerid, 0x00FF00FF, "You have unblocked your Personal Messaging arrival."); //The messages that sends when the player toggled on/unblocked his PMs
}
else if( strcmp( params, "off", true ) == 0 ) // This one says, Else if the player types "off"
{ // If he wrote "off" Do this:
PMEnabled[playerid] = 0; //Disables or blocks Personal Messages from arriving.
SendClientMessage(playerid, 0xAA3333AA, "You have blocked Personal Messages from arriving."); //The message that sends when the player toggled off/blocked his PMs
}
else SendClientMessage(playerid, -1,"CMD: /togpm [on/off]"); //This one says like the first line, if the player only types /togpm, this message shows.
return 1;
}
public OnPlayerConnect(playerid)
{
PMEnabled[playerid] = 1; //Putting this will automatically toggles the connected player's PMs ON when he/she connects.
return 1;
}
Nice tutorial, even though I had this command included into my "ZCMD - Command Collection", as you can see in my signature! The only thing which I got less is the toggling / switchting between the enabling / disabling of PMs...
|
new PMEnabled[MAX_PLAYER_NAME]; // Defnining PMEnabled with the MAX_PLAYER_NAME
new PMEnabled[MAX_PLAYERS]; // Defnining PMEnabled with the MAX_PLAYERS
replace
pawn Code:
pawn Code:
|
if(pID == playerid) return SendClientMessage(playerid,0xAFAFAFAA,"You can't send a pm to yourself");