More sscanf help
#1

In my quest to fully learn sscanf, I have ran across alot of problems, and questions; This one has always stumped me. How would I go about adding an optional parameter? According to the official sscanf release topic, "i" is an optional integer, and "S" is an optional string - How would I go about making it optional? Such as..

pawn Код:
COMMAND:muteplayer(playerid, params[])
{
    new MuteReason[128], String[128], Player;
    if(sscanf(params, "uS[128]", Player, MuteReason)) { //"S" is the optional string parameter according to ******' topic.
        SendClientMessage(playerid, c_white, "[USAGE] /MutePlayer [Player ID] [Mute Reason (optional)]");
        return 1;
    }
    SetPVarInt(Player, "Muted", 1);
    if(!MuteReason)) {
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: No Reason Specified.", pName(playerid));
        return 1;
    }
    else {
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: \"%s\"", pName(playerid), MuteReason);
    }
    SendClientMessage(playerid, c_white, String);
    return 1;
}
Now, of course this wouldn't work, but logically, this is how it should work in my mind. Any ideas?
Reply
#2

use the "z" : if(sscanf(params,"uz[128]",Player,MuteReason))
Reply
#3

Quote:

C:\Users\Sky\Desktop\Work\Coding\sPAdmin\filterscr ipts\sPAdmin.pwn(253) : error 033: array must be indexed (variable "MuteReason")
C:\Users\Sky\Desktop\Work\Coding\sPAdmin\filterscr ipts\sPAdmin.pwn(253) : error 029: invalid expression, assumed zero
C:\Users\Sky\Desktop\Work\Coding\sPAdmin\filterscr ipts\sPAdmin.pwn(257) : warning 225: unreachable code
C:\Users\Sky\Desktop\Work\Coding\sPAdmin\filterscr ipts\sPAdmin.pwn(257) : error 029: invalid expression, assumed zero

pawn Код:
COMMAND:muteplayer(playerid, params[])
{
    new MuteReason[128], String[128], Player;
    if(sscanf(params, "uz[128]", Player, MuteReason)) {
        SendClientMessage(playerid, c_white, "[USAGE] /MutePlayer [Player ID] [Mute Reason (optional)]");
        return 1;
    }
    SetPVarInt(Player, "Muted", 1);
    if(!MuteReason)) { //Line 253
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: No Reason Specified.", pName(playerid));
        return 1;
    }
    else { //Line 257
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: \"%s\"", pName(playerid), MuteReason);
    }
    SendClientMessage(playerid, c_white, String);
    return 1;
}
Reply
#4

You can only use an exclamation mark to see if a value is 0 if you’re using an integer.

pawn Код:
if(isnull(MuteReason)) { //Line 253
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: No Reason Specified.", pName(playerid));
        return 1;
    }
    else { //Line 257
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: \"%s\"", pName(playerid), MuteReason);
    }
If you haven’t tried using the ’S’, try it. The ’Z’ parameter was used for the stock, but if you’re using the plugin—you’ll want to use ’S’ instead.
Reply
#5

pawn Код:
COMMAND:muteplayer(playerid, params[])
{
    new MuteReason[128], String[128], Player;
    if(sscanf(params, "uS[128]", Player, MuteReason)) return SendClientMessage(playerid, -1, "[USAGE] /MutePlayer [Player ID] [Mute Reason (optional)]");
    if(isnull(MuteReason))
    {
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: No Reason Specified.", pName(playerid));

    }
    else
    {
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: \"%s\"", pName(playerid), MuteReason);
    }
    SetPVarInt(Player, "Muted", 1);
    SendClientMessage(playerid, c_white,String);
    return 1;
}
Reply
#6

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
You can only use an exclamation mark to see if a value is 0 if you're using an integer.

pawn Код:
if(isnull(MuteReason)) { //Line 253
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: No Reason Specified.", pName(playerid));
        return 1;
    }
    else { //Line 257
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: \"%s\"", pName(playerid), MuteReason);
    }
Right, thank you. I shall try this out.
Reply
#7

pawn Код:
COMMAND:muteplayer(playerid, params[])
{
    new MuteReason[128], String[128], Player;
    if(sscanf(params, "uS[128]", Player, MuteReason)) {
        SendClientMessage(playerid, c_white, "[USAGE] /MutePlayer [Player ID] [Mute Reason (optional)]");
        return 1;
    }
    SetPVarInt(Player, "Muted", 1);
    if(isnull(MuteReason)) {
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: No Reason Specified.", pName(playerid));
        return 1;
    }
    else {
        format(String, sizeof(String), "You have been muted by Administrator %s, Reason: \"%s\"", pName(playerid), MuteReason);
    }
    SendClientMessage(playerid, c_white, String);
    return 1;
}
Doesn't work, and spams me with:

Quote:

Console input: reloadfs sPAdmin
[18:10:55] Filter script 'sPAdmin.amx' unloaded.
[18:10:55]
[18:10:55] [+] Filterscript "sPAdmin" has been initiated.
[18:10:55]
[18:10:55] [-] Filterscript Version: 0.1
[18:10:55] [-] Filterscript Author: Skylar Paul
[18:10:55]
[18:10:55] [+] Setting up your gamemode..
[18:10:55]
[18:10:55] [-] Game Mode Text set to "v0.1a"
[18:10:55] [-] Server Name set to "Change this!"
[18:10:55] [-] 0 Pickup(s) loaded from "Pickups.txt"
[18:10:55] [-] 0 Vehicle(s) loaded from "Vehicles.txt"
[18:10:55] [-] 0 Label(s) loaded from "Labels.txt"
[18:10:55] [-] 1 Map Icon(s) loaded from "MapIcons.txt"
[18:10:55]
[18:10:55] [+] Your Game Mode has been set up successfully.
[18:10:55]
[18:10:55] [-] Server has been started!
[18:10:55] [-] Date: [04/15/2011] | Time: [18:10]
[18:10:55]
[18:10:55] Filterscript 'sPAdmin.amx' loaded.
[18:11:00] sscanf warning: No default value found.
[18:11:00] sscanf warning: Unknown format specifier '[', skipping.
[18:11:00] sscanf warning: Unknown format specifier '1', skipping.
[18:11:00] sscanf warning: Unknown format specifier '2', skipping.
[18:11:00] sscanf warning: Unknown format specifier '8', skipping.
[18:11:00] sscanf warning: Unknown format specifier ']', skipping.
[18:11:00] sscanf warning: Format specifier does not match parameter count.

Reply
#8

Get the plugin.
Reply
#9

sscanf(params, "uS[128]", Player, MuteReason)

->

sscanf(params, "us[128]", Player, MuteReason)
Reply
#10

You have to put a default value at an optional parameter if I remember it right.

ie: sscanf(params, "uS(none)[128]", Player, MuteReason)

You can replace "none" by anything.

You do have to change your code a bit, but thats how optional parameters work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)