SA-MP Forums Archive
Returning unknown command. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Returning unknown command. (/showthread.php?tid=601637)



Returning unknown command. - -CaRRoT - 24.02.2016

Hello, I've spent a good amount of time rewriting this command through different ways but I still get the same result every time which is unknown command, am not sure if I am just tired and that the error is right infront of me or that it's something else.

Here's the command..

Код:
CMD:tempban(playerid, params[])
{
	new id[24], days, reason[128], banner[128];
	if(pInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You're not authorized to use this command.");
	if(sscanf( params, "s[24]is[128]", id, days, reason)) return SCM(playerid, -1, "USAGE: /tempban [player name] [days] [reason]");
	new filestring[79],  exp = gettime()+(60*60*24*days);
	format(filestring, sizeof(filestring), "/Users/%s.ini", id);
	if(!fexist(filestring)) return SCM(playerid, COLOR_RED, "This username doesnt exist! ");
	else
	{
		new INI:File = INI_Open(filestring);
  		INI_SetTag(File, "User Data");
		INI_WriteInt(File, "pBanned", 1);
		INI_WriteInt(File, "pBannedExp",exp);
		INI_Close(File);
	}
	format(banner, sizeof(banner), "You have banned %s from the server for %d days.", id, days);
	SCM(playerid, COLOR_RED, banner);
	format(banner, sizeof(banner), "%s has been temporarily banned by %s %s for %d days | Reason: %s", id, AdminRank(playerid), RemoveUnderScore(playerid), days, reason);
	SCMToAll(COLOR_RED, banner);
	return 1;
}
I open/close the file using the same way to ban offline player and it works fine.


Re: Returning unknown command. - Threshold - 24.02.2016

I tried rearranging the code and making some unnecessary arrays smaller, and came to this:
pawn Код:
CMD:tempban(playerid, params[])
{
    if(pInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You're not authorized to use this command.");

    new
        id[24],
        days,
        reason[60]
    ;

    if(sscanf(params, "s[24]is[60]", id, days, reason)) return SCM(playerid, -1, "USAGE: /tempban [player name] [days] [reason]");

    new filestring[40];

    format(filestring, sizeof(filestring), "/Users/%s.ini", id);
    if(!fexist(filestring)) return SCM(playerid, COLOR_RED, "This username doesnt exist! ");

    new
        exp = gettime() + (86400 * days),
        INI:File = INI_Open(filestring),
        banner[144]
    ;

    INI_SetTag(File, "userdata");
    INI_WriteInt(File, "pBanned", 1);
    // Code ends here, returns error.
    INI_WriteInt(File, "pBannedExp", exp);
    INI_Close(File);
    format(banner, sizeof(banner), "You have banned %s from the server for %d days.", id, days);
    SCM(playerid, COLOR_RED, banner);
    format(banner, sizeof(banner), "%s has been temporarily banned by %d %d for %d days | Reason: %s", id, AdminRank(playerid), RemoveUnderScore(playerid), days, reason);
    SCMToAll(COLOR_RED, banner);
    return 1;
}
The code abruptly ends before the INI_WriteInt, mainly because the integer you are trying to save is too large. I just ran the code and I got this integer:
Код:
exp = 1456387343
That was a 1 day ban. (Which reminds me, you should also add checks to see whether day is below 1...)

So, as annoying as it is, you should find an alternative method to 'gettime' and then adding on the seconds.

Here's my version of the code:
pawn Код:
CMD:tempban(playerid, params[])
{
    if(pInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You're not authorized to use this command.");

    new
        id[24],
        days,
        reason[60]
    ;

    if(sscanf(params, "s[24]is[60]", id, days, reason)) return SCM(playerid, -1, "USAGE: /tempban [player name] [days] [reason]");
    if(days < 1) return SCM(playerid, COLOR_RED, "Ban duration needs to be at least 1 day or more.");
    new filestring[40];

    format(filestring, sizeof(filestring), "/Users/%s.ini", id);
    if(!fexist(filestring)) return SCM(playerid, COLOR_RED, "This username doesn't exist! ");

    new
        exp = gettime() + (86400 * days),
        INI:File = INI_Open(filestring),
        banner[144]
    ;
    INI_SetTag(File, "userdata");
    INI_WriteInt(File, "pBanned", 1);
    // WriteInt and gettime() do not mix well, mainly because gettime returns such a large integer. Alternative methods will need to be used.
    INI_WriteInt(File, "pBannedExp", exp);
    INI_Close(File);
    format(banner, sizeof(banner), "You have banned %s from the server for %d days.", id, days);
    SCM(playerid, COLOR_RED, banner);
    format(banner, sizeof(banner), "%s has been temporarily banned by %d %d for %d days | Reason: %s", id, AdminRank(playerid), RemoveUnderScore(playerid), days, reason);
    SCMToAll(COLOR_RED, banner);
    return 1;
}



Re: Returning unknown command. - -CaRRoT - 24.02.2016

So what alternative methods do you suggest to save the integer?


Re: Returning unknown command. - Nero_3D - 24.02.2016

There had been a problem with WriteInt because it used valstr which has problems with large numbers
But the latest version of y_ini doesn't have that problem so using gettime should be a fine


Re: Returning unknown command. - Threshold - 25.02.2016

Time to update my y_ini I guess :P