How To: SSCANF To Return 'No Reason'
#1

Hey there guys,

I'm kind of new to sscanf and ZCMD altogether, but I just wanted to ask a quick question.
Here's my /kick command:
pawn Код:
CMD:kick(playerid,params[])
{
    new id, reason[60];
    if(!IsPlayerAdmin(playerid) && Player[playerid][Admin] < 4) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}You Have Entered An Invalid Command. Read {00FF00}/CMDS{FFFFFF}.");
    if(sscanf(params,"us[60]",id,reason) || sscanf(params,"u",id)) return SendClientMessage(playerid, red, "SYNTAX ERROR: {00FF00}/KICK {FFFF00}<PlayerID> <Reason>");
    if(strlen(reason) > 60) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Reason Must Be Below 60 Characters.");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Player Is Not Connected.");
    if(!strlen(reason))
    {
        reason = "No Reason.";
    }
    new string[134], string2[177];
    if(Player[playerid][Hidden] == 0)
    {
        format(string,sizeof(string),"You Have Been Kicked By Administrator %s | Reason: %s", pName(playerid), reason);
        format(string,sizeof(string),"Player %s Has Been Kicked From The Server By Administrator %s | Reason: %s",pName(id),pName(playerid),reason);
    }
    else
    {
        format(string,sizeof(string),"You Have Been Kicked From The Server | Reason: %s", reason);
        format(string2,sizeof(string2),"Player %s Has Been Kicked From The Server | Reason: %s",pName(id),reason);
    }
    SendClientMessage(id, red, string);
    SendClientMessage(id, orange, "If You Think This Is A Mistake Or You Are Being Treated Unfairly, Post A Report At 'WWW.AWPGAMING.COM/FORUMS'");
    format(string,sizeof(string),"You Have Kicked %s From The Server | Reason: %s", pName(id), reason);
    SendClientMessage(playerid, yellow, string);
    format(string,sizeof(string),"Administrator %s Has Kicked Player %s | Reason: %s",pName(playerid), pName(id), reason);
    Kick(id);
    SendClientMessageToAll(red,string2);
    return 1;
}
Okay, so let's just say that if I tried to kick someone for a reason, it would appear as normal. As you may have noticed, I have if(!strlen(reason)) in my script, telling it to return as 'No Reason', but I still get the Syntax Error above it. So how would I go about making it, so that if they didn't enter a reason, it would return as 'No Reason', but if they DID enter it, it would function as normal?

I appreciate any help you can offer and will gladly give rep upon request to any helpers.
Regards,
clarencecuzz.
Reply
#2

EDIT: try this

pawn Код:
CMD:kick(playerid,params[])
{
    new id, reason[60];
    if(!IsPlayerAdmin(playerid) && Player[playerid][Admin] < 4) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}You Have Entered An Invalid Command. Read {00FF00}/CMDS{FFFFFF}.");
    if(sscanf(params,"us[60]",id,reason) || sscanf(params,"u",id)) return if(sscanf(params,"us[60]",id,reason) || sscanf(params,"u",id)) return SendClientMessage(playerid, red, "SYNTAX ERROR: {00FF00}/KICK {FFFF00}<PlayerID> <Reason>");
    if(strlen(reason) > 60) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Reason Must Be Below 60 Characters.");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Player Is Not Connected.");
    if(!params(reason))
    {
        reason = "No Reason.";
    }
    new string[134], string2[177];
    if(Player[playerid][Hidden] == 0)
    {
        format(string,sizeof(string),"You Have Been Kicked By Administrator %s | Reason: %s", pName(playerid), reason);
        format(string,sizeof(string),"Player %s Has Been Kicked From The Server By Administrator %s | Reason: %s",pName(id),pName(playerid),reason);
    }
    else
    {
        format(string,sizeof(string),"You Have Been Kicked From The Server | Reason: %s", reason);
        format(string2,sizeof(string2),"Player %s Has Been Kicked From The Server | Reason: %s",pName(id),reason);
    }
    SendClientMessage(id, red, string);
    SendClientMessage(id, orange, "If You Think This Is A Mistake Or You Are Being Treated Unfairly, Post A Report At 'WWW.AWPGAMING.COM/FORUMS'");
    format(string,sizeof(string),"You Have Kicked %s From The Server | Reason: %s", pName(id), reason);
    SendClientMessage(playerid, yellow, string);
    format(string,sizeof(string),"Administrator %s Has Kicked Player %s | Reason: %s",pName(playerid), pName(id), reason);
    Kick(id);
    SendClientMessageToAll(red,string2);
    return 1;
}
Reply
#3

Just use default value in sscanf:
Код:
if(sscanf(params,"uS(No Reason)[128]",id,reason)) return SendClientMessage(playerid, red, "SYNTAX ERROR: {00FF00}/KICK {FFFF00}<PlayerID> <Optional: Reason>");
and remove
Код:
if(!strlen(reason))
    {
        reason = "No Reason.";
    }
To understand better sscanf, take a look in the main topic: https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#4

Visually, it doesn't look like it would work.

Thanks for trying though

EDIT: Thanks ^^
Reply
#5

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
Visually, it doesn't look like it would work.

Thanks for trying though
Try the edit I made in my post it might work...
Reply
#6

No, sorry :S

But I'll still give you rep for your efforts, thank you for trying xD
[THREAD SOLVED]
Reply
#7

@too late.
pawn Код:
CMD:kick(playerid,params[])
{
    new id, reason[60];
    if(!IsPlayerAdmin(playerid) && Player[playerid][Admin] < 4) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}You Have Entered An Invalid Command. Read {00FF00}/CMDS{FFFFFF}.");
    if(sscanf(params,"us[60]",id,reason)) return SendClientMessage(playerid, red, "SYNTAX ERROR: {00FF00}/KICK {FFFF00}<PlayerID> <Reason>");
    if(strlen(reason) > 60) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Reason Must Be Below 60 Characters.");
    if(!strlen(reason)) return SendClientMessage(playerid,-1,"You must put a reason");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Player Is Not Connected.");
    new string[134], string2[177];
    if(Player[playerid][Hidden] == 0)
    {
        format(string,sizeof(string),"You Have Been Kicked By Administrator %s | Reason: %s", pName(playerid), reason);
        format(string,sizeof(string),"Player %s Has Been Kicked From The Server By Administrator %s | Reason: %s",pName(id),pName(playerid),reason);
    }
    else
    {
        format(string,sizeof(string),"You Have Been Kicked From The Server | Reason: %s", reason);
        format(string2,sizeof(string2),"Player %s Has Been Kicked From The Server | Reason: %s",pName(id),reason);
    }
    SendClientMessage(id, red, string);
    SendClientMessage(id, orange, "If You Think This Is A Mistake Or You Are Being Treated Unfairly, Post A Report At 'WWW.AWPGAMING.COM/FORUMS'");
    format(string,sizeof(string),"You Have Kicked %s From The Server | Reason: %s", pName(id), reason);
    SendClientMessage(playerid, yellow, string);
    format(string,sizeof(string),"Administrator %s Has Kicked Player %s | Reason: %s",pName(playerid), pName(id), reason);
    Kick(id);
    SendClientMessageToAll(red,string2);
    return 1;
}
Reply
#8

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
pawn Код:
CMD:kick(playerid,params[])
{
    new id, reason[60];
    if(!IsPlayerAdmin(playerid) && Player[playerid][Admin] < 4) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}You Have Entered An Invalid Command. Read {00FF00}/CMDS{FFFFFF}.");
    if(sscanf(params,"us[60]",id,reason)) return SendClientMessage(playerid, red, "SYNTAX ERROR: {00FF00}/KICK {FFFF00}<PlayerID> <Reason>");
    if(strlen(reason) > 60) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Reason Must Be Below 60 Characters.");
    if(!strlen(reason)) return SendClientMessage(playerid,-1,"You must put a reason");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Player Is Not Connected.");
    new string[134], string2[177];
    if(Player[playerid][Hidden] == 0)
    {
        format(string,sizeof(string),"You Have Been Kicked By Administrator %s | Reason: %s", pName(playerid), reason);
        format(string,sizeof(string),"Player %s Has Been Kicked From The Server By Administrator %s | Reason: %s",pName(id),pName(playerid),reason);
    }
    else
    {
        format(string,sizeof(string),"You Have Been Kicked From The Server | Reason: %s", reason);
        format(string2,sizeof(string2),"Player %s Has Been Kicked From The Server | Reason: %s",pName(id),reason);
    }
    SendClientMessage(id, red, string);
    SendClientMessage(id, orange, "If You Think This Is A Mistake Or You Are Being Treated Unfairly, Post A Report At 'WWW.AWPGAMING.COM/FORUMS'");
    format(string,sizeof(string),"You Have Kicked %s From The Server | Reason: %s", pName(id), reason);
    SendClientMessage(playerid, yellow, string);
    format(string,sizeof(string),"Administrator %s Has Kicked Player %s | Reason: %s",pName(playerid), pName(id), reason);
    Kick(id);
    SendClientMessageToAll(red,string2);
    return 1;
}
Already solved. And your way don't works too, he wanted "No Reason" to be the default value of 'Reason', in your way you still have to complete the 'Reason' parameter.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)