Author Topic: How to activate bot on see within a certain area.  (Read 2792 times)

0 Members and 1 Guest are viewing this topic.

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: How to activate bot on see within a certain area.
« Reply #20 on: May 17, 2009, 12:50:02 pm »
Having Max_Players global const instead of doing 1024 loops every second wouldn't be that bad. When Max_Players is 16, there will be only 256 loops.

If I'm not wrong, when we have 16 players on the server, there will be checked about 220 times if string 'Dummy' matches.

Doing this so could help a bit;
Quote
for j := 1 to 32 do
  if (i <> j) and (GetPlayerStat(j, 'Active')) then
    if GetPlayerStat(j, 'Human') = false then
      if GetPlayerStat(i, 'Team') <> GetPlayerStat(j, 'Team') then
        if IDToName(j) = 'Dummy' then begin

What is more, I would recommend using different, simple version of placebot which doesn't create dinamic arrays which may be cause of crashes.
« Last Edit: May 17, 2009, 12:52:08 pm by tk »

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: How to activate bot on see within a certain area.
« Reply #21 on: May 17, 2009, 11:57:15 pm »
Here use insted of 32 that:
Code: [Select]
function MaxID: Byte;
var i: Byte;
begin
    Result := 0;
    for i := 1 to 32 do
      if GetPlayerStat(i,'Active') = True then
        Result := i;
end;
Not tested, i did just write it so but it shold work.

I found that somewhere in MMod from Avarax sme time ago.
It will return the highest ID so you won't loop for players which aren't there.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: How to activate bot on see within a certain area.
« Reply #22 on: May 18, 2009, 05:30:01 am »
I suggest putting MaxID into a variable (well, it has no purpose if you call it more than once; would just make the speed slower)
Code: [Select]
IdHigh := MaxId();It could possibly be even better if you got the highest bot named Dummy too for the 2nd loop

Code: [Select]
function MaxId(): byte;
begin
  for Result := 32 downto 1 do
    if (GetPlayerStat(Result, 'Active') = true) then
      exit;
  Result := 0;
end;
I believe would be more efficient.
« Last Edit: May 18, 2009, 02:36:16 pm by DorkeyDear »

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: How to activate bot on see within a certain area.
« Reply #23 on: May 18, 2009, 11:40:08 am »
yeah just assign it to some var in apponidle and use the var for all your loops

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: How to activate bot on see within a certain area.
« Reply #24 on: May 18, 2009, 12:00:36 pm »
Yes But when doing this you should update the value every time a player joins or quits ;D

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: How to activate bot on see within a certain area.
« Reply #25 on: May 18, 2009, 02:02:58 pm »
Yes But when doing this you should update the value every time a player joins or quits ;D
duh, if apponidle isn't enough for you


edit: wait... yeah, makes more sense to just do it on join/quit X.x

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: How to activate bot on see within a certain area.
« Reply #26 on: May 18, 2009, 02:10:06 pm »
OnCommand (addbot) and ActivateServer (recompile) aswell

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: How to activate bot on see within a certain area.
« Reply #27 on: May 18, 2009, 03:46:08 pm »
I suggest storing dummys x / y  as variable, so appon loop needs to do only 32 (or less) checks..
Also Known As REIMA


Lol Happles (happy apples)

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: How to activate bot on see within a certain area.
« Reply #28 on: May 19, 2009, 07:33:32 am »
Quote
OnCommand (addbot)
Why? It will be checked when the bot joins a team. Yes, ActivateServer, but every scripter shoul know its better when reseting all variables on activate server, or not?

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: How to activate bot on see within a certain area.
« Reply #29 on: May 19, 2009, 07:58:34 am »
OnJoinTeam(), OnJoinGame() is not called while adding the bot.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: How to activate bot on see within a certain area.
« Reply #30 on: May 19, 2009, 08:03:50 am »
Just tested and yes you're right, that's bad that it doesn't call the two procedures :/

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: How to activate bot on see within a certain area.
« Reply #31 on: May 19, 2009, 09:50:53 am »
Ok, thx for the script :) it works fine!

The only things I need to add are these:

Witch gets kicked when she dies, Dummy respawns after this.
When the dummy get shot (from any distance)the Witch will be activated to (OnPlayerDamage ?)
                  Forum Rules   -   Search

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: How to activate bot on see within a certain area.
« Reply #32 on: May 19, 2009, 11:37:54 am »
yes, use OnPlayerDamage for this.

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: How to activate bot on see within a certain area.
« Reply #33 on: May 19, 2009, 12:22:23 pm »
yes, use OnPlayerDamage for this.

is it possible to give it kind of a "or"

In like:

When you get near OR when you shoot "dummy" do this;...
                  Forum Rules   -   Search

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: How to activate bot on see within a certain area.
« Reply #34 on: May 19, 2009, 01:47:47 pm »
Yeah just use apponidle for distance check and onplayer damage if it gets shoot :D

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: How to activate bot on see within a certain area.
« Reply #35 on: May 19, 2009, 03:49:52 pm »
IDK: I just tryed something, (Besides the two parts I didnt fill-in) is it right :)?
Could someone help me with that part?

Code: [Select]
function OnPlayerDamage(WHAT TO WRITE HERE?): AND HERE;
 
var
  i, j: byte;
  X2, Y2, DX, DY: single;
begin
  for i := 1 to 32 do
    if (GetPlayerStat(i, 'Active') = true) then
      if (GetPlayerStat(i, 'Human') = true) then begin
        for j := 1 to 32 do
          if ((i <> j) and (GetPlayerStat(j, 'Active') = true)) then
            if ((GetPlayerStat(j, 'Human') = false) and (GetPlayerStat(j, 'Name') = 'Dummy') and (GetPlayerStat(i, 'Team') <> GetPlayerStat(j, 'Team'))) then begin
              GetPlayerXY(j, X2, Y2);
                PlaceBot('Witch', GetPlayerStat(j, 'Team'), X2, Y2);
                KickPlayer(j);
              end;
            end;
      end;
end;

& on-kill (based on the taliban script from Shantec)


Code: [Select]
procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
begin
  if (IdToName(victim) = 'Witch') and (IdToName(killer) <> 'Major') then begin
WriteConsole(Killer,'You killed the Witch!',RGB(200,200,200))
Command('/Kick Witch');
  end;
end;
« Last Edit: May 19, 2009, 03:55:00 pm by D4NG3R NL »
                  Forum Rules   -   Search

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: How to activate bot on see within a certain area.
« Reply #36 on: May 20, 2009, 08:39:43 am »
Code: [Select]
function OnPlayerDamage(Victim, Shooter: byte; Damage: integer): integer;
begin
    Result := Damage // You need that otherwise you won't able to do any damage ingame!
end;

Here you go