JeffryUGP

Race-Timer (Upcounting, 99.9% accurate) - 2+ TDs

Feb 21st, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.78 KB | None | 0 0
  1. //At top of your script.
  2. new Race_TimeCounter[2] = {-1, ...};
  3. new Text:Race_TD[2];
  4.  
  5.  
  6. //OnFilterScriptInit/OnGameModeInit
  7. Race_TD[0] = TextDrawCreate(17.000000, 429.000000, "00:00");
  8. TextDrawBackgroundColor(Race_TD[0], 65535);
  9. TextDrawFont(Race_TD[0], 1);
  10. TextDrawLetterSize(Race_TD[0], 0.500000, 1.000000);
  11. TextDrawColor(Race_TD[0], 16777215);
  12. TextDrawSetOutline(Race_TD[0], 1);
  13. TextDrawSetProportional(Race_TD[0], 1);
  14. Race_TimeCounter[0] = SetTimerEx("UpdateTime", 200, true, "d", 0);
  15.  
  16. Race_TD[1] = TextDrawCreate(17.000000, 449.000000, "00:00");
  17. TextDrawBackgroundColor(Race_TD[1], 65535);
  18. TextDrawFont(Race_TD[1], 1);
  19. TextDrawLetterSize(Race_TD[1], 0.500000, 1.000000);
  20. TextDrawColor(Race_TD[1], 16777215);
  21. TextDrawSetOutline(Race_TD[1], 1);
  22. TextDrawSetProportional(Race_TD[1], 1);
  23. Race_TimeCounter[1] = SetTimerEx("UpdateTime", 200, true, "d", 1);
  24.  
  25. //OnPlayerConnect
  26. TextDrawShowForPlayer(playerid, Race_TD[0]);
  27. TextDrawShowForPlayer(playerid, Race_TD[1]);
  28.  
  29.  
  30. //On Bottom of your script.
  31. forward UpdateTime(id);
  32. public UpdateTime(id)
  33. {
  34.     if(RaceTimer[id] == 0)
  35.     {
  36.         TextDrawSetString(Race_TD[id], "00:00");
  37.     }
  38.     else
  39.     {
  40.         new Str[34], x[2];
  41.         new Total = GetTickCount() - RaceTimer[id];
  42.         x[0] = Total/60000;
  43.         Total -= x[0]*60000;
  44.         x[1] = Total / 1000;
  45.         Total -= x[1]*1000;
  46.         format(Str, sizeof(Str), "%02d:%02d", x[0], x[1]);
  47.         TextDrawSetString(Race_TD[id], Str);
  48.     }
  49.     return 1;
  50. }
  51.  
  52. //Replace 'id' by the id you want it to be.
  53. //Whereever you want to freeze the timer:
  54. if(Race_TimeCounter[id] != -1) KillTimer(Race_TimeCounter[id]);
  55. Race_TimeCounter[id] = -1;
  56.  
  57. //To start it again (we just prevent bugs, by checking if it runs already):
  58. if(Race_TimeCounter[id] != -1) KillTimer(Race_TimeCounter[id]);
  59. Race_TimeCounter[id] = SetTimer("UpdateTime", 200, true);
Advertisement
Add Comment
Please, Sign In to add comment