Super easy Countdown command
#1

How can I create a super easy Countdown which works for everyone? It's a filterscript



pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT

#include <a_samp>
#include <TextDrawCountDown>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif



public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/cd", cmdtext, true, 10) == 0)
    {
  // Do something here
        return 1;
    }
    return 0;
}
here is the include

Code:
/*   TextDrawCountDown by Littlejohny (TextDrawCountDown)       */
/*                                      by Littlejohny                                  */
/*              **************************************          */
/*      TextDrawCountDownForPlayer(playerid, seconds)                   */
/*      TextDrawCountDownForAll(seconds)                                                */
/*      HideCountDownForPlayer(playerid)                                                */
/*      HideCountDownForAll()                                                                   */
 
#if defined _TextDrawCountDown_included
  #endinput
#endif
 
#include <a_samp>
 
#define _TextDrawCountDown_included
#pragma library TextDrawCountDown
 
#define RED 0xE60000FF
 
new tdcstr[64];
 
new PlayerText:tdcd[MAX_PLAYERS],
        pcdtime[MAX_PLAYERS],
        ptdctimer[MAX_PLAYERS],
        pCOUNT_ON[MAX_PLAYERS] = 0;
 
new cdtime,
        tdctimer,
        COUNT_ON;
 
forward TextDrawCountDownForAll(seconds);
forward TextDrawCountDownForPlayer(playerid, seconds);
forward HideCountDownForAll();
forward HideCountDownForPlayer(playerid);
forward PlayerCountTimer(playerid);
forward TextCountTimer();
 
public OnPlayerConnect(playerid)
{
    tdcd[playerid] = CreatePlayerTextDraw(playerid, 320.000000,410.000000, "TDCD");
        PlayerTextDrawTextSize(playerid, tdcd[playerid],636.000000,824.000000);
        PlayerTextDrawAlignment(playerid, tdcd[playerid], 2);
        PlayerTextDrawFont(playerid, tdcd[playerid],3);
        PlayerTextDrawLetterSize(playerid, tdcd[playerid],0.499999,1.800000);
        PlayerTextDrawColor(playerid, tdcd[playerid],0xffffffff);
        PlayerTextDrawSetProportional(playerid, tdcd[playerid],2);
        PlayerTextDrawSetShadow(playerid, tdcd[playerid],1);
        PlayerTextDrawSetOutline(playerid, tdcd[playerid], 1);
        if(funcidx("tdcd_OnPlayerConnect") != -1) return CallLocalFunction("tdcd_OnPlayerConnect", "d",playerid);
        return 1;
}
#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect tdcd_OnPlayerConnect
forward tdcd_OnPlayerConnect(playerid);
 
public TextDrawCountDownForPlayer(playerid, seconds)
{
    if(pCOUNT_ON[playerid] == 1) return 1;
 
        pcdtime[playerid] = seconds;
        if(pcdtime[playerid] < 1 || pcdtime[playerid] > 30)
        {
            pcdtime[playerid] = 0;
                return 1;
        }
        ptdctimer[playerid] = SetTimerEx("PlayerCountTimer", 1000, 1, "i", playerid);
        pCOUNT_ON[playerid] = 1;
       
        format(tdcstr,sizeof(tdcstr), "~w~CountDown: ~r~%d ~w~second/s", pcdtime[playerid]);
        pcdtime[playerid]--;
       
        PlayerTextDrawSetString(playerid, tdcd[playerid], tdcstr);
        PlayerTextDrawShow(playerid, tdcd[playerid]);
        PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
        return 1;
}
 
public TextDrawCountDownForAll(seconds)
{
        if(COUNT_ON == 1) return 1;
 
        COUNT_ON = 1;
        cdtime = seconds;
        if(cdtime < 1 || cdtime > 30)
        {
            cdtime = 0;
                return 1;
        }
        tdctimer = SetTimer("TextCountTimer", 1000, 1);
       
        format(tdcstr,sizeof(tdcstr), "~w~CountDown: ~r~%d ~w~second/s", cdtime);
        cdtime--;
       
        for (new i = 0; i < MAX_PLAYERS; i++)
        {
                if(IsPlayerConnected(i) && pCOUNT_ON[i] == 0)
                {
                        PlayerTextDrawSetString(i, tdcd[i], tdcstr);
                        PlayerTextDrawShow(i, tdcd[i]);
                        PlayerPlaySound(i, 1058, 0.0, 0.0, 0.0);
                }
        }
        return 1;
}
 
public HideCountDownForPlayer(playerid)
{
        PlayerTextDrawHide(playerid, tdcd[playerid]);
        pCOUNT_ON[playerid] = 0;
        return 1;
}
 
public HideCountDownForAll()
{
        for (new i = 0; i < MAX_PLAYERS; i++)
        {
        if(IsPlayerConnected(i) && pCOUNT_ON[i] == 0)
                {
                PlayerTextDrawHide(i, tdcd[i]);
                }
        }
        COUNT_ON = 0;
        return 1;
}
 
public TextCountTimer()
{
        if(cdtime <= 30 && cdtime >= 1)
        {
            format(tdcstr,sizeof(tdcstr), "~w~CountDown: ~r~%d ~w~second/s", cdtime);
                cdtime--;
 
            for (new i = 0; i < MAX_PLAYERS; i++)
                {
                if(IsPlayerConnected(i) && pCOUNT_ON[i] == 0)
                        {
                        PlayerTextDrawSetString(i, tdcd[i], tdcstr);
                        PlayerTextDrawShow(i, tdcd[i]);
                        PlayerPlaySound(i, 1058, 0.0, 0.0, 0.0);
                        }
                }
        }
        else if(cdtime == 0)
        {
            for (new i = 0; i < MAX_PLAYERS; i++)
                {
                if(IsPlayerConnected(i) && pCOUNT_ON[i] == 0)
                        {
                                KillTimer(tdctimer);
                                PlayerTextDrawSetString(i, tdcd[i], "~w~CountDown: ~g~GO !");
                                PlayerTextDrawShow(i, tdcd[i]);
                                PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
                        }
                }
                SetTimer("HideCountDownForAll", 3000, 0);
        }
        return 1;
}
 
public PlayerCountTimer(playerid)
{
        if(pcdtime[playerid] <= 30 && pcdtime[playerid] >= 1)
        {
            format(tdcstr,sizeof(tdcstr), "~w~CountDown: ~r~%d ~w~second/s", pcdtime[playerid]);
            PlayerTextDrawSetString(playerid, tdcd[playerid], tdcstr);
            PlayerTextDrawShow(playerid, tdcd[playerid]);
            PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
            pcdtime[playerid]--;
        }
        else if(pcdtime[playerid] == 0)
        {
                        KillTimer(ptdctimer[playerid]);
                        PlayerTextDrawSetString(playerid, tdcd[playerid], "~w~CountDown: ~g~GO !");
                        PlayerTextDrawShow(playerid, tdcd[playerid]);
                        SetTimerEx("HideCountDownForPlayer", 3000, 0, "i", playerid);
                        PlayerPlaySound(playerid, 1056, 0.0, 0.0, 0.0);
        }
        return 1;
}
Reply
#2

Find the thread for the script and read how to use it...?
Reply
#3

Quote:
Originally Posted by Bakr
View Post
Find the thread for the script and read how to use it...?
Its not a script... O_o
Reply
#4

An include is not a script? Interesting.
Reply
#5

Something like this?
https://sampforum.blast.hk/showthread.php?pid=241101#pid241101
pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT

#include <a_samp>
#include <TextDrawCountDown>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif



public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/cd", cmdtext, true, 10) == 0)
    {
  TextDrawCountDownForAll(seconds)
    Parameters:
        seconds[]   how many seconds (max 30)
        return 1;
    }
    return 0;
}
Reply
#6

He gave you the functions of the include with documentation on what they use. There are even examples later in the thread.

If you don't know how to script at all, look at one of the MANY tutorials on getting started.
Reply
#7

LOL, the function is just the first line. Parameters and seconds[] are an explanation of the code.

pawn Code:
if (strcmp("/cd", cmdtext, true) == 0)
{
    TextDrawCountDownForAll(seconds); // Replace "seconds" for the amount of seconds you want the countdown to last. Use TextDrawCountDownForPlayer(playerid, seconds) if you want to show it just to a player.
    return 1;
}
Reply
#8

wow LOL so many errors
Code:
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(40) : error 017: undefined symbol "CreatePlayerTextDraw"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(40) : warning 213: tag mismatch
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(41) : warning 217: loose indentation
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(41) : error 017: undefined symbol "PlayerTextDrawTextSize"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(42) : error 017: undefined symbol "PlayerTextDrawAlignment"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(43) : error 017: undefined symbol "PlayerTextDrawFont"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(44) : error 017: undefined symbol "PlayerTextDrawLetterSize"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(45) : error 017: undefined symbol "PlayerTextDrawColor"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(46) : error 017: undefined symbol "PlayerTextDrawSetProportional"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(47) : error 017: undefined symbol "PlayerTextDrawSetShadow"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(48) : error 017: undefined symbol "PlayerTextDrawSetOutline"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(64) : warning 217: loose indentation
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(68) : warning 217: loose indentation
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(76) : error 017: undefined symbol "PlayerTextDrawSetString"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(77) : error 017: undefined symbol "PlayerTextDrawShow"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(91) : warning 217: loose indentation
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(102) : error 017: undefined symbol "PlayerTextDrawSetString"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(103) : error 017: undefined symbol "PlayerTextDrawShow"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(112) : error 017: undefined symbol "PlayerTextDrawHide"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(123) : error 017: undefined symbol "PlayerTextDrawHide"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(135) : warning 217: loose indentation
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(137) : warning 217: loose indentation
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(141) : error 017: undefined symbol "PlayerTextDrawSetString"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(142) : error 017: undefined symbol "PlayerTextDrawShow"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(154) : error 017: undefined symbol "PlayerTextDrawSetString"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(155) : error 017: undefined symbol "PlayerTextDrawShow"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(159) : warning 217: loose indentation
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(169) : error 017: undefined symbol "PlayerTextDrawSetString"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(170) : error 017: undefined symbol "PlayerTextDrawShow"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(177) : error 017: undefined symbol "PlayerTextDrawSetString"
C:\Users\Julius\Desktop\UltimateStunting\pawno\include\TextDrawCountDown.inc(178) : error 017: undefined symbol "PlayerTextDrawShow"
C:\Users\Julius\Desktop\UltimateStunting\filterscripts\cd.pwn(40) : error 017: undefined symbol "seconds"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


24 Errors.
Reply
#9

  • Did you modify something in the include file? Replace it with the original file.
  • Are all your server files updated to SA-MP 0.3x?
  • It could be the include's fault.
Reply
#10

Quote:
Originally Posted by PHudson
View Post
  • Did you modify something in the include file? Replace it with the original file.
  • Are all your server files updated to SA-MP 0.3x?
  • It could be the include's fault.
No I didn't and yes it is 0.3x
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)