Author Topic: TW Control  (Read 975 times)

0 Members and 1 Guest are viewing this topic.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
TW Control
« on: August 11, 2008, 04:31:14 am »
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)
Code: [Select]
// 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;
« Last Edit: August 11, 2008, 05:11:34 pm by iDante »

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: TW Control
« Reply #1 on: August 11, 2008, 05:32:55 pm »
I would like anyone to answer:
1. What other const's/commands/other stuff should I add?
- maybe: !shuffle which randomly switches players around the two teams
2. Any bugs anyone can find? I haven't extensively tested it out.
- Can't test it since I'm on Linux, I would otherwise.
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)
- Learning more about the scripting core is definitely worth the time you put into the script.
There are other worlds than these

Offline Rellik

  • Major(1)
  • Posts: 23
Re: TW Control
« Reply #2 on: August 12, 2008, 04:39:11 am »
Seen as I can only suggest commands xP

1) Maybe when there is only 5 minutes left and the server detects that each team has zero or equal points, it will stop all airstrikes, disable/destroy statguns  . and force a random weapon to all of the team members (like ak's for bravo , ruger for alpha etc...) and maybe (if possible) decide the winning team by which team has the most players in the top 3...

Lol its a bit confusing, seen as I just woke up :P

Idea #2:

Scenario: Alpha Team has 9 points out of a total of 10, Bravo Team has 2. When a team dominates the other team by 5 points or greater, the lower scoring team, can have one of its teammembers to type in his command console /gamepoint . This will then send a prvate message to the whole of blue team and the message will read something along the lines of

 "<Team Name> Has challenged you to a Gampoint Match, the first team to score wins, you have 30 seconds to vote. if you accept type /accept . If you do not accept, don't do anything"

Then the winning higher scoring team has 30 seconds to type /accept
The result will rely on the majority of votes. so 7 out of 8 people typed /accept so the match will take place.

The server will /restart so to speak, the time limit will be replenished or increased and the scores will be reset to zero. first team to score wins :D
« Last Edit: August 12, 2008, 04:57:19 am by Rellik »

Offline Peu

  • Soldier
  • **
  • Posts: 117
Re: TW Control
« Reply #3 on: August 21, 2008, 02:42:24 pm »
Seen as I can only suggest commands xP

1) Maybe when there is only 5 minutes left and the server detects that each team has zero or equal points, it will stop all airstrikes, disable/destroy statguns  . and force a random weapon to all of the team members (like ak's for bravo , ruger for alpha etc...) and maybe (if possible) decide the winning team by which team has the most players in the top 3...

throw tactics out the window at the end of the match?