Author Topic: working on stronger bots..  (Read 1479 times)

0 Members and 1 Guest are viewing this topic.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
working on stronger bots..
« on: November 09, 2009, 01:10:47 pm »
The basic idea of this script goes to Gizds Special Bots Script on which this one is based. I have just pick up his script and overworked all the functions/procedures to make it work better and also added some new things! (later..)

Code: [Select]
const

classes = 1; // Set this to the numbers of bots you want to use

type
Bots = record
  health, healthleft, output, input, bonus, bonustimer, bonuscool, reg, regtimer, regcool: integer;
  name: string;
  showhealth: boolean;
  weapon: byte;
          healthcolor: longint;
end;

var
Bot: Array [1..32] of Bots;
        createbot: array [0..classes] of Bots;

procedure ActivateServer();
begin
  // This will be given to any players!
  createbot[0].name              := '';
  createbot[0].health            := 0;
  createbot[0].weapon            := 255;
  createbot[0].output            := 10000;
  createbot[0].input             := 10000;
  createbot[0].bonus             := 0;
  createbot[0].bonustimer        := 0;
  createbot[0].reg               := 0;
  createbot[0].regtimer          := 0;
  createbot[0].showhealth        := False;
  createbot[0].healthcolor       := $FFFFFF;

  createbot[1].name              := 'you cant see me';  // The Name of the Bot
  createbot[1].health            := 800;                // The Health of the Bot ( 150 in normal, 65 in realistic game mode)
  createbot[1].weapon            := 255;                // The Weapon the Bot will carry
  createbot[1].output            := 10000;              // Damage Increase in 100.00%
  createbot[1].input             := 10000;              // Damage Decrease in 100.00%
  createbot[1].bonus             := 1;                  // Bonus the Bot will gain ( 1 Predator; 2 Berserker; 3 Vest; 4 Nades;  5 Cluster Nades;
  createbot[1].bonustimer        := 20;                 // The interval (seconds) in which the bot will gain the bonus; granted automaticly on respawn.
  createbot[1].reg               := 8;                  // Health the Bot will regenerate (0 to disable regeneration!)
  createbot[1].regtimer          := 1;                  // The regeneration rate in seconds (0 to disable regeneration!)
  createbot[1].showhealth        := True;               // True to display the health to the shooter, false to disable it
  createbot[1].healthcolor       := $F3F8F6;            // The color the health will shown when showhealth is true
end;

function str(value: variant): string;
begin
  case VarType(value) of
    3:     Result := IntToStr(value);
    5, 17: Result := FloatToStr(value);
    256:   Result := value;
  end;
end;

function Assignable(ID: byte): boolean;
var i: byte;
begin
  Result := False;
  for i := 1 to classes do begin
    if GetPlayerStat(ID,'Human') = False then begin
      if IDToName(ID) = createbot[i].name then begin
        Result := True;
      end;
    end;
  end;
end;

procedure Assign(ID: Byte);
var i: byte;
begin
  if Assignable(ID) then begin
    for i := 1 to classes do begin
      if IDToName(ID) = createbot[i].name then begin
        Bot[ID] := createbot[i];
      end;
    end;
  end else
    Bot[ID] := createbot[0];
end;

procedure DisplayHealth(Victim, Shooter: byte);
begin
  if Bot[Victim].showhealth then begin
    DrawText(Shooter, str(Bot[Victim].healthleft) + ' Health', 200, Bot[Victim].healthcolor, 0.08, 260, 350);
  end;
end;

procedure Regenerate(ID: byte);
begin
  if Bot[ID].healthleft > 0 then begin
    Bot[ID].healthleft := Bot[ID].healthleft + Bot[ID].reg;
    if Bot[ID].healthleft > Bot[ID].health then begin
      Bot[ID].healthleft := Bot[ID].health;
    end;
  end;
end;

procedure DamageBot(Victim, Shooter: byte; Damage: integer);
begin
  if Bot[Victim].healthleft > 0 then begin
    if Damage < 5000 then begin
      Bot[Victim].healthleft := Bot[Victim].healthleft - Damage;
    end else
    begin
      Bot[Victim].healthleft := Bot[Victim].healthleft - Round(Damage / 75);
    end;
    if Bot[Victim].healthleft < 1 then begin
      DoDamageBy(Victim, Shooter, 200);
    end;
  end;
end;

procedure AppOnIdle(Ticks: integer);
var i: byte;
begin
  for i := 1 to 32 do begin
    if Assignable(i) then begin

      // Bonus Stuff
      if ((Bot[i].bonus <> 0) and (Bot[i].bonus <> 255) and (Bot[i].bonustimer <> 0)) then begin
        if Bot[i].bonuscool > 0 then begin
          Bot[i].bonuscool := Bot[i].bonuscool - 1;
        end else
        begin
          Bot[i].bonuscool := Bot[i].bonustimer - 1;
          GiveBonus(i,Bot[i].bonus);
        end;
      end;

      // Weapon Stuff
      if Bot[i].Weapon <> 255 then begin
        if GetPlayerStat(i,'Primary') <> Bot[i].Weapon then begin
          ForceWeapon(i,Bot[i].Weapon,0,0);
        end;
      end;

      // Regeneration Stuff
      if ((Bot[i].reg > 0) and (Bot[i].regtimer > 0) and (Bot[i].healthleft > 0) and (Bot[i].healthleft < Bot[i].health)) then begin
        if Bot[i].regcool > 0 then begin
          Bot[i].regcool := Bot[i].regcool - 1;
        end else
        begin
          Bot[i].regcool := Bot[i].regtimer - 1;
          Regenerate(i);
        end;
      end;

    end;
  end;
end;

procedure OnPlayerRespawn(ID: Byte);
begin
  if Assignable(ID) then begin

    // Check if the bot is already assigned
    if IDToName(ID) <> Bot[ID].name then begin
      Assign(ID);
    end;

    // Check if the bot has bonus enabled and give him 1 second after respawn
    if ((Bot[ID].Bonus <> 255) and (Bot[ID].Bonus <> 0)) then begin
      Bot[ID].bonustimer := 1;
      Bot[ID].regcool    := Bot[ID].regtimer;
    end;

    // Check if the bot carries the right weapon
    if Bot[ID].Weapon <> 255 then begin
      if GetPlayerStat(ID,'Primary') <> Bot[ID].weapon then begin
        ForceWeapon(ID, Bot[ID].weapon, 255, 0);
      end;
    end;

  end;
end;

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer): integer;
var dmg: integer;
begin
  Result := Damage;

  if ((Assignable(Shooter)) and (Assignable(Victim))) then begin
    dmg := Round(Damage * Bot[Victim].input * Bot[Shooter].output / 100000000);
    DamageBot(Victim,Shooter,dmg);
    Result := -Damage;
    exit;
  end else
  begin
    if ((not Assignable(Shooter)) and (Assignable(Victim))) then begin
      dmg := Round(Damage * Bot[Victim].input / 10000);
      DamageBot(Victim,Shooter,dmg);
      DisplayHealth(Shooter, Victim);
      Result := -Damage;
      exit;
    end else
    begin
      if ((Assignable(Shooter)) and (not Assignable(Victim))) then begin
        dmg := Round(Damage * Bot[Shooter].output / 10000);
        Result := dmg;
        exit;
      end else
      begin
        if ((not Assignable(Shooter)) and (not Assignable(Victim))) then begin
          Result := Damage;
          exit;
        end;
      end;
    end;
  end;
end;

The problem is that DisplayHealth won't executet somehow and i have no idea why ( i also tried to kill him, 5 barret shots, didn't die..), it seems to be in OnPlayerDamage()
 (btw. when danmer, or someone else reads this who knows about the damage mod i am using here, tell me if i done it right so far)
Maybe i just forgot something but i haven't found the fault yet!
« Last Edit: November 10, 2009, 10:49:43 am by y0uRd34th »

Offline Neosano

  • Camper
  • ***
  • Posts: 253
  • IIAWAK!
Re: ProBots - working on stronger bots =)
« Reply #1 on: November 09, 2009, 03:28:28 pm »
Danmer is too lazy to read this.
Maybe if you'll give him some beer...
KAWAAAAAAAIIIIIIIIII

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: ProBots - working on stronger bots =)
« Reply #2 on: November 10, 2009, 12:30:42 am »
I didnt read over your code in great detail, but i suggest you use a different method for the damage. Gizd's old way doesnt allow for bots to bleed and get health packs like they normally would. But my method does. Try this if you want:
Code: [Select]
function IntToFloat(Num: integer): single;
begin
result := strtofloat(inttostr(num));
end;

result := round(inttofloat(damage)*(150/inttofloat(+sbot[victim].maxhealth)));

(you need the inttofloat function)
Here is how I calculate and show the health:
Code: [Select]
function CharMultiply(char: string; times: variant): string;
var u: integer;
begin
result := '';
for u := 1 to round(times) do begin
result := (result + char);
end;
end;

// needs the aforementioned function inttofloat()
function GPH(ID: byte): integer;
begin
result := round(inttofloat(getplayerstat(ID,'health'))*(inttofloat(sbot[ID].maxhealth)/150));
end;

// VERY stripped down, prone to errors/typos
procedure DrawHp(ID,HPTarget: byte);
var hp,hp2,hpam: string; times,timesvest,maxtimes: integer;
begin
if getplayerstat(hptarget,'health') > 0 then begin
maxtimes := 15;
times := round(maxtimes/(150/inttofloat(getplayerstat(hptarget,'health'))));
if getplayerstat(hptarget,'vest') > 0 then timesvest := round((maxtimes div 2)/(100/inttofloat(getplayerstat(hptarget,'vest'))));
hp := '   '+(getplayerstat(hptarget,'name')+' : ('+charmultiply('/',times)+charmultiply('-',maxtimes-times)+')'+iif(timesvest>0,' - ('+charmultiply('/',timesvest)+charmultiply('-',(maxtimes div 2)-timesvest)+')',''));
hpam := inttostr(gph(hptarget))+'/'+inttostr(sbot[hptarget].maxhealth)
hp2 := '   '+charmultiply(' ',(inttofloat(length(hp)) div 2)-(inttofloat(length(hpam)) div 2))+hpam;
end else begin
hp := '';
hp2 := '';
end;
drawtext(ID,hp+chr(13)+chr(10)+hp2,300,$ffffffff,0.06,15,350);
end;

Sorry for any typos in the code, I had to rip all the other elements out of it that my script uses. And sorry i didnt directly answer your origanal question.


Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: ProBots - working on stronger bots =)
« Reply #3 on: November 10, 2009, 01:07:41 am »
yes, thank you, i wanted to add that later too, but first i wanted to make the basics :)

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: ProBots - working on stronger bots =)
« Reply #4 on: November 10, 2009, 07:53:17 am »
Quote
Code: [Select]
function IntToFloat(Num: integer): single;
begin
result := strtofloat(inttostr(num));
end;

result := round(inttofloat(damage)*(150/inttofloat(+sbot[victim].maxhealth)));

(you need the inttofloat function)
Whats the point of using IntToFloat btw?
« Last Edit: November 10, 2009, 07:55:06 am by tk »

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: ProBots - working on stronger bots =)
« Reply #5 on: November 10, 2009, 07:56:36 am »
Don't base on my like 1 year old script...

If you wish I can make "modern" version of this script :)
« Last Edit: November 10, 2009, 08:01:27 am by Gizd »

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: ProBots - working on stronger bots =)
« Reply #6 on: November 10, 2009, 09:51:05 am »
=/ the problem is, i haven't found another resolution for assign() and assignable() yet, if I had it wouldnt be that much than your script :p
And making your one "modern", would really nice from you, but my problem is (I maybe want to make
a Zombie scirpt with this I am working on, thats why i startet "remaking" this) i can't work with
other peoples coded script very well in my own ones.. i hope you understand me

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: working on stronger bots..
« Reply #7 on: November 10, 2009, 04:27:10 pm »
I'll rewrite it after 1.5.1 comes out.