SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 25/11/2012, 09:05 PM   #1
thefatshizms
High-roller
 
thefatshizms's Avatar
 
Join Date: Dec 2011
Location: England
Posts: 1,788
Reputation: 259
Cool Making a Private message system

Private Message System
Introduction

Hello, today i'm going to be showing you how to make a total of two commands, them being a /pm <id> <message>
and /r <message> the r meaning reply.

Things you will be needing

[Inc] Zcmd By zeex. - http://forum.sa-mp.com/showthread.php?t=91354
[Plugin] Sscanf By Y_Less. - http://forum.sa-mp.com/showthread.php?t=120356
Basic Pawn Knowledge.

Lets get started

Add this to the top of your script if you haven't done so already:
pawn Code:
#include <a_samp> //Including sa-mp functions
#include <zcmd> //Zcmd, for our commands
#include <sscanf2> //This is for our extensions or params
Now we will need to add a variable, this is to store the id of the last player that pm'ed you.
If you don't know what a variable is, it's like algebra where you have X and x can be equal to something.
pawn Code:
new LastPm[MAX_PLAYERS]; // The MAX_PLAYERS evaluates to 500 being the default maximum players. we need it
// so we can make it relative to a certin player
Now we are going to need a function to get a players name and return it to the script.
pawn Code:
stock PlayerName(playerid)
{
    new name[MAX_PLAYER_NAME]; // Declearing a new string variable named 'name' with a length of MAX_PLAYER_NAME which i think is 24
    GetPlayerName(playerid, name, sizeof(name));// Getting playerid's name and assigning it the the string variable
    return name;// return the name to the script
}
pawn Code:
public OnPlayerConnect(playerid)
{
    LastPm[playerid] = -1;
    return 1;
}
// Setting the variables both to -1 meaning that he hasnt been pmed
public OnPlayerDisconnect(playerid, reason)
{  
    LastPm[playerid] = -1;
    return 1;
}
Now we can get on to the commands!
pawn Code:
CMD:pm(playerid, params[])
{
    new id, string[2][128], message[128]; // a int variable named id, this is to store the id of the player you are pming
    if(sscanf(params,"us[128]",id,message)) return SendClientMessage(playerid, -1, "Syntax: /pm <id> <message>");// this is for your extension aka params, u is for the id s is for the string 'message'
    if(id == playerid) return SendClientMessage(playerid, -1, "You cannot send a pm to yourself");// If the id you want to pm is your id then send a message back that we cant pm ourself!
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "This player is not connected");// If the id of the player you want to pm is not connect send a message
    format(string[0], 128, "** Pm Sent to %s : %s", PlayerName(id), message);// formatting a string the [0] is part of the array %s is a string and we are using our function PlayerName to return the players name the message variable is equal to what you put
    format(string[1], 128, "** Pm From %s : %s", PlayerName(playerid), message);// same as the above
    SendClientMessage(playerid, -1, string[0]);// Sending the first string
    SendClientMessage(id, -1, string[1]);// sending the string
    LastPm[id] = playerid;// Setting the player you pmed LastPm variable to your id so he can use /r to pm you back
    return 1;
}

pawn Code:
CMD:r(playerid, params[])
{
    new string[2][128], message[128]; // same as the pm command without the id because we are using that in the LastPm variable
    if(LastPm[playerid] == -1) return SendClientMessage(playerid, -1, "No one has pm'ed you since you joined the server"); // when the player connects we set the variable to -1 so it means he hasnt been pm'ed this is just checking if this is true then sending a message
    if(LastPm[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "The player that last pm'ed you has left the server");// If the above is false and you have been pm'ed before BUT that player has left we send this message
    if(sscanf(params,"s[128]",message)) return SendClientMessage(playerid, -1, "Syntax: /r <message>");// same as the pm command
    format(string[0], 128, "** Pm Sent to %s : %s", PlayerName(LastPm[playerid]), message);// same as the pm command
    format(string[1], 128, "** Pm From %s : %s", PlayerName(playerid), message);//same as the pm command
    SendClientMessage(playerid, -1, string[0]);//same as the pm command
    SendClientMessage(LastPm[playerid], -1, string[1]);//same as the pm command
    LastPm[LastPm[playerid]] = playerid;// If the guy we just replied to got a message from someone else before we replied we can then set it back to our id since we just pmed him
    return 1;
}

I hope this helped you, i'm willing to explain more if needed.
__________________
SFCNR ******* | SFCNR Forum

Last edited by thefatshizms; 26/11/2012 at 12:54 PM.
thefatshizms is offline   Reply With Quote
Old 25/11/2012, 09:08 PM   #2
NewerthRoleplay
High-roller
 
NewerthRoleplay's Avatar
 
Join Date: Nov 2011
Location: England :: The Danger Zone
Posts: 1,083
Reputation: 133
Default Re: Making a Private message system

Nice man, great explanation
__________________
NewerthRoleplay is offline   Reply With Quote
Old 25/11/2012, 09:59 PM   #3
thefatshizms
High-roller
 
thefatshizms's Avatar
 
Join Date: Dec 2011
Location: England
Posts: 1,788
Reputation: 259
Default Re: Making a Private message system

Thanks
__________________
SFCNR ******* | SFCNR Forum
thefatshizms is offline   Reply With Quote
Old 26/11/2012, 12:39 AM   #4
Zex Tan
Huge Clucker
 
Join Date: Mar 2012
Location: South Australia
Posts: 307
Reputation: 48
Default Re: Making a Private message system

Good job
Zex Tan is offline   Reply With Quote
Old 26/11/2012, 01:43 AM   #5
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,316
Reputation: 3191
Default Re: Making a Private message system

Are you aware that will give loads of errors in the console? Did you test the code as posted?
Y_Less is offline   Reply With Quote
Old 26/11/2012, 07:34 AM   #6
thefatshizms
High-roller
 
thefatshizms's Avatar
 
Join Date: Dec 2011
Location: England
Posts: 1,788
Reputation: 259
Default Re: Making a Private message system

Are you sure? I've tested the code and I get no errors in the console.
__________________
SFCNR ******* | SFCNR Forum
thefatshizms is offline   Reply With Quote
Old 26/11/2012, 07:41 AM   #7
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,316
Reputation: 3191
Default Re: Making a Private message system

Positive.
Y_Less is offline   Reply With Quote
Old 26/11/2012, 10:14 AM   #8
thefatshizms
High-roller
 
thefatshizms's Avatar
 
Join Date: Dec 2011
Location: England
Posts: 1,788
Reputation: 259
Default Re: Making a Private message system

Ok, I'm at school atm ill look into the errorrs when I get home
__________________
SFCNR ******* | SFCNR Forum
thefatshizms is offline   Reply With Quote
Old 26/11/2012, 10:31 AM   #9
zProfessional
Big Clucker
 
zProfessional's Avatar
 
Join Date: Nov 2012
Location: In Xtremer's Back
Posts: 167
Reputation: 20
Default Re: Making a Private message system

this is nice
__________________
zProfessional is offline   Reply With Quote
Old 26/11/2012, 10:48 AM   #10
XtremeR
Gangsta
 
XtremeR's Avatar
 
Join Date: Aug 2012
Location: Australia
Posts: 896
Reputation: 565
Default Re: Making a Private message system

Simple but nice, it would be better if you had used stuff like Read Able Pms for Admins..
__________________
XtremeR is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] [FS]Private Message System SpiderWalk Filterscripts 42 21/01/2015 07:31 AM
Private Message System. [HELP] ProdrifterX Scripting Help 3 27/05/2012 11:11 AM
[Tutorial] Simple Private Message System Using zCMD And Sscanf with Logs Jason_Thunde Tutorials 3 19/10/2011 09:59 PM
Making private plate ColdIce Help Archive 8 17/05/2011 03:49 AM
Question on a making my own private message command. CaptainCaveMan Help Archive 3 28/08/2009 04:07 PM


All times are GMT. The time now is 06:28 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.