SA-MP Forums Archive
[HELP] Count Down - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Count Down (/showthread.php?tid=215625)



[HELP] Count Down - Larsey123IsMe - 23.01.2011

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;
}



Re: [HELP] Count Down - Retardedwolf - 23.01.2011

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


Re: [HELP] Count Down - Larsey123IsMe - 23.01.2011

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 =/



Re: [HELP] Count Down - Not available - 23.01.2011

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



Re: [HELP] Count Down - Larsey123IsMe - 23.01.2011

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)


Re: [HELP] Count Down - Not available - 23.01.2011

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


Re: [HELP] Count Down - Marricio - 23.01.2011

you tried...
/countdown 20 Hi!
it should be..
/countdown Hi! 20


Re: [HELP] Count Down - Not available - 23.01.2011

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


Re: [HELP] Count Down - Larsey123IsMe - 23.01.2011

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


Re: [HELP] Count Down - Marricio - 23.01.2011

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