I was bored so I made a script today. It is essentially TW Domination, but very accurate, far shorter (lines of code I mean, even without all of Domination's airstrike and mine stuff his is still 200+ lines. This is around 75), and less buggy.
Right now it can only do /enable, /disable, and !status (for players), so...:
I would like anyone to answer:
1. What other const's/commands/other stuff should I add?
2. Any bugs anyone can find? I haven't extensively tested it out.
3. Was it worth my time? (it was for me because I learned a lot about the scripting core, which is surprising because its so simple, but still true)
// TW Control by iDante
// Use and abuse it however you like, just leave this here.
const
TALLY_TIME = 1; // Number of seconds between checking the location of each player. The lower the more accurate, 1 minimum.
ADVERT_TIME = 30; // Number of seconds between advertising the current scores to the players.
RED_TEXT_COLOR = $FFFF0000; // Alpha team announcement colors
BLUE_TEXT_COLOR = $FF0000FF; // Bravo team announcement colors
var
teamscore, count, avg, percents, flagsX: array[1..2] of integer;
nexted, enabled: boolean;
i: integer;
// Check the location of each player and calculate his 'score'
procedure Update;
var x, t: integer;
begin
for i := 1 to 32 do
if GetPlayerStat(i, 'active') then begin
x := round(GetPlayerStat(i, 'x')); t := GetPlayerStat(i, 'team');
teamscore[t] := teamscore[t] + iif(flagsX[t] < 0, -(flagsX[t] - x), (flagsX[t] - x));
inc(count[t],1);
avg[t] := teamscore[t] / count[t];
end;
end;
// Calculates %'s for each team and reports them to the players.
procedure Report;
begin
for i := 1 to 2 do begin
percents[i] := (100*avg[i])/(avg[1]+avg[2]);
if percents[i] > 100 then percents[i] := 100;
if percents[i] < 0 then percents[i] := 0;
end;
WriteConsole(0,'Alpha''s Control: ' + inttostr(percents[1])+'%',RED_TEXT_COLOR);
WriteConsole(0,'Bravo''s Control: ' + inttostr(percents[2])+'%',BLUE_TEXT_COLOR);
end;
procedure AppOnIdle(Ticks: integer);
begin
if not nexted then begin
nexted := true;
enabled := true;
Command('/map '+CurrentMap);
end;
if enabled then begin
if Ticks mod (TALLY_TIME * 60) = 0 then Update;
if (Ticks mod (ADVERT_TIME * 60) = 0) and (not (avg[1] = 0) or not (avg[2] = 0)) then Report;
end;
end;
function OnCommand(ID: Byte; Text: string): boolean;
begin
if Text = '/enable' then enabled := true;
if Text = '/disable' then enabled := false;
end;
procedure OnPlayerSpeak(ID: Byte; Text: string);
begin
if (Text = '!status') and (enabled) then Report;
end;
procedure OnMapChange(NewMap: String);
var
x1, y1, x2, y2: Single;
begin // Report the winners, a tie is almost impossible
if enabled then begin
if (teamscore[1] > teamscore[2]) then DrawText(0,'Alpha team Won!',330,RED_TEXT_COLOR,0.15,40,240);
if (teamscore[2] > teamscore[1]) then DrawText(0,'Bravo team Won!',330,BLUE_TEXT_COLOR,0.15,40,240);
end;
GetFlagsXY(x1, y1, x2, y2); // Reset information for the next round.
flagsX[1] := round(x2); flagsX[2] := round(x1);
for i := 1 to 2 do begin
teamscore[i] := 0;
count[i] := 0;
end;
end;