Making my own PM command -
Torran - 10.03.2010
Im trying to make my own PM command using zcmd/sscanf,
And i have run into a little trouble,
I have this at the top of my command
pawn Код:
CMD:pm(playerid, params[])
{
new id;
new message;
if (sscanf(params, "us", id, message)) SendClientMessage(playerid, COLOR_RED, "Usage ~ /pm [PlayerID/PartOfName] [Message]");
else if (id == playerid) SendClientMessage(playerid, COLOR_RED, "Error ~ You cannot PM yourself");
else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Error ~ Player not Connected");
else {
But it just completely ignores:
pawn Код:
else if (id == playerid) SendClientMessage(playerid, COLOR_RED, "Error ~ You cannot PM yourself");
else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Error ~ Player not Connected");
Does anyone know why?
Ask if you wanna see the full PM cmd
Re: Making my own PM command -
woot - 10.03.2010
Why do you use else statements?
Re: Making my own PM command -
Torran - 10.03.2010
I dont know,
Ive always used else statements, Never ran into a problem..
Guess i just looked at this code and followed it ever since:
https://sampwiki.blast.hk/wiki/Fast_Commands#givecash
Re: Making my own PM command -
gotenks918 - 10.03.2010
Quote:
CMD m(playerid, params[])
{
new id,
message;
if (sscanf(params, "us", id, message)) return SendClientMessage(playerid, COLOR_RED, "Usage ~ /pm [PlayerID/PartOfName] [Message]");
if (id == playerid) return SendClientMessage(playerid, COLOR_RED, "Error ~ You cannot PM yourself");
if (id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Error ~ Player not Connected");
else {
|
Try that, although I'm a n00b at scripting
You might also want to enable to PM CMD to have 128 characters "if (sscanf(params, "us[128]", id, message))", I think that works.
Re: Making my own PM command -
Kyosaur - 10.03.2010
Quote:
Originally Posted by //exora
Why do you use else statements?
|
The else statements are gross, yes, but thats not his problem. He's declaring message as an integer; it should be a string.
Quote:
Originally Posted by gotenks918
Quote:
CMD m(playerid, params[])
{
new id,
message;
if (sscanf(params, "us", id, message)) return SendClientMessage(playerid, COLOR_RED, "Usage ~ /pm [PlayerID/PartOfName] [Message]");
if (id == playerid) return SendClientMessage(playerid, COLOR_RED, "Error ~ You cannot PM yourself");
if (id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Error ~ Player not Connected");
else {
|
Try that, although I'm a n00b at scripting
You might also want to enable to PM CMD to have 128 characters "if (sscanf(params, "us[128]", id, message))", I think that works.
|
Thats only for the plugin version. (dont know if he is using it or not... i assume not)
Re: Making my own PM command -
gotenks918 - 10.03.2010
Oh you're right lol XD.
new message[128]; or what ever you want the max string length to be.
Re: Making my own PM command -
Torran - 10.03.2010
Ok, I tried doing if, And i guess i know why i use else,
Because rather than sending one message with the specific error,
It does everything,
It shows the usage, It says player not found, It ses i cant pm myself, And it sends the pm too
EDIT: Works now thanks
Im not using the plugin version btw
Re: Making my own PM command -
gotenks918 - 10.03.2010
returning the SendClientMessage should prevent it from going on to the next if statement.
Re: Making my own PM command -
Finn - 10.03.2010
Quote:
Originally Posted by Joe Torran C
Ok, I tried doing if, And i guess i know why i use else,
Because rather than sending one message with the specific error,
It does everything,
It shows the usage, It says player not found, It ses i cant pm myself, And it sends the pm too
|
There's no real difference between
pawn Код:
if(this == that) print("message 1");
else if(this < that) print("message 2");
else print("message 3");
return 1;
And
pawn Код:
if(this == that) return print("message 1");
if(this < that) return print("message 2");
return print("message 3");
As like you can see it's the same code except that in the first code the return is delayed to the later part of the code.
It doesn't really matter how you do it, it's just a matter of taste. I prefer to use the code below.
Re: Making my own PM command -
Miguel - 10.03.2010
pawn Код:
CMD:pm(playerid, params[])
{
new
id,
string[128];
if(sscanf(params, "us", id, string)) return SendClientMessage(playerid, COLOR, "Usage ~ /pm [PlayerID/PartOfName] [Message]");
else if(id == playerid) return SendClientMessage(playerid, COLOR, "Error ~ You cannot PM yourself");
else if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR, "Error ~ Player not Connected");
else
{
// code
}
return 1;
}
Mine is like that...