SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/09/2015, 03:35 AM   #1
Alpay0098
Huge Clucker
 
Alpay0098's Avatar
 
Join Date: Oct 2014
Location: Behind ya :o
Posts: 287
Reputation: 20
Default Countdown Timer

Hi,
How can I make a countdown timer that starts from 900 seconds to 0 second?
I need the code in the easiest level.
__________________
My works :
  • [FilterScript] Reconnect System Removed due to some reasons. P.M. me if you want it.
Alpay0098 is offline   Reply With Quote
Old 03/09/2015, 03:50 AM   #2
SickAttack
High-roller
 
Join Date: Dec 2013
Posts: 4,768
Reputation: 754
Default Re: Countdown Timer

pawn Code:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <sscanf2>
#include <zcmd>

// DEFINES:

// FUNCTIONS:

#define function%0(%1) forward%0(%1); public%0(%1)
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

// PER-PLAYER VARIABLES:

// GENERAL:

new pCountdown[MAX_PLAYERS],
pCountdownText[MAX_PLAYERS][2][128];

// TIMERS:

new tmPlayerCountdown[MAX_PLAYERS];

// MAIN:

main()
{
    print("Development Mode: player_countdown.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// COMMANDS:

CMD:playercountdown(playerid, params[])
{
    new time;
    if(sscanf(params, "i", time)) return SendClientMessage(playerid, -1, "Usage: /countdown (time in seconds).");
    if(time <= 0) return SendClientMessage(playerid, -1, "You have entered an invalid number.");

    SetPlayerCountdown(playerid, time, "Player countdown: ", "Countdown over!");
    return 1;
}

// FUNCTIONS:

stock SetPlayerCountdown(playerid, time, interval_text[], complete_text[])
{
    pCountdown[playerid] = time + 1;
    strcpy(pCountdownText[playerid][0], interval_text, 128);
    strcpy(pCountdownText[playerid][1], complete_text, 128);

    KillTimer(tmPlayerCountdown[playerid]);
    tmPlayerCountdown[playerid] = SetTimerEx("PlayerCountdown", 1000, true, "i", playerid);
    return 1;
}

function PlayerCountdown(playerid)
{
    new string[144];
    pCountdown[playerid] --;

    if(pCountdown[playerid] <= 0)
    {
        GameTextForPlayer(playerid, pCountdownText[playerid][1], 5000, 3);

        KillTimer(tmPlayerCountdown[playerid]);
    }
    else
    {
        format(string, sizeof(string), "%s%s", pCountdownText[playerid][0], ConvertToMinutes(pCountdown[playerid]));
        GameTextForPlayer(playerid, string, 5000, 3);
    }
    return 1;
}

stock ConvertToMinutes(time)
{
    new string[10], minutes, seconds;
    if(time > 59)
    {
        minutes = floatround(time / 60);
        seconds = floatround(time - minutes * 60);
        format(string, sizeof(string), "%01d:%02d", minutes, seconds);
    }
    else
    {
        seconds = floatround(time);
        format(string, sizeof(string), "0:%02d", seconds);
    }
    return string;
}

You figure out the rest, Einstein.
SickAttack is offline   Reply With Quote
Old 03/09/2015, 10:49 AM   #3
lanix
Big Clucker
 
lanix's Avatar
 
Join Date: Dec 2014
Location: Croatia
Posts: 157
Reputation: 3
Default Re: Countdown Timer

Code:
#include <a_samp>

forward test(playerid);

new timer;
new count = 900;

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp("/startcount", cmdtext, true, 11) == 0)
    {
        timer = SetTimerEx("test", 1000, 1, "d", playerid);
        return 1;
        }
    return 1;
}
public test(playerid)
{
    count--;
    if(count==0)
    {
        KillTimer(timer);
        GameTextForPlayer(playerid,"~r~Go Go Go",2000,5);
        }else{
            new string[24];
            format(string, sizeof(string), "Please wait: %d", count);
            return GameTextForPlayer(playerid, string, 100, 5);
        }
    return 1;
}
__________________
Simple Anticheat: http://forum.sa-mp.com/showthread.php?t=570399
lanix is offline   Reply With Quote
Old 03/09/2015, 10:51 AM   #4
jlalt
Banned
 
Join Date: Oct 2014
Location: Iran
Posts: 1,268
Reputation: 366
Default Re: Countdown Timer

http://forum.sa-mp.com/showthread.php?t=169023
jlalt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Countdown timer? Lajko1 Scripting Help 6 26/07/2014 03:58 PM
Countdown timer? RALL0 Scripting Help 2 17/08/2013 02:53 AM
Timer Countdown [ huge timer's ] RicaNiel Scripting Help 4 28/08/2012 12:43 PM
Timer won't Countdown!!! Tigerbeast11 Help Archive 20 24/08/2011 10:09 AM
countdown timer The Woody Help Archive 7 18/06/2011 08:33 PM


All times are GMT. The time now is 12:00 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.