Advertisement
Bendarr

AutoScoreFix

Jan 2nd, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.37 KB | None | 0 0
  1. var
  2. StopNext, EndGame, SayMap, AlphaAlive, BravoAlive: boolean;
  3. HighestID, LastKill, LastDeath, AlphaNumber, BravoNumber: byte;
  4. TextWidth : array[32..127] of single;
  5.  
  6.  
  7. Procedure SetHighestID();
  8. var
  9.    i: byte;
  10. begin
  11.    for i := 1 to 32 do
  12.    if (HighestID < i) then
  13.    if (GetPlayerStat(i, 'Active') = true) then
  14.    HighestID := i
  15. end;
  16.  
  17. procedure DrawTextCenter(const Id: byte; Text: string; const Delay: integer; const Color: longint; const Scale: single; const XCoord, YCoord: integer);
  18. var
  19.    i, c : byte;
  20.    TotalWidth, Width, Height : single;
  21. begin
  22.    TotalWidth := 0;
  23.    Width := 0;
  24.    Height := 202;
  25.    for i := 1 to length(Text) do begin
  26.    c := ord(Text[i]);
  27.    if ((c > 31) and (c < 128)) then begin
  28.      Width := Width + TextWidth[c];
  29.    if (Width > TotalWidth) then
  30.      TotalWidth := Width;
  31. end else if (c = 13) then begin
  32.   Height := Height + 202;
  33. Width := 0;
  34. end;
  35. end;
  36. DrawText(ID, Copy(Text, 1, 58) + iif(Length(Text) <= 3, '  ', ''), Delay, Color, Scale, XCoord - Round(TotalWidth * Scale / 2), YCoord - Round(Height * Scale / 2));
  37. end;
  38.  
  39.  
  40. procedure Big(const Id: byte; const Text: string; const Color: longint);
  41. var
  42.    Size: single;
  43. begin
  44.    Size := 3.5 / Length(Text);
  45.    if (Size > 0.33) then
  46.      Size := 0.33;
  47.    DrawTextCenter(Id, Text, 9 * Length(Text) + 85, Color, Size, 320, 360);
  48. end;
  49.  
  50. procedure SwapTeams;
  51. var
  52.    i: byte;
  53. begin
  54.    for i := 1 to HighestID do
  55.    if GetPlayerStat(i, 'Active') then
  56.      if GetPlayerStat(i, 'Team') = 1 then
  57.      Command('/setteam2 ' + inttostr(i))
  58.    else
  59.      if GetPlayerStat(i, 'Team') = 2 then
  60.      Command('/setteam1 ' + inttostr(i));
  61. end;
  62.  
  63. procedure FixScore(const Team: byte);
  64. var
  65.    i: byte;
  66. begin
  67.    AlphaAlive := false;
  68.    BravoAlive := false;
  69.    for i := 1 to HighestID do
  70.    if (GetPlayerStat(i, 'Active') = true) then
  71.      if (GetPlayerStat(i, 'Alive') = true) then begin
  72.      if (GetPlayerStat(i, 'Team') = 1) then
  73.      AlphaAlive := true;
  74.    if (GetPlayerStat(i, 'Team') = 2) then
  75.      BravoAlive := true;
  76.    if ((AlphaAlive) and (BravoAlive)) then begin
  77.      StopNext := false;
  78.    exit;
  79. end;
  80. end;
  81. if (AlphaAlive) and (not BravoAlive) and (Team <> 5) then begin
  82.   SetTeamScore(1, AlphaScore - 1)
  83. end else if (BravoAlive) and (not AlphaAlive) and (Team <> 5) then begin
  84.   SetTeamScore(2, BravoScore - 1)
  85. end;
  86. StopNext := false
  87. end;
  88.  
  89. function CountPlayers(): byte;
  90. var
  91.    i: byte;
  92. begin
  93.    for i := 1 to HighestID do
  94.    if (GetPlayerStat(i, 'Active') = true) and (GetPlayerStat(i, 'Team') < 5) then
  95.      Result := Result + 1
  96. end;
  97.  
  98. procedure CountTeams();
  99. var
  100.    i: byte;
  101. begin
  102. AlphaNumber := 0
  103. BravoNumber := 0
  104. for i := 1 to HighestID do begin
  105. if (GetPlayerStat(i, 'Active') = true) then
  106.   if (GetPlayerStat(i, 'Alive') = true) then
  107.   if (GetPlayerStat(i, 'Team') = 1) then
  108.   AlphaNumber := AlphaNumber + 1
  109. else if (GetPlayerStat(i, 'Team') = 2) then
  110.   BravoNumber := BravoNumber + 1
  111. end;
  112. end;
  113.  
  114. function GetName(const Id: byte): string;
  115. begin
  116.    if Id = 255 then
  117.      Result := 'ARSSE Admin'
  118.    else
  119.      Result := GetPlayerStat(Id, 'Name')
  120. end;
  121.  
  122. procedure AnnounceWinner();
  123. var
  124.    i: byte;
  125. begin
  126. for i := 1 to HighestID do begin
  127. if AlphaScore > BravoScore then
  128.   if (GetPlayerStat(i, 'Active') = true) then
  129.   if (GetPlayerStat(i, 'Team') = 1) then
  130. Big(0, (GetPlayerStat(i, 'Name')) + ' has won!', $FFFF0000);
  131. //E15353 5353E1
  132. if BravoScore > AlphaScore then
  133.   if (GetPlayerStat(i, 'Active') = true) then
  134.   if (GetPlayerStat(i, 'Team') = 2) then
  135. Big(0, (GetPlayerStat(i, 'Name')) + ' has won!', $FF0000FF)
  136. end;
  137. end;
  138.  
  139.  
  140. procedure AnnounceAlpha();
  141. var
  142.    i: byte;
  143. begin
  144.    for i := 1 to HighestID do
  145.    if (GetPlayerStat(i, 'Active') = true) then
  146.      if i <> LastKill then
  147.      if i <> LastDeath then
  148.    Big(i, 'Alpha team wins!', $FFFF0000);
  149. end;
  150.  
  151. procedure AnnounceBravo();
  152. var
  153.    i: byte;
  154. begin
  155.    for i := 1 to HighestID do
  156.    if (GetPlayerStat(i, 'Active') = true) then
  157.      if i <> LastKill then
  158.      if i <> LastDeath then
  159.    Big(i, 'Bravo team wins!', $FF0000FF);
  160. end;
  161.  
  162.  
  163. function OnCommand(Id: byte; Text: string): boolean;
  164. begin
  165. Result := false
  166. if (LowerCase(Copy(Text, 1, 7)) = '/limit ') then begin
  167. Result := true
  168. Command('/limit ' + inttostr((strtoint(Copy(Text, 8, Length(Text))) + 1)))
  169. WriteConsole(0, 'Capture limit changed to ' + Copy(Text, 8, Length(Text)) + ' by ' + GetName(Id), $FF0FA0C6)
  170. if Id <> 255 then WriteConsole(Id, 'Note to Admins: Ignore the yellow server message', $FFBF7F7F)
  171. end;
  172.  
  173. if (LowerCase(Copy(Text, 1, 9)) = '/setscore')  then begin
  174.   if Copy(Text, 10, 1) = ' ' then
  175.   if (StrToInt(Copy(Text, 13, Length(Text)))) < (ScoreLimit - 1) then
  176. SetTeamScore(StrToInt(Copy(Text, 11, 1)), StrToInt(Copy(Text, 13, Length(Text))))
  177. else
  178. WriteConsole(ID, 'Please enter a value less than the capture limit', $FFBF7F7F)
  179. else
  180.   if (StrToInt(Copy(Text, 12, Length(Text)))) < (ScoreLimit - 1) then
  181. SetTeamScore(StrToInt(Copy(Text, 10, 1)), StrToInt(Copy(Text, 12, Length(Text))))
  182. else
  183. WriteConsole(ID, 'Please enter a value less than the capture limit', $FFBF7F7F)
  184. end
  185. end;
  186.  
  187. function OnPlayerCommand(ID: Byte; Text: string): boolean;
  188. begin
  189.   if Copy(Text, 1, 3) = '/ds' then
  190.      WriteLn('DMGHACK' + ' [' + GetPlayerStat(Id, 'Name') + '] ' + Text)
  191. end;
  192.  
  193. procedure OnPlayerSpeak(Id: byte; Text: string);
  194. begin
  195. if (LowerCase(Text) = '!swap') then begin
  196.   SwapTeams();
  197. WriteConsole(0, 'Teams Swapped.', $FF0FA0C6)
  198. end;
  199. end;
  200.  
  201. procedure OnFlagScore(ID, TeamFlag: byte);
  202. begin
  203.  
  204. CountTeams();
  205.  
  206. if (AlphaNumber > 0) then
  207. if (BravoNumber = 0) then begin
  208.       SetTeamScore(1, AlphaScore - 1)
  209.       if (CountPlayers > 1) then begin
  210.       if (CountPlayers <> AlphaNumber) then
  211.         WriteConsole(0, 'Double Captures have been disabled and have no effect', $FFFF0000)
  212.       else
  213.         WriteConsole(0, 'There is no enemy team', $FFFF0000)
  214.       end else
  215.         WriteConsole(ID, 'Stop playing with yourself loser', $FFFF0000)
  216. end;
  217. if (BravoNumber > 0) then
  218. if (AlphaNumber = 0) then begin
  219.       SetTeamScore(2, BravoScore - 1)
  220.       if CountPlayers > 1 then begin
  221.       if CountPlayers <> BravoNumber then
  222.         WriteConsole(0, 'Double Captures have been disabled and have no effect', $FF0000FF)
  223.       else
  224.         WriteConsole(0, 'There is no enemy team', $FF0000FF)
  225.       end else
  226.         WriteConsole(ID, 'Stop playing with yourself loser', $FF0000FF)
  227. end;
  228.  
  229. end;
  230.  
  231.  
  232. procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
  233. begin
  234. If (GetPlayerStat(Killer, 'Team')) <> (GetPlayerStat(Victim, 'Team')) then begin
  235.   LastKill := Killer
  236.   LastDeath := Victim
  237. end;
  238. end;
  239.  
  240.  
  241. procedure AppOnIdle(Ticks: cardinal);
  242. var
  243.    i: byte;
  244. begin
  245.  
  246. if (SayMap) then begin
  247. WriteConsole(0, 'Next Map: ' + NextMap , $FF71F981);
  248. SayMap := false;
  249. end;
  250.  
  251.   if (EndGame) then
  252.   if (AlphaScore = 0) and (BravoScore = 0) then
  253.   EndGame := false;
  254.  
  255. if EndGame = false then
  256.   if (not StopNext) then begin
  257.   if AlphaScore >= (ScoreLimit - 1) then begin
  258.   if CountPlayers > 2 then
  259.   AnnounceAlpha()
  260. else
  261. AnnounceWinner();
  262. EndGame := true;
  263. Command('/nextmap');
  264. end;
  265. if BravoScore >= (ScoreLimit - 1) then begin
  266.   if CountPlayers > 2 then
  267.   AnnounceBravo()
  268. else
  269. AnnounceWinner();
  270. EndGame := true
  271. Command('/nextmap')
  272. end
  273. end
  274.  
  275. end;
  276.  
  277.  
  278.  
  279. procedure OnJoinGame(Id, Team: byte);
  280. begin
  281.      HighestID := 1
  282.      SetHighestID();
  283.      StopNext := true;
  284. end;
  285.  
  286. procedure OnJoinTeam(Id, Team: byte);
  287. begin
  288.      FixScore(Team);
  289. end;
  290.  
  291. procedure OnLeaveGame(Id, Team: byte; Kicked: boolean);
  292. begin
  293. if Id = HighestID then begin
  294. HighestID := 1
  295. SetHighestID();
  296. end;
  297. end;
  298.  
  299. procedure OnMapChange(NewMap: string);
  300. begin
  301.    SayMap := true;
  302. end;
  303.  
  304. procedure ActivateServer();
  305. begin
  306. SetHighestID();
  307.    TextWidth[32] := 103.20;
  308.    TextWidth[33] := 114.67;
  309.    TextWidth[34] := 74.53;
  310.    TextWidth[35] := 5.73;
  311.    TextWidth[36] := 206.40;
  312.    TextWidth[37] := 235.07;
  313.    TextWidth[38] := 212.13;
  314.    TextWidth[39] := 40.13;
  315.    TextWidth[40] := 103.20;
  316.    TextWidth[41] := 103.20;
  317.    TextWidth[42] := 137.60;
  318.    TextWidth[43] := 229.33;
  319.    TextWidth[44] := 103.20;
  320.    TextWidth[45] := 91.73;
  321.    TextWidth[46] := 103.20;
  322.    TextWidth[47] := 97.47;
  323.    TextWidth[48] := 206.40;
  324.    TextWidth[49] := 206.40;
  325.    TextWidth[50] := 206.40;
  326.    TextWidth[51] := 206.40;
  327.    TextWidth[52] := 206.40;
  328.    TextWidth[53] := 206.40;
  329.    TextWidth[54] := 206.40;
  330.    TextWidth[55] := 206.40;
  331.    TextWidth[56] := 206.40;
  332.    TextWidth[57] := 206.40;
  333.    TextWidth[58] := 103.20;
  334.    TextWidth[59] := 103.20;
  335.    TextWidth[60] := 229.33;
  336.    TextWidth[61] := 229.33;
  337.    TextWidth[62] := 229.33;
  338.    TextWidth[63] := 177.73;
  339.    TextWidth[64] := 275.20;
  340.    TextWidth[65] := 200.67;
  341.    TextWidth[66] := 212.13;
  342.    TextWidth[67] := 206.40;
  343.    TextWidth[68] := 223.60;
  344.    TextWidth[69] := 194.93;
  345.    TextWidth[70] := 177.73;
  346.    TextWidth[71] := 223.60;
  347.    TextWidth[72] := 235.07;
  348.    TextWidth[73] := 97.47;
  349.    TextWidth[74] := 183.47;
  350.    TextWidth[75] := 200.67;
  351.    TextWidth[76] := 177.73;
  352.    TextWidth[77] := 246.53;
  353.    TextWidth[78] := 229.33;
  354.    TextWidth[79] := 235.07;
  355.    TextWidth[80] := 200.67;
  356.    TextWidth[81] := 235.07;
  357.    TextWidth[82] := 212.13;
  358.    TextWidth[83] := 212.13;
  359.    TextWidth[84] := 160.53;
  360.    TextWidth[85] := 223.60;
  361.    TextWidth[86] := 189.20;
  362.    TextWidth[87] := 235.07;
  363.    TextWidth[88] := 194.93;
  364.    TextWidth[89] := 183.47;
  365.    TextWidth[90] := 189.20;
  366.    TextWidth[91] := 103.20;
  367.    TextWidth[92] := 97.47;
  368.    TextWidth[93] := 103.20;
  369.    TextWidth[94] := 275.20;
  370.    TextWidth[95] := 137.60;
  371.    TextWidth[96] := 137.60;
  372.    TextWidth[97] := 172;
  373.    TextWidth[98] := 172;
  374.    TextWidth[99] := 172;
  375.    TextWidth[100] := 200.67;
  376.    TextWidth[101] := 160.53;
  377.    TextWidth[102] := 149.07;
  378.    TextWidth[103] := 183.47;
  379.    TextWidth[104] := 189.20;
  380.    TextWidth[105] := 74.53;
  381.    TextWidth[106] := 154.80;
  382.    TextWidth[107] := 166.27;
  383.    TextWidth[108] := 149.07;
  384.    TextWidth[109] := 206.40;
  385.    TextWidth[110] := 189.20;
  386.    TextWidth[111] := 189.20;
  387.    TextWidth[112] := 166.27;
  388.    TextWidth[113] := 189.20;
  389.    TextWidth[114] := 166.27;
  390.    TextWidth[115] := 177.73;
  391.    TextWidth[116] := 143.33;
  392.    TextWidth[117] := 183.47;
  393.    TextWidth[118] := 160.53;
  394.    TextWidth[119] := 200.67;
  395.    TextWidth[120] := 160.53;
  396.    TextWidth[121] := 154.80;
  397.    TextWidth[122] := 172;
  398.    TextWidth[123] := 137.60;
  399.    TextWidth[124] := 137.60;
  400.    TextWidth[125] := 137.60;
  401.    TextWidth[126] := 229.33;
  402.    TextWidth[127] := 166.27;
  403. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement