[Tutorial] Making a simple PM system with ZCMD & sscanf
#1

Hi there, I'll show you have to make a simple PM command system using ZCMD (Click Me!) and sscanf.

First off, lets include zcmd (download it if you don't have it).
pawn Код:
#include <zcmd>
So now we can use zcmd!

Now, lets create the command pm.
pawn Код:
CMD:pm(playerid, params[])
{
    return 1;
}
Now that we have the actual command, we can start declaring new things to add.

pawn Код:
new str[128], str2[128], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
We need to make those, so we don't get "Unknown Symbol".

So, next up is using sscanf to check if the player typed anything after "/pm"
pawn Код:
if(sscanf(params, "us", id, str2))
{
    SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id/name> <message>");
    return 1;
}
Lets sort it out:
u = ID, or Name.
s = string.

{Float,_}:...
ID/Name = The ID/Name they inserted into their PM.
str2 = The message they inserted into their PM.

------------------------------------------------

So now that we have checked if they inserted a ID and Message, sscanf automatically assigns it to the declaration.

so no need to do str2 = strrest(params, idx). (Thank god ******).

Next we check if the player they entered is connected or not:
pawn Код:
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
//We did IsPlayerConnected(id)) because we are checking the player they want to send the pm too.
Now we check if they sent the PM to themselves, or another person.
pawn Код:
if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
So now we move on to sending the messages!

First off, we need to get the player's name, and the receiver's name.
pawn Код:
GetPlayerName(playerid, Name1, sizeof(Name2)); //The Sender's Name so we use (playerid).
GetPlayerName(id, Name2, sizeof(Name2)); //The Receiver's Name so we use (id).

Then, now that we have their names, we format the string (message) to send/receive.
pawn Код:
//This is where we use string #1 (str). Now that we have created, we float The Receiver's name, their ID, and the message!
format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
//Now we send the sender a message repeating what they sent to the receiver:
SendClientMessage(playerid, 0xFF0000FF, str); //Notice its (playerid, not id)

//Now we repeat the first format, but we change it a little, this is the message getting sent to the receiver:
format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
//Float Sender's Name, Sender's ID, and Sender's Message.

//After we have formated the message, we send it to the receiver!
SendClientMessage(id, 0xFF0000FF, Message); //Notice its (id, not playerid).

And so, with all of this added, it should look something like this:
pawn Код:
CMD:pm(playerid, params[])
{
    new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
    if(sscanf(params, "us", id, str2))
    {
        SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id> <message>");
        return 1;
    }
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
    if(playerid == id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!")
    {
        GetPlayerName(playerid, Name1, sizeof(Name1));
        GetPlayerName(id, Name2, sizeof(Name2));
        format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
        SendClientMessage(playerid, 0xFF0000FF, str);
        format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
        SendClientMessage(id, 0xFF0000FF, str);
    }
    return 1;
}
Hoped this helped!

| - The Toni - |
Reply


Messages In This Thread
Making a simple PM system with ZCMD & sscanf - by Toni - 31.07.2010, 17:06
Re: Making a simple PM system with ZCMD & sscanf - by Kevin_Joshen - 31.07.2010, 23:59
Re: Making a simple PM system with ZCMD & sscanf - by willsuckformoney - 01.08.2010, 00:21
Re: Making a simple PM system with ZCMD & sscanf - by Kevin_Joshen - 01.08.2010, 00:34
Re: Making a simple PM system with ZCMD & sscanf - by Kar - 01.08.2010, 00:56
Re: Making a simple PM system with ZCMD & sscanf - by willsuckformoney - 01.08.2010, 02:45
Re: Making a simple PM system with ZCMD & sscanf - by hab2ever - 01.08.2010, 12:31
Re: Making a simple PM system with ZCMD & sscanf - by Toni - 01.08.2010, 13:59
Re: Making a simple PM system with ZCMD & sscanf - by M3ntaL - 01.08.2010, 16:30
Re: Making a simple PM system with ZCMD & sscanf - by Sergei - 01.08.2010, 16:35
Re: Making a simple PM system with ZCMD & sscanf - by Toni - 01.08.2010, 16:40
Re: Making a simple PM system with ZCMD & sscanf - by M3ntaL - 01.08.2010, 16:47
Re: Making a simple PM system with ZCMD & sscanf - by Sergei - 01.08.2010, 17:01
Re: Making a simple PM system with ZCMD & sscanf - by Toni - 01.08.2010, 17:30
Re: Making a simple PM system with ZCMD & sscanf - by Sergei - 01.08.2010, 20:02
Re: Making a simple PM system with ZCMD & sscanf - by Toni - 01.08.2010, 20:44
Re: Making a simple PM system with ZCMD & sscanf - by Blades - 18.08.2010, 10:32
Re: Making a simple PM system with ZCMD & sscanf - by Toni - 18.08.2010, 11:06
Re: Making a simple PM system with ZCMD & sscanf - by Blades - 19.08.2010, 08:41
Re: Making a simple PM system with ZCMD & sscanf - by Blades - 08.09.2010, 09:56
Re: Making a simple PM system with ZCMD & sscanf - by PinkFloydLover - 08.09.2010, 11:26
Re: Making a simple PM system with ZCMD & sscanf - by gondes - 19.09.2010, 15:53
Re: Making a simple PM system with ZCMD & sscanf - by Toni - 19.09.2010, 16:01
Re: Making a simple PM system with ZCMD & sscanf - by _rAped - 05.01.2011, 04:28
Re: Making a simple PM system with ZCMD & sscanf - by opik - 06.08.2011, 10:18
Re: Making a simple PM system with ZCMD & sscanf - by mickos - 08.06.2012, 05:12
Re: Making a simple PM system with ZCMD & sscanf - by chuck100 - 14.05.2013, 22:28
Re: Making a simple PM system with ZCMD & sscanf - by Pettersen - 18.05.2013, 17:10
Re: Making a simple PM system with ZCMD & sscanf - by ATGOggy - 30.10.2014, 13:59
Re: Making a simple PM system with ZCMD & sscanf - by Rudy_ - 30.10.2014, 14:01
Re: Making a simple PM system with ZCMD & sscanf - by ATGOggy - 30.10.2014, 14:24
Re: Making a simple PM system with ZCMD & sscanf - by Rudy_ - 30.10.2014, 14:25
Re: Making a simple PM system with ZCMD & sscanf - by ATGOggy - 30.10.2014, 14:30
Re: Making a simple PM system with ZCMD & sscanf - by ATGOggy - 30.10.2014, 17:16
Re: Making a simple PM system with ZCMD & sscanf - by ATGOggy - 31.10.2014, 11:05
Re: Making a simple PM system with ZCMD & sscanf - by Arastair - 08.11.2014, 14:44
Re: Making a simple PM system with ZCMD & sscanf - by antixgaming - 30.04.2018, 13:24

Forum Jump:


Users browsing this thread: 1 Guest(s)