Author Topic: [Request] Looking for Shoot() procedure  (Read 668 times)

0 Members and 1 Guest are viewing this topic.

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
[Request] Looking for Shoot() procedure
« on: June 30, 2009, 02:25:51 pm »
Hai all!
I'm currentyl working on my Zombie Remake 1.3b for my server, and i need a procedure that shoots from point A to point B, example:
Code: [Select]
Shoot(GetPlayerStat(id, 'x'), GetPlayerStat(id, 'y'), GetPlayerStat(Player, 'x'), GetPlayerStat(Player, 'y')...);not like Veloircity, anyway: Who will help will be added to my Credits list on my zombie server ^^

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: [Request] Looking for Shoot() procedure
« Reply #1 on: June 30, 2009, 02:52:15 pm »
there you go (copied from MMod by Avarax)

Code: [Select]
function Aim(const X1,Y1,X2,Y2: single) : single;
begin
  if (X2 - X1)<>0 then begin
    if X1 > X2 then
      result:= arctan((y2 - y1) / (x2 - x1)) + Pi
    else
      result:= arctan((y2 - y1) / (x2 - x1));
  end
  else begin
    if Y2 > Y1 then result:= Pi/2 + Pi/4;
    if Y2 < Y1 then result:= -Pi/2 + Pi/4;
  end;
end;

procedure Shoot(const X1,Y1,X2,Y2,speed,power,decentralize,accuracy: single; const owner,style: byte);
var AccuracyMarginal: integer;
    angle: single;
begin
  If Accuracy < 100 then
    AccuracyMarginal:=round((100 - Accuracy) / 100 * 3600)
  else
    AccuracyMarginal:=0;
  angle:=Aim(X1,Y1,X2,Y2);
  CreateBullet(X1+decentralize*cos(angle),Y1+decentralize*sin(angle),cos(angle + deg2rad(random(-AccuracyMarginal,AccuracyMarginal) / 10))*speed,sin(angle + deg2rad(random(-AccuracyMarginal,AccuracyMarginal) / 10))*speed,power,style,owner);
end;

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
Re: [Request] Looking for Shoot() procedure
« Reply #2 on: July 01, 2009, 06:11:47 am »
Thanks, fast&easy like i like it  ::)