Problem with /settime command
#1

Im having issues with this command, i do not receive any errors when i try to compile, but once i get in-game and try to set the server time, it's always sending me the error message "You may only set valid hours between 0 and 23" instead of setting the server time, help plz.


pawn Код:
CMD:settime(playerid, params[])
{
new pTI, string[128];
if(pInfo[playerid][Level] < 1) return SendClientMessage(playerid, 0xFF0000AA, "[ERROR]You are not authorized to use this command.");
if(sscanf(params, "u", pTI)) return SendClientMessage(playerid, 0xFF0000AA, "[USAGE]: /settime <time>.");
if(pTI > 24 || pTI > 0) return SendClientMessage(playerid, 0xFF0000AA, "You may only set valid hours between 0 and 23");
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerTime(i, pTI, 0);
}
format(string, sizeof(string), "World time has been set to %d", pTI);
SendClientMessageToAll(0x10F441AA, string);
return 1;
}
There's the code!
Reply
#2

pawn Код:
if(pTI > 24 || pTI < 0)
That's good. You gave statement "if pTI is larger than 24 or if it's LARGER than 0. Should be Smaller than 0. Cheers.
Reply
#3

From what I can see, your "u" in your sscanf should be either "i" or "d"
Reply
#4

pawn Код:
if(pTI > 24 || pTI < 0)
I just fixed, but i still receive the same error message.

Damnit @MattyG, true story.

Thank you guys for the help, its fixed!
Reply
#5

Try this:
Код:
// this line verify if the time is invalid ... "time < 0" || "time >= 24"
if(pTI >= 24 || pTI < 0) {
   return SendClientMessage(playerid, 0xFF0000AA, "You may only set valid hours between 0 and 23");
}
// only the value 0, 1, ..., 22, 23 will reach here
Your code:
Код:
// this line verify if the time is valid ... "time > 0" is ok ...
// but you continue whit this "time > 24" make no sens for your purpose ...
if(pTI > 24 || pTI > 0) {
   return SendClientMessage(playerid, 0xFF0000AA, "You may only set valid hours between 0 and 23");
}
// only the value -1, -2, -3, etc will reach here
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)