SSCANF 2 Command Issue -
Scenario - 28.09.2010
Hey, folks. So I have this command (/say) but it does not fully work.
pawn Код:
command(say, playerid, params[])
{
new message, string[128];
if(PlayerStatistics[playerid][pAdminLevel] >= 3)
{
if(sscanf(params, "s[119]", message))
{
SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /say [message]");
}
else
{
if(IsPlayerConnectedEx(playerid))
{
format(string, sizeof(string), "* Admin: %s", message);
SendClientMessageToAll(0x2587CEFF, string);
}
else
{
SendClientMessage(playerid, COLOR_WHITE, "You are not logged in!");
}
}
}
return 1;
}
The command will actually display only numbers, not letters or special characters. Plus, it gives the "SERVER: UNKNOWN COMMAND!" message...
Re: SSCANF 2 Command Issue -
bigcomfycouch - 29.09.2010
You had message, which should've been a string, as an interger. You also needn't use sscanf for a single parameter.
pawn Код:
#define isnull(%1) (!%1[0] || (%1[0] == '\1' && !%1[1]))
command(say, playerid, params[])
{
new
string[128];
if(PlayerStatistics[playerid][pAdminLevel] < 3) return 1;
if(isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /say [message]");
if(!IsPlayerConnectedEx(playerid)) return SendClientMessage(playerid, COLOR_WHITE, "You are not logged in!");
format(string, sizeof(string), "* Admin: %s", message);
SendClientMessageToAll(0x2587CEFF, string);
return 1;
}
Re: SSCANF 2 Command Issue -
Scenario - 29.09.2010
Quote:
Originally Posted by bigcomfycouch
You had message, which should've been a string, as an interger. You also needn't use sscanf for a single parameter.
pawn Код:
#define isnull(%1) (!%1[0] || (%1[0] == '\1' && !%1[1]))
command(say, playerid, params[]) { new string[128]; if(PlayerStatistics[playerid][pAdminLevel] < 3) return 1; if(isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /say [message]"); if(!IsPlayerConnectedEx(playerid)) return SendClientMessage(playerid, COLOR_WHITE, "You are not logged in!"); format(string, sizeof(string), "* Admin: %s", message); SendClientMessageToAll(0x2587CEFF, string); return 1; }
|
Doesn't SSCANF already check if the parameter is null?
Re: SSCANF 2 Command Issue -
bigcomfycouch - 29.09.2010
I removed the sscanf check because, as I already said, sscanf isn't needed for a single parameter.
Re: SSCANF 2 Command Issue -
Scenario - 29.09.2010
Quote:
Originally Posted by bigcomfycouch
I removed the sscanf check because, as I already said, sscanf isn't needed for a single parameter.
|
Okay, now I'm getting an error.
pawn Код:
C:\Users\Nick Piccoli\Desktop\Relentless Trucking\gamemodes\R-Trucking.pwn(26) : warning 201: redefinition of constant/macro (symbol "isnull(%1)")
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
1 Warning.
Re: SSCANF 2 Command Issue - [L3th4l] - 29.09.2010
you already have defined, "isnull" somewere
Re: SSCANF 2 Command Issue -
Scenario - 29.09.2010
Quote:
Originally Posted by [L3th4l]
you already have defined, "isnull" somewere
|
My script is 1758 lines long, I have not defined "isnull" anywhere else, unless it's the SSCANF include.
EDIT: I just got it to stop showing the error. I go in game, do '/say hello', but it doesn't show the message, it just shows the text which is already in the string.
Re: SSCANF 2 Command Issue - [L3th4l] - 29.09.2010
Check on your includes. If i'm not mistaken, i think zcmd has that defined.
Edit- Else try this
pawn Код:
COMMAND:say(playerid, params[])
{
if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Say < Message >");
format(string, sizeof(string), "Me: %s", params);
SendClientMessageToAll(COLORHERE, string);
return 1;
}
Just include a player name if you want
Re: SSCANF 2 Command Issue -
Grim_ - 29.09.2010
Or you could just delete the definition you have just added.
Re: SSCANF 2 Command Issue -
Scenario - 29.09.2010
I re-wrote the command and it all seems to be working now.
pawn Код:
command(say, playerid, params[])
{
new Message[128], string[128];
if(sscanf(params, "s[128]", Message))
{
SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /say [message]");
}
else
{
if(strlen(Message) < 1 || !IsPlayerConnectedEx(playerid))
{
return 1;
}
else
{
format(string, sizeof(string), "* Admin: %s", Message);
SendClientMessageToAll(0x2587CEFF, string);
}
}
return 1;
}