Help please, lacks forward declaration..
#8

TESTED AND WORKS!!!


Alright.
I will use ZCMD. You'll need the ZCMD include. The sscanf2 include as well.
You can easily find them on the forum.

Lets start with making the command.

pawn Код:
COMMAND:pm(playerid,params[])
{

return 1;
}
That's how we start making the command.

Now we need this in our command:
pawn Код:
new id,string[100],text[100],playername1[MAX_PLAYER_NAME],playername2[MAX_PLAYER_NAME];
The id is the person we'll send it to.
the string is the message you and the player will get.
The text is the text you'll send.

Now we're going to use the sscanf fuction.

pawn Код:
if(sscanf(params,"us[100]",id,text)) return SendClientMessage(playerid,COLOR,"USAGE:/pm playerid text");
If you forget the [100] after the S you'll get a warning in your server.exe, so don't forget it.

Now we want to check if the player is connected.

pawn Код:
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR,"Player not connected");
We don't use playerid at the !IsPlayerConnected(id)) because we don't want to know if the player that uses the command is online.

Now what will happen when the player is connected and you used the cmd on a good way?

pawn Код:
else
{
GetPlayerName(playerid,playername1,sizeof(playername1));
GetPlayerName(id,playername2,sizeof(playername2));
format(string,sizeof(string),"PM from %s: %s",playername1,text);
SendClientMessage(id,COLOR,string);
format(string,sizeof(string),"PM to %s: %s",playername2,text);
SendClientMessage(playerid,COLOR,string);
}
Now that's done.

The whole code:

pawn Код:
COMMAND:pm(playerid,params[])
{
new id,string[100],text[100],playername1[MAX_PLAYER_NAME],playername2[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername1,sizeof(playername1));
GetPlayerName(id,playername2,sizeof(playername2));
if(sscanf(params,"us[100]",id,text)) return SendClientMessage(playerid,COLOR,"USAGE:/pm playerid text");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR,"Player not connected");
else
{
GetPlayerName(playerid,playername1,sizeof(playername1));
GetPlayerName(id,playername2,sizeof(playername2));
format(string,sizeof(string),"PM from %s: %s",playername1,text);
SendClientMessage(id,COLOR,string);
format(string,sizeof(string),"PM to %s: %s",playername2,text);
SendClientMessage(playerid,COLOR,string);
}
return 1;
}
I hope I've explained this well enough.

Good luck

EDIT:
Damn you calgon!! xD
You were faster. LOl
Reply


Messages In This Thread
Help please, lacks forward declaration.. - by iGetty - 31.01.2011, 12:35
Re: Help please, lacks forward declaration.. - by Calgon - 31.01.2011, 12:38
Re: Help please, lacks forward declaration.. - by iGetty - 31.01.2011, 12:43
Re: Help please, lacks forward declaration.. - by Calgon - 31.01.2011, 12:44
Re: Help please, lacks forward declaration.. - by iGetty - 31.01.2011, 12:47
Re: Help please, lacks forward declaration.. - by Calgon - 31.01.2011, 13:07
Re: Help please, lacks forward declaration.. - by iGetty - 31.01.2011, 13:19
Re: Help please, lacks forward declaration.. - by bartje01 - 31.01.2011, 13:21
Re: Help please, lacks forward declaration.. - by Calgon - 31.01.2011, 13:23
Re: Help please, lacks forward declaration.. - by bartje01 - 31.01.2011, 13:28

Forum Jump:


Users browsing this thread: 5 Guest(s)