04 Desember, 2012

PAWNO Programming | A simple PM for SA-MP.

Alright guys, today I wanna show you how to make a Personal Message or also known as PM simply. The includes are sscanf and zcmd. Alright let's see.

First insert these codes on top of your script
#include <a_samp>
#include <sscanf>
#include <zcmd>

And then insert this codes in bottom of your script or in your CMDs section.
CMD:pm(playerid, params[])
{
         new id, msgs[100], string[140], sender[MAX_PLAYER_NAME], target[MAX_PLAYER_NAME];
         if(sscanf(params, "us", id, msgs)) return SendClientMessage(playerid, Your Color, "CMD: /pm [target]");
         if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, Your Color, "ERROR: Player not found");
         else
         {
                GetPlayerName(playerid, sender, sizeof(sender));
                GetPlayerName(id, target, sizeof(target));
                format(string, sizeof(string), "%s : %s", sender, msgs);
                SendClientMessage(id, Your Color, string);
                format(string, sizeof(string), "Sent to %s: %s", target, msgs);
                SendClientMessage(playerid, Your Color, string);
         }
         return 1;
}

Okay i'll explain it to you,
These codes
CMD:pm(playerid, params[])
{
         new id, msgs[100], string[140], sender[MAX_PLAYER_NAME], target[MAX_PLAYER_NAME];
         if(sscanf(params, "us", id, msgs)) return SendClientMessage(playerid, Your Color, "CMD: /pm [target]");
They'll scan the player's command, if the players aren't fill the CMD form, the server gonna send error message or tell the player about the structures of this command.

And then these codes

if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, Your Color, "ERROR: Player not found");
         else
         {
                GetPlayerName(playerid, sender, sizeof(sender));
                GetPlayerName(id, target, sizeof(target));
                format(string, sizeof(string), "%s : %s", sender, msgs);
                SendClientMessage(id, Your Color, string);
                format(string, sizeof(string), "Sent to %s: %s", target, msgs);
                SendClientMessage(playerid, Your Color, string);
         }
These codes mean it'll process the command, if the player's target isn't connect, the server'll send an error message, otherwise if the player's target was connected it'll continue the process with scanning player's name and the target's name, eventually the server will send the message to each player

That's all for today, thank you for visiting my site, and sorry for my bad english and my another mistakes.
Best regards, Ryu a.K.a Raveronze

2 komentar: