Author Topic: Decimal value?  (Read 882 times)

0 Members and 1 Guest are viewing this topic.

Offline Moroes

  • Soldier
  • **
  • Posts: 165
    • Soldat-Game.eu
Decimal value?
« on: August 24, 2011, 07:28:21 am »
Hi,I am script beginner.
I was playing around with missile script.But the acceleration of missile doesnt fit to me.
Is there any way to set acceleration to number between -1 and 0?(for example -0,5)
Its on the 4th line.
Thanks

Code: [Select]
    const 
      rocketFuel = -1;   // default 45; 
      accuracy = 0; //0 - the best accuracy, default 40;   
      acceleration = -1; // 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; 

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Decimal value?
« Reply #1 on: August 24, 2011, 08:50:57 am »
-0.5

Offline Moroes

  • Soldier
  • **
  • Posts: 165
    • Soldat-Game.eu
Re: Decimal value?
« Reply #2 on: August 24, 2011, 09:02:58 am »
-0.5

What a clever trollsolution  :o .But it doesnt work...

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Decimal value?
« Reply #3 on: August 25, 2011, 01:07:03 pm »
-0.5

What a clever trollsolution  :o .But it doesnt work...
try changing interval to float