0 Members and 1 Guest are viewing this topic.
Why would you want that?
unit BulletProjectiveLine;const Gravity = 0.06; g_ = 0.135; //gravity acceleration [pixels/tick^2] k_ = 0.01; // air resistance factor ik_ = 1.0 - k_;type tTVector = record x, y, vx, vy: single; t: word; end; var WeaponSpeed: array [0..16] of single; Vec: tTVector;function BallisticAim(x1, y1, x2, y2, v, gravity: single): single; external 'ballistic_aim@aim.dll';function GetWeaponName(Weapon: Byte): String;begin case (Weapon) of 0: Result := 'USSOCOM'; 1: Result := 'Desert Eagles'; 2: Result := 'HK MP5'; 3: Result := 'Ak-74'; 4: Result := 'Steyr AUG'; 5: Result := 'Spas-12'; 6: Result := 'Ruger 77'; 7: Result := 'M79'; 8: Result := 'Barret M82A1'; 9: Result := 'FN Minimi'; 10: Result := 'XM214 Minigun'; 11: Result:= 'Combat Knife'; 12: Result:= 'Chainsaw'; 13: Result:= 'M72 LAW'; 14: Result:= 'Flamer'; 15: Result:= 'Rambo Bow'; 16: Result:= 'Flamed Arrows'; else Result := ''; end;end;procedure CastAndDraw(x, y, g: single; var vec: tTVector; CheckPlayerOnly, CheckBulletOnly: boolean);var x2, y2: single;begin while vec.t > 0 do begin vec.t := vec.t - 1; x2 := x; x := x + vec.vx; vec.vx := vec.vx * ik_; vec.vy := vec.vy + g; y2 := y; y := y + vec.vy; vec.vy := vec.vy * ik_; if Map.RayCast(x, y, x2, y2, CheckPlayerOnly, false, CheckBulletOnly, CheckBulletOnly, 0) then begin vec.X := x2; vec.Y := y2; Players.WorldText(vec.t, '.', 60, $33CC00, 0.09, x-3, y-25); exit; end else begin Players.WorldText(vec.t, '.',60, $FF0000, 0.08, x-3, y-25); end; end; vec.X := x2; vec.Y := y2;end;procedure DrawBulletProjectiveLines(Player: TActivePlayer);var Speed, Angle: single;begin if (Player.Primary.WType<>255) then begin Speed := WeaponSpeed[Player.Primary.WType]; Angle := BallisticAim(Player.X, Player.Y, single(Player.MouseAimX), single(Player.MouseAimY), Speed, Gravity); Vec.vx := (cos(angle)*Speed); Vec.vy := (sin(angle)*Speed); Vec.T := 400; CastAndDraw(Player.X, Player.Y, g_*Gravity/Gravity, vec, true, true); end;end;procedure Check(Ticks: integer);var i:byte;begin for i := 1 to 32 do if (Players[i].Active) then if ((Players[i].Alive) and (Players[i].IsAdmin)) then DrawBulletProjectiveLines(Players[i]); Players[1].WorldText(401, 'O', 60, $DCB2010, 0.10, single(Players[1].MouseAimX)-8, single(Players[1].MouseAimY)-23);end;procedure ReadWeaponsSpeed();var i: byte; WeaponINI: TIniFile;begin if (Game.Realistic) then WeaponINI := File.CreateINI('weapons.ini') else WeaponINI := File.CreateINI('weapons_realistic.ini'); for i := 0 to 16 do WeaponSpeed[i] := (WeaponINI.ReadInteger(GetWeaponName(i), 'Speed', 0)/10);end;begin ReadWeaponsSpeed(); Game.TickThreshold := 1; Game.OnClockTick := @Check;end.
Angle := BallisticAim(Player.X, Player.Y, single(Player.MouseAimX), single(Player.MouseAimY), Speed, Gravity);
Angle := arctan2(Player.X - single(Player.MouseAimX), Player.Y - single(Player.MouseAimY));
Angle := arctan2(-Player.X + single(Player.MouseAimX), -Player.Y + single(Player.MouseAimY));