Author Topic: Reward Flagger  (Read 1545 times)

0 Members and 1 Guest are viewing this topic.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Reward Flagger
« on: June 12, 2008, 10:22:30 pm »
Script Name: Reward Flagger... Sucks but whatever.
Script Description: Every x seconds the flagger is given a settable amount of points. It'll prolly be on an htf server if I ever make one. If its been made before (prolly has) then... whatever.
Original Author(s): Me.
Core Version: The latest one.
Code:
Code: [Select]
const
  TimeBetweenBonus = 10;
  BonusPoints = 1;

var
  FlagCapped: Boolean;
  FlagCarrier, BonusTimer: Integer;

procedure ActivateServer();
begin
  FlagCapped := False;
  BonusTimer := 0;
end;

procedure AppOnIdle(Ticks: integer);
begin
  if FlagCapped then begin
    if GetPlayerStat(FlagCarrier,'Flagger') then begin
      inc(BonusTimer, 1);
      if (BonusTime mod TimeBetweenBonus = 0) then SetScore(FlagCarrier,GetPlayerStat(FlagCarrier,'kills')+BonusPoints);
    end else begin
      FlagCapped := False;
      BonusTime := 0;
    end;
  end;
end;

procedure OnFlagGrab(ID, TeamFlag: byte;GrabbedInBase: boolean);
begin
  FlagCapped := True;
  FlagCarrier := ID;
end;

BTW I'm pretty new to scripting so if there's anything in my code that needs fixing/improving then tell me. Thanks.
« Last Edit: June 13, 2008, 02:28:56 pm by iDante »

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Reward Flagger
« Reply #1 on: June 13, 2008, 05:34:22 am »
Seems simple and pretty good.
First about the layout, instead of using a tab; just do two spaces, saves up some room. Also it would be nice if you added an extra line between different procedures and const/var.
Like you said it will prolly be for htf, note that this code wont work for ctf, since there can be only one FlagCarrier at the same time.

This seems double (if not triple, think about it):
Code: [Select]
if FlagCapped = True then begin
  if GetPlayerStat(FlagCarrier,'Flagger') = True then begin
    if FlagCapped = True then
If the player is flagger, then the flag is automatically capped, no?

This piece of code stands one tab too far:
Code: [Select]
if GetPlayerStat(FlagCarrier,'Flagger') = False then
  FlagCapped := False;
Also, don't forget to put BonusTimer back on zero here!

Code: [Select]
BonusTimer := BonusTimer+1;
you can use inc(BonusTimer, 1) here

mweh.. you know what, here:
Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
  if FlagCapped then begin
    if GetPlayerStat(FlagCarrier,'Flagger') then begin
      inc(BonusTimer, 1);
      if (BonusTime mod TimeBetweenBonus = 0) then SetScore(FlagCarrier,GetPlayerStat(FlagCarrier,'kills')+BonusPoints);//mod = modulo, look it up
    end else begin
      FlagCapped := False;
      BonusTime := 0;
    end;
  end;
end;

:D hope i helped
Come join: EliteCTF
Listen to: My Music

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Reward Flagger
« Reply #2 on: June 13, 2008, 02:26:50 pm »
Thanks, you did.

I have a question, is there a limit to how much can happen in AppOnIdle()? because it seems like if it runs every second it might slow down the server if too much is happening in it.

Edit: I noticed you changed
Code: [Select]
if (BonusTime = TimeBetweenBonus)to
Code: [Select]
if (BonusTime mod TimeBetweenBonus = 0)
is there an important difference I'm missing?
« Last Edit: June 13, 2008, 02:30:22 pm by iDante »

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Reward Flagger
« Reply #3 on: June 20, 2008, 05:33:28 pm »
Thanks, you did.

I have a question, is there a limit to how much can happen in AppOnIdle()? because it seems like if it runs every second it might slow down the server if too much is happening in it.

For computers a second is a lot, you probably do in it what you like.


Edit: I noticed you changed
e
Code: [Select]
if (BonusTime = TimeBetweenBonus)to
Code: [Select]
if (BonusTime mod TimeBetweenBonus = 0)
is there an important difference I'm missing?

If you use BonusTime=TimeBetweenBonus you will have to reset bonustime to zero. after every loop.
BonusTime mod TimeBetweenBonus=0 will check if the residu of BonusTime/TimeBetweenBonus is 0(modulo). BonusTime will continue to grow but whenever it is a multiple of TimeBetweenBonus the modulo will be 0. Google modulo for more info.
Come join: EliteCTF
Listen to: My Music

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Reward Flagger
« Reply #4 on: June 20, 2008, 07:48:46 pm »
If you use BonusTime=TimeBetweenBonus you will have to reset bonustime to zero. after every loop.
BonusTime mod TimeBetweenBonus=0 will check if the residu of BonusTime/TimeBetweenBonus is 0(modulo). BonusTime will continue to grow but whenever it is a multiple of TimeBetweenBonus the modulo will be 0. Google modulo for more info.
0.o thanks again. If there was still karma you would have +2 by now :)