[HELP] Count Down
#1

When i type "/countdown 20 Hi!" then the count down sart like this...
76
75
74
ect..

Why it dont count down from the number i entered?

pawn Код:
#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;
}
Reply
#2

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
Reply
#3

Quote:
Originally Posted by Retardedwolf
Посмотреть сообщение
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
Thanks :P
pawn Код:
if(sscanf(params, "ds", time, cdmessage)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /countdown (time) (message)");
//I dont see anything wrong =/
Reply
#4

I do. It should be.
pawn Код:
if(sscanf(params, "ds[128]", time, cdmessage)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /countdown (time) (message)");/
Reply
#5

Quote:
Originally Posted by Not available
Посмотреть сообщение
I do. It should be.
pawn Код:
if(sscanf(params, "ds[128]", time, cdmessage)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /countdown (time) (message)");/
Dont work, giving me the error usage:
Usage: /countdown (time) (message)
Reply
#6

Quote:
Originally Posted by Larsey123IsMe
Посмотреть сообщение
Dont work, giving me the error usage:
Usage: /countdown (time) (message)
Do you use sscanf1 and not 2?
Reply
#7

you tried...
/countdown 20 Hi!
it should be..
/countdown Hi! 20
Reply
#8

Quote:
Originally Posted by Marricio
Посмотреть сообщение
you tried...
/countdown 20 Hi!
it should be..
/countdown Hi! 20
Wrong.
Reply
#9

Quote:
Originally Posted by Not available
Посмотреть сообщение
Do you use sscanf1 and not 2?
I think i use 1
Reply
#10

pawn Код:
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;
}
im not used to dcmd but try that :S
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)