13.07.2013, 13:10
How can I create a super easy Countdown which works for everyone? It's a filterscript
here is the include
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;
}
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; }