#include <a_samp>
#include <sscanf>
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
forward Counter();
new CountdownTimer = -1;
new CountDownMessage[256];
new Counttime;
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(countdown, 9, cmdtext);
return 0;
}
dcmd_countdown(playerid, params[])
{
new time, cdmessage;
if(CountdownTimer != -1) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Countdown already started!");
if(sscanf(params, "ds", time, cdmessage)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /countdown (text) (message)");
Counttime = time;
format(CountDownMessage, 128, "%s", cdmessage);
CountdownTimer = SetTimer("Counter", 1000, true);
return 1;
}
public Counter()
{
Counttime--;
if(Counttime <= 0)
{
GameTextForAll(CountDownMessage, 1500, 3);
KillTimer(CountdownTimer);
CountdownTimer = -1;
}
else
{
new string[256];
format(string, 10, "%d", Counttime);
GameTextForAll(string, 2000, 3);
}
return 1;
}
You're creating a string with 256 characters / len and later formatting it only with 128 characters / len isn't that a waste and at the last part you're creating a string with 256 len / char and only formatting 10 char / len.
EDIT:: Mistake at sscanf line. Check the SCM part |
if(sscanf(params, "ds", time, cdmessage)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /countdown (time) (message)");
//I dont see anything wrong =/
if(sscanf(params, "ds[128]", time, cdmessage)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /countdown (time) (message)");/
I do. It should be.
pawn Код:
|
Dont work, giving me the error usage:
Usage: /countdown (time) (message) |
you tried...
/countdown 20 Hi! it should be.. /countdown Hi! 20 |
dcmd_countdown(playerid, params[])
{
new time, cdmessage;
if(CountdownTimer != -1) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Countdown already started!");
if(sscanf(params, "ds", time, cdmessage)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /countdown (text) (message)");
Counttime = strval(params);
format(CountDownMessage, 128, "%s", cdmessage);
CountdownTimer = SetTimer("Counter", 1000, true);
return 1;
}