SSCANF 2 Command Issue
#1

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...
Reply
#2

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;
}
Reply
#3

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?
Reply
#4

I removed the sscanf check because, as I already said, sscanf isn't needed for a single parameter.
Reply
#5

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.
Reply
#6

you already have defined, "isnull" somewere
Reply
#7

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.
Reply
#8

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
Reply
#9

Or you could just delete the definition you have just added.
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)