[CMD] update command help
#1

When I use this cmd it does it like /update updates add even when i type something like /update motds motd1 textttxtxtx how do i fix this?

Код:
CMD:update(playerid, params[])
{
    // Calculating
    new Year, Month, Day, Hour, Minute, option1[32], option2[32], string[128], line, bugname[10];
    getdate(Year, Month, Day);
    gettime(Hour, Minute);
    {
        new ActualDay;
        PlayerInfo[playerid][pIDay] = ActualDay;
        PlayerInfo[playerid][pIMonth] = Month;
        PlayerInfo[playerid][pIDay] = Day;
        PlayerInfo[playerid][pIMonth] = Month;
        PlayerInfo[playerid][pIYear] = Year;
        PlayerInfo[playerid][pIHour] = Hour;
        PlayerInfo[playerid][pIMinute] = Minute;
    }
        if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
        if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
        if(strlen(params) > 128) return SendClientMessage(playerid, COLOR_GREY, "Maximum characters limit is 128.");
        if(!aDuty[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You are not on Admin Duty.");
        if(sscanf(params, "s[32]", option1))
    {
        SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update [option]");
        SendClientMessage(playerid, COLOR_GREY, "OPTIONS: updates, motds, reminders, bugs");
        return 1;
    }
    if(strcmp(option1, "updates", true))
    {
        if(sscanf(params, "s[32]s[32]", option1, option2))
        {
            SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update updates [option]");
            SendClientMessage(playerid, COLOR_GREY, "OPTIONS: add, remove");
            return 1;
        }
        if(strcmp(option2, "add", true))
        {
            if(sscanf(params, "s[32]s[32]s[100]", option1, option2, params))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update updates add [text]");
                return 1;
            }
            new File:updates=fopen("updates.cfg", io_append);
            format(string, sizeof(string), "%s - [%d/%d/%d - %d:%d]\r\n", params, PlayerInfo[playerid][pIMonth], PlayerInfo[playerid][pIDay], PlayerInfo[playerid][pIYear], PlayerInfo[playerid][pIHour], PlayerInfo[playerid][pIMinute]);
            fwrite(updates, string);
            fclose(updates);
            format(string, sizeof(string), "AdmCmd: %s has posted updates, use /updates to view it.", RPN(playerid));
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            return 1;
        }
        if(strcmp(option2, "remove", true))
        {
            if(sscanf(params, "s[32]s[32]i", option1, option2, line))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update updates remove [updateid]");
                return 1;
            }
            if(line < 1) return SendClientMessage(playerid, COLOR_GREY, "Invalid update id.");
            fdeleteline("updates.cfg", line);
            format(string, sizeof(string), "AdmCmd: %s has removed updates from /updates.", RPN(playerid));
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            return 1;
        }
        return 1;
    }
    if(strcmp(option1, "reminders", true))
    {
        if(sscanf(params, "s[32]s[32]", option1, option2))
        {
            SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update reminders [option]");
            SendClientMessage(playerid, COLOR_GREY, "OPTIONS: add, remove");
            return 1;
        }
        if(strcmp(option2, "add", true))
        {
            if(sscanf(params, "s[32]s[32]s[100]", option1, option2, params))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update reminders add [text]");
                return 1;
            }
            new File:updates=fopen("reminders.cfg", io_append);
            format(string, sizeof(string), "%s - [%d/%d/%d - %d:%d]\r\n", params, PlayerInfo[playerid][pIMonth], PlayerInfo[playerid][pIDay], PlayerInfo[playerid][pIYear], PlayerInfo[playerid][pIHour], PlayerInfo[playerid][pIMinute]);
            fwrite(updates, string);
            fclose(updates);
            format(string, sizeof(string), "AdmWarn: %s has added reminders, use /reminders to view it.", RPN(playerid));
            SendAdminMessage(COLOR_LIGHTRED, 1, string);
            return 1;
        }
        if(strcmp(option2, "remove", true))
        {
            if(sscanf(params, "s[32]s[32]i", option1, option2, line))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update reminders remove [reminderid]");
                return 1;
            }
            if(line < 1) return SendClientMessage(playerid, COLOR_GREY, "Invalid update id.");
            fdeleteline("reminders.cfg", line);
            format(string, sizeof(string), "AdmWarn: %s has removed reminders from /reminders.", RPN(playerid));
            SendAdminMessage(COLOR_LIGHTRED, 1, string);
            return 1;
        }
        return 1;
    }
    if(strcmp(option1, "bugs", true))
    {
        if(sscanf(params, "s[32]s[32]", option1, option2))
        {
            SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update bugs [option]");
            SendClientMessage(playerid, COLOR_GREY, "OPTIONS: add, remove");
            return 1;
        }
        if(strcmp(option2, "add", true))
        {
            if(sscanf(params, "s[32]s[32]s[10]s[128]", option1, option2, bugname, params))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update bugs add [bugname] [info]");
                return 1;
            }
            new File: file = fopen("bugs.cfg", io_append);
            format(string, sizeof(string), "{5BA74B}Bug: {FF6347}%s {5BA74B}- Info: %s\r\n", bugname, params);
            fwrite(file, string);
            fclose(file);
            format(string, sizeof(string), "AdmCmd: %s has added bugs, use /bugs to view it.", RPN(playerid));
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            return 1;
        }
        if(strcmp(option2, "remove", true))
        {
            if(sscanf(params, "s[32]s[32]i", option1, option2, line))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update bugs remove [bugid]");
                return 1;
            }
            if(line < 1) return SendClientMessage(playerid, COLOR_GREY, "Invalid bug id.");
            fdeleteline("bugs.cfg", line);
            format(string, sizeof(string), "AdmCmd: %s has removed bugs from /bugs.", RPN(playerid));
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            return 1;
        }
        return 1;
    }
    if(strcmp(option1, "motds", true))
    {
        if(sscanf(params, "s[32]s[32]", option1, option2))
        {
            SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update motds [option]");
            SendClientMessage(playerid, COLOR_GREY, "OPTIONS: motd1, motd2, motd3");
            return 1;
        }
        if(strcmp(option2, "motd1", true))
        {
            if(sscanf(params, "s[32]s[32]s[100]", option1, option2, params))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update motds motd1 [text]");
                return 1;
            }
	        format(ServerMOTD1, sizeof(ServerMOTD1), "%s", params);
	        format(string, sizeof(string), "AdmCmd: [motd1]%s has changed the message of the day to %s.", RPN(playerid), params);
	        SendClientMessageToAll(COLOR_LIGHTRED, string);
	        format(string, sizeof(string), "%s", params);
	     	TextDrawSetString(MainMenuTxtdraw[6], string);
            return 1;
        }
        if(strcmp(option2, "motd2", true))
        {
            if(sscanf(params, "s[32]s[32]i", option1, option2, line))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update motds motd2 [text]");
                return 1;
            }
	        format(ServerMOTD2, sizeof(ServerMOTD2), "%s", params);
	        format(string, sizeof(string), "AdmCmd: [motd2]%s has changed the message of the day to %s.", RPN(playerid), params);
	        SendClientMessageToAll(COLOR_LIGHTRED, string);
	        format(string, sizeof(string), "%s", params);
	     	TextDrawSetString(MainMenuTxtdraw[7], string);
            return 1;
        }
        if(strcmp(option2, "motd3", true))
        {
            if(sscanf(params, "s[32]s[32]i", option1, option2, line))
            {
                SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /update motds motd3 [text]");
                return 1;
            }
	        format(ServerMOTD3, sizeof(ServerMOTD3), "%s", params);
	        format(string, sizeof(string), "AdmCmd: [motd3]%s has changed the message of the day to %s.", RPN(playerid), params);
	        SendClientMessageToAll(COLOR_LIGHTRED, string);
	        format(string, sizeof(string), "%s", params);
	     	TextDrawSetString(MainMenuTxtdraw[8], string);
            return 1;
        }
        return 1;
    }
    return 1;
}
Reply
#2

Bump
Reply
#3

......
Reply
#4

ummm still need help...
Reply
#5

Sorry but i really cant get your point and i think other potential helpers might have the same problem as no one has answered yet...

Could you please explain more in detail what you are expecting this commands to do and what is not working the way you would like it to?

Thanks
Reply
#6

Okay so what it is doing is when I type for example /update motds motd1 [text here] it will ACTS as if you type /update updates add even though you don't. So what is wrong in the code for it to be making it use /updates updates add [text here] even tho you would type /update motds motd1....
Reply
#7

help....
Reply
#8

still not fixed and need help asap
Reply
#9

I still need help! PLEASE someone help me ffs
Reply
#10

pawn Код:
if(strcmp(option1, "updates", true) == 0)
Strcmp returns 0 if both strings are identical, your code was checking if strcmp returned something else than 0 by NOT specifying what the result must have been.
By default, the code inside an If-statement is executed when the expression (or comparison) is any value other than 0.

You need to add the "== 0" to every strcmp line.

You can also do this:
pawn Код:
if(!strcmp(option1, "updates", true))
Note the "!" in front of strcmp, this is a boolean NOT character to invert the result.
This would check if both string are identical, and in that case strcmp returns 0 (false).
The "!" turns this into 1 (true).

https://sampwiki.blast.hk/wiki/Strcmp
https://sampwiki.blast.hk/wiki/Using_strcmp%28%29
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)