Author Topic: Missle script  (Read 1108 times)

0 Members and 1 Guest are viewing this topic.

Offline arex95

  • Major(1)
  • Posts: 2
Missle script
« on: August 16, 2010, 06:32:18 am »
Hi. I'm new in scripting so I ask you... I found missle script but i don't know how to use it.
Code: [Select]
const
   rocketFuel = 45;   // default 45;
   accuracy = 40; //0 - the best accuracy, default 40;
   acceleration = 3; // default 3;
   flametraceMovement = 2; // default 2;

procedure nova(X,Y,dir_x,dir_y,r,speed,power: single; n: word; style, id: byte);
var
   angle,sine,cosine: single;
begin
   angle:=6.28318/n;
   for n:=n downto 1 do
   begin
      sine:=sin(angle*n);
      cosine:=cos(angle*n);
      CreateBullet(cosine*r + X, sine*r + Y,cosine*speed + dir_x,sine*speed + dir_y,power, style, ID);
   end;
end;

procedure Missile(owner_ID, target_ID: Byte; X, Y: Single);
{v. 1.6}
var
   poly_coll, target_coll: Boolean;
   n, interval: Word;
   X2, Y2, dist, next_dist_x, next_dist_y, prev_dist_x, prev_dist_y, rd: Single;
begin
   GetPlayerXY(target_ID,X2,Y2);
   dist:=Distance(X,Y,X2,Y2);
   next_dist_x:=(X2-X)/(dist/10);
   next_dist_y:=(Y2-Y)/(dist/10);
   X:=X + next_dist_x;
   Y:=Y + next_dist_y;
   prev_dist_x:=next_dist_x;
   prev_dist_y:=next_dist_y;
   interval:=40;
   while n < rocketFuel do
   begin
      Sleep(interval);
      next_dist_x:=((X2-X)/(dist/(20+accuracy*2))+prev_dist_x*accuracy) / (accuracy+1);
      next_dist_y:=((Y2-Y)/(dist/(24+accuracy*2))+prev_dist_y*accuracy) / (accuracy+1);
      prev_dist_x:=next_dist_x;
      prev_dist_y:=next_dist_y;
      X:=X + next_dist_x;
      Y:=Y + next_dist_y;
      GetPlayerXY(target_ID,X2,Y2);
      dist:=Distance(X,Y,X2,Y2);
      if dist > 80 then //poly dodging
      begin
         if not rayCast(X,Y,X+15,Y,rd,16) then X:=X - 15 else
            if not rayCast(X,Y,X-15,Y,rd,16) then X:=X + 15;
         if not rayCast(X,Y,X,Y+18,rd,19) then Y:=Y - 18 else
            if not rayCast(X,Y,X,Y-18,rd,19) then Y:=Y + 18;
      end;
      if dist < 25 then //check for collision
      begin
         target_coll:=true;
         break;
      end else
         if not RayCast(X,Y,X,Y,rd,1) then
         begin
            poly_coll:=true;
            break;
         end;
      if dist > 10*flametraceMovement then //create one flame
         CreateBullet(X, Y, next_dist_x/10*flametraceMovement, next_dist_y/10*flametraceMovement, 0, 5, owner_ID);
      if interval > 9 then   
         interval:=interval-acceleration; //acceleration
      n:=n+1;
   end;
   if target_coll then //collision with target
   begin
      DoDamageBy(target_ID, owner_ID, GetPlayerStat(target_ID, 'health')-1);
      nova(X,Y,next_dist_x/2,next_dist_y/2,20,5,2,7,14,owner_ID);
      nova(X2,Y2,0,0,30,8,2,9,14,owner_ID);
      nova(X2,Y2,0,0,12,-3,10,5,4,owner_ID);
   end else
      if poly_coll then   //collision with poly
      begin
         nova(X,Y,next_dist_x/2,next_dist_y/2,20,5,2,7,14,owner_ID);
         nova(X,Y,0,0,20,-3,10,4,4,owner_ID);
      end else
         begin //no fuel
            nova(X,Y,next_dist_x/3,next_dist_y/2,20,5,2,7,14,owner_ID);
            CreateBullet(X, Y, next_dist_x/2, next_dist_x/3, 10, 4, owner_ID);
         end;
end;

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Missle script
« Reply #1 on: August 16, 2010, 09:51:34 am »
Code: (pascal) [Select]
const
   rocketFuel = 45;   // default 45;
   accuracy = 40; //0 - the best accuracy, default 40;
   acceleration = 3; // default 3;
   flametraceMovement = 2; // default 2;

procedure nova(X,Y,dir_x,dir_y,r,speed,power: single; n: word; style, id: byte);
var
   angle,sine,cosine: single;
begin
   angle:=6.28318/n;
   for n:=n downto 1 do
   begin
      sine:=sin(angle*n);
      cosine:=cos(angle*n);
      CreateBullet(cosine*r + X, sine*r + Y,cosine*speed + dir_x,sine*speed + dir_y,power, style, ID);
   end;
end;

procedure Missile(owner_ID, target_ID: Byte; X, Y: Single);
{v. 1.6}
var
   poly_coll, target_coll: Boolean;
   n, interval: Word;
   X2, Y2, dist, next_dist_x, next_dist_y, prev_dist_x, prev_dist_y, rd: Single;
begin
   GetPlayerXY(target_ID,X2,Y2);
   dist:=Distance(X,Y,X2,Y2);
   next_dist_x:=(X2-X)/(dist/10);
   next_dist_y:=(Y2-Y)/(dist/10);
   X:=X + next_dist_x;
   Y:=Y + next_dist_y;
   prev_dist_x:=next_dist_x;
   prev_dist_y:=next_dist_y;
   interval:=40;
   while n < rocketFuel do
   begin
      Sleep(interval);
      next_dist_x:=((X2-X)/(dist/(20+accuracy*2))+prev_dist_x*accuracy) / (accuracy+1);
      next_dist_y:=((Y2-Y)/(dist/(24+accuracy*2))+prev_dist_y*accuracy) / (accuracy+1);
      prev_dist_x:=next_dist_x;
      prev_dist_y:=next_dist_y;
      X:=X + next_dist_x;
      Y:=Y + next_dist_y;
      GetPlayerXY(target_ID,X2,Y2);
      dist:=Distance(X,Y,X2,Y2);
      if dist > 80 then //poly dodging
      begin
         if not rayCast(X,Y,X+15,Y,rd,16) then X:=X - 15 else
            if not rayCast(X,Y,X-15,Y,rd,16) then X:=X + 15;
         if not rayCast(X,Y,X,Y+18,rd,19) then Y:=Y - 18 else
            if not rayCast(X,Y,X,Y-18,rd,19) then Y:=Y + 18;
      end;
      if dist < 25 then //check for collision
      begin
         target_coll:=true;
         break;
      end else
         if not RayCast(X,Y,X,Y,rd,1) then
         begin
            poly_coll:=true;
            break;
         end;
      if dist > 10*flametraceMovement then //create one flame
         CreateBullet(X, Y, next_dist_x/10*flametraceMovement, next_dist_y/10*flametraceMovement, 0, 5, owner_ID);
      if interval > 9 then  
         interval:=interval-acceleration; //acceleration
      n:=n+1;
   end;
   if target_coll then //collision with target
   begin
      DoDamageBy(target_ID, owner_ID, GetPlayerStat(target_ID, 'health')-1);
      nova(X,Y,next_dist_x/2,next_dist_y/2,20,5,2,7,14,owner_ID);
      nova(X2,Y2,0,0,30,8,2,9,14,owner_ID);
      nova(X2,Y2,0,0,12,-3,10,5,4,owner_ID);
   end else
      if poly_coll then   //collision with poly
      begin
         nova(X,Y,next_dist_x/2,next_dist_y/2,20,5,2,7,14,owner_ID);
         nova(X,Y,0,0,20,-3,10,4,4,owner_ID);
      end else
         begin //no fuel
            nova(X,Y,next_dist_x/3,next_dist_y/2,20,5,2,7,14,owner_ID);
            CreateBullet(X, Y, next_dist_x/2, next_dist_x/3, 10, 4, owner_ID);
         end;
end;

function OnCommand(ID: byte; Text: string): boolean;
var
X, Y: single;
begin
Result := false
if Copy(Text, 1, 8) = '/missile' then begin
try
ID := StrToInt(GetPiece(Text, ' ', 1))
GetPlayerXY(ID, X, Y)
threadfunc([ID, StrToInt(GetPiece(Text, ' ', 2)), X, Y-10], 'Missile')
except
WriteConsole(ID, 'Syntax err', $FFFF2222);
end;
end;
end;

Use this, command /missile <Shooter_ID> <Target_ID>, however i don't guarantee you stability of this.
To figure out how is command defined just compare your version with mine (in other words: look what i added @ bottom)

Ah, and you don't forget to mention somewhere that original script is by tk`
« Last Edit: August 16, 2010, 09:53:23 am by FalconPL »
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Missle script
« Reply #2 on: August 16, 2010, 10:06:03 am »
or you can use an automatic launcher aiming the missile at the nearest target
Code: (pascal) [Select]
function lookForTarget(ID: byte; MinDistance, MaxDistance: integer; UsingRaycast: boolean): byte;
var
   i,Team: byte; X,Y,X2,Y2,sqrdist,maxdist: single;
begin
   GetPlayerXY(ID,X,Y);
   maxdist:=MaxDistance*MaxDistance;
   Result:=0;
   Team := GetPlayerStat(ID, 'Team');
   for i:=1 to 32 do
      if i <> ID then
         if GetPlayerStat(i, 'Active') then
            if GetPlayerStat(i, 'Alive') then
               if GetPlayerStat(i, 'team') <> Team then
               begin
                  GetPlayerXY(i,X2,Y2);
                  if UsingRayCast then
                     if not RayCast(X,Y-7,X2,Y2-7,sqrdist,MaxDistance+1) then continue;
                  X2:=X2-X; Y2:=Y2-Y; sqrdist:=X2*X2+Y2*Y2;
                  if (sqrdist < maxdist) and (sqrdist >= MinDistance) then
                  begin
                     Result:=i;
                     maxdist:=sqrdist;
                  end;
               end;
end;

function OnCommand(ID: Byte; Text: string): boolean;
var x, y: single; target: byte;
begin
  if Text = '/aim' then begin
    target := lookForTarget(ID, 0, 700, true);
    if target > 0 then begin
      GetPlayerXY(ID, x, y);
      Missile(ID, target, x, y);
    end;
  end;
  Result := false;
end;

Offline the halo fan

  • Camper
  • ***
  • Posts: 285
  • Mustly the heat of battle is just the begining
Re: Missle script
« Reply #3 on: August 17, 2010, 07:00:19 pm »
wheres the down and instructions
« Last Edit: August 17, 2010, 07:04:27 pm by the halo fan »