Advertisement
Guest User

For Dab

a guest
Jul 23rd, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.44 KB | None | 0 0
  1. addMessageCallback("MsgPracticeEnd", StopTimer);
  2. addMessageCallback("MsgCtfLlamaGrab", StartTimer);
  3. addMessageCallback("MsgCtfOdGrab", StartTimer);
  4. addMessageCallback("MsgCtfFlagGrab", StartTimer);
  5. addMessageCallback("MsgCtfFlagPickup", StartTimer);
  6. addMessageCallback("MsgCtfFlagThrow", StopTimerNonReset);
  7. addMessageCallback("MsgCtfFlagDrop", StopTimerNonReset);
  8. addMessageCallback("MsgCtfFlagCap", StopTimer);
  9. addMessageCallback("MsgCtfFlagReturn", StopTimer);
  10. if(!isObject(FlagTimer))
  11. {
  12.     new ScriptObject(FlagTimer)
  13.     {
  14.         FlagTakenBeta = 0;
  15.         FlagTakenAlpha = 0;
  16.         BetaTime = 0;
  17.         LastBetaTime = 0;
  18.         AlphaTime = 0;
  19.         LastAlphaTime = 0;
  20.     };
  21. }
  22. function HudUpdate(%fillervar, %fillervar, %team)
  23. {
  24.         %data = "Alpha: " TAB FlagTimer.AlphaTime NL
  25.                 "Beta:  " TAB FlagTimer.BetaTime NL
  26.                 "Last Alpha Cap: " TAB FlagTimer.LastAlphaTime NL
  27.                 "Last Beta Cap: " TAB FlagTimer.LastBetaTime;
  28.     HudOverlay.setHudElementText($HudOverlay::FlagTimer, %data);
  29. }
  30. function StartTimer(%fillervar, %fillervar, %team)
  31. {
  32.     HudUpdate();
  33.     //Get the team name, (Alph = Alpha)
  34.     $team3 = getSubStr(deTag(%team), 3, 4);
  35.     $team3 = (stripTrailingSpaces($team3));
  36.     //If its alpha, go to "StartTimerAlpha" and set the flag taken to "1".
  37.     if($team3 $= "Alph")
  38.     {
  39.         FlagTimer.FlagTakenAlpha = 1;
  40.         StartTimerAlph();
  41.     }
  42.     //If its Beta, go to "StartTimerBeta" and set the flag taken to "1".
  43.     if($team3 $= "Beta")
  44.     {
  45.         FlagTimer.FlagTakenBeta = 1;
  46.         StartTimerBeta();
  47.     }
  48. }
  49.  
  50. function StartTimerAlph()
  51. {
  52.     //If the flag is still taken, wait one second then go to "AddTimeAlph"
  53.     if(FlagTimer.FlagTakenAlpha == 1)
  54.         {  
  55.             schedule(10, 0, "AddTimeAlph");
  56.         }
  57. }
  58.  
  59. function StartTimerBeta()
  60. {
  61.     //If the flag is still taken, wait one second then go to "AddTimeBeta"
  62.     if(FlagTimer.FlagTakenBeta == 1)
  63.         {  
  64.             schedule(10, 0, "AddTimeBeta");
  65.         }
  66. }
  67.  
  68. function AddTimeAlph()
  69. {
  70.     //Here, go to function StartTimer again
  71.     FlagTimer.AlphaTime += 0.01;
  72.     HudUpdate();
  73.     StartTimerAlph();
  74. }
  75. function AddTimeBeta()
  76. {
  77.     //Here, go to function StartTimer again
  78.     FlagTimer.BetaTime += 0.01;
  79.     HudUpdate();
  80.     StartTimerBeta();
  81. }
  82. //--------------------------
  83. //Stop Functions
  84. //--------------------------
  85. function StopTimer(%fillervar, %fillervar, %stopTeam)
  86. {
  87.     HudUpdate();
  88.     //Get the team name, (Alph = Alpha)
  89.     $stopteam3 = getSubStr(deTag(%stopTeam), 3, 4);
  90.     $stopteam3 = (stripTrailingSpaces($stopteam3));
  91.     //If its Alpha, go to "StopTimeAlpha"
  92.     if($stopteam3 $= "Alph")
  93.     {
  94.         StopTimerAlpha();
  95.     }
  96.     //If its Beta, go to "StopTimeBeta"
  97.     if($stopteam3 $= "Beta")
  98.     {
  99.         StopTimerBeta();
  100.     }
  101. }
  102. //Do not reset
  103. function StopTimerNonReset(%fillervar, %fillervar, %stopTeam)
  104. {
  105.     //Get the team name, (Alph = Alpha)
  106.     $stopteam3 = getSubStr(deTag(%stopTeam), 3, 4);
  107.     $stopteam3 = (stripTrailingSpaces($stopteam3));
  108.     //If its Alpha, go to "StopTimeAlpha"
  109.     if($stopteam3 $= "Alph")
  110.     {
  111.         StopTimerNonResetAlpha();
  112.     }
  113.     //If its Beta, go to "StopTimeBeta"
  114.     if($stopteam3 $= "Beta")
  115.     {
  116.         StopTimerNonResetBeta();
  117.     }
  118. }
  119. function StopTimerAlpha()
  120. {
  121. FlagTimer.FlagTakenAlpha = 0;
  122. FlagTimer.LastAlphaTime = FlagTimer.AlphaTime;
  123. FlagTimer.AlphaTime = 0;
  124. //Stop the timer for alpha, and reset the time to 0
  125. HudUpdate();
  126. }
  127. function StopTimerNonResetAlpha()
  128. {
  129. HudUpdate();
  130. //Stop the timer for Alpha, but don't reset the time.
  131. FlagTimer.FlagTakenAlpha = 0;
  132. }
  133.  
  134. function StopTimerBeta()
  135. {
  136. //Stop the timer for beta, and reset the time to 0
  137. FlagTimer.FlagTakenBeta = 0;
  138. FlagTimer.LastBetaTime = FlagTimer.BetaTime;
  139. FlagTimer.BetaTime = 0;
  140. HudUpdate();
  141. }
  142. function StopTimerNonResetBeta()
  143. {
  144. HudUpdate();
  145. //Stop the timer for beta, but don't reset the time.
  146. FlagTimer.FlagTakenBeta = 0;
  147. }
  148. //--------------------------
  149. //HUD Code
  150. //--------------------------
  151. package FlagTimer
  152. {
  153.     function HudOverlay::AddHudElements(%this)
  154.     {
  155.         parent::AddHudElements(%this);
  156.         %index = %this.AddHudElement();
  157.         %this.setHudElementPosition(%index, 825, 10);
  158.         %this.setHudElementParent(%index, $HudElement::FlagTime);
  159.         %this.setHudElementPositionAnchor(%index, "Left", "Top");
  160.         %this.setHudElementRenderWhenDead(%index, true);
  161.         $HudOverlay::FlagTimer = %index;
  162.         %data = "Alpha Flag:     " TAB FlagTimer.AlphaTime NL
  163.                 "Beta Flag:      " TAB FlagTimer.BetaTime NL
  164.                 "Last Alpha Cap: " TAB FlagTimer.LastAlphaTime NL
  165.                 "Last Beta Cap:  " TAB FlagTimer.LastBetaTime;
  166.         HudOverlay.setHudElementText($HudOverlay::FlagTimer, %data);
  167.     }
  168. };
  169. activatepackage(FlagTimer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement