Author Topic: How to create a knife and throw it automaticly?  (Read 832 times)

0 Members and 1 Guest are viewing this topic.

Offline rafineria888

  • Major(1)
  • Posts: 10
How to create a knife and throw it automaticly?
« on: February 24, 2016, 11:06:30 am »
Hi.
I need to know (THREAD...).
I want to spawn this knife on Player.ID.X | Player.ID.Y position and push it to the closest enemy player.
How to do this in only ScriptCore3?
Thanks :)

Offline Savage

  • Soldier
  • **
  • Posts: 155
Re: How to create a knife and throw it automaticly?
« Reply #1 on: February 24, 2016, 02:55:34 pm »
Probably easiest way, type /aim as Admin to shoot to nearest enemy(If you need better aim... then you will need dll made by tk)

Code: [Select]
const
bspeed = 15;
bstyle = 13;
bdamage = 1000;

function NearestEnemy(const ID: Byte): Byte;
var
i,temp: Byte;
d: Single;
begin
for i := 1 to 32 do
if (i<>ID) and (Players[i].Active) and (Players[i].Alive) and ((Players[i].Team=0) or (Players[i].Team<>Players[ID].Team)) then begin
d := Distance(Players[ID].X, Players[ID].Y, Players[i].X, Players[i].Y);
temp := i;
Result := i;
break;
end;

if temp<32 then
for i := temp+1 to 32 do
if (i<>ID) and (Players[i].Active) and (Players[i].Alive) and ((Players[i].Team=0) or (Players[i].Team<>Players[ID].Team)) and (Distance(Players[ID].X, Players[ID].Y, Players[i].X, Players[i].Y)<d) then begin
d := Distance(Players[ID].X, Players[ID].Y, Players[i].X, Players[i].Y);
Result := i;
end;
end;

function OAC(Player: TActivePlayer; Command: string): boolean;
var
enemy: Byte;
x1,y1,x2,y2,d: Single;
begin
if Command='/aim' then begin
enemy := NearestEnemy(Player.ID);
if enemy<>0 then begin
x1 := Player.X;
y1 := Player.Y-12;
x2 := Players[enemy].X;
y2 := Players[enemy].Y-12;
d := Distance(x1, y1, x2, y2);
Map.CreateBullet(x1, y1, (x2-x1)/d*bspeed, (y2-y1)/d*bspeed, bdamage, bstyle, Player);
end else
Player.WriteConsole('Enemy not found',$FF0000);
end;

Result := False;
end;

begin
Game.OnAdminCommand := @OAC;
end.
« Last Edit: February 25, 2016, 11:35:21 am by Savage »

Offline rafineria888

  • Major(1)
  • Posts: 10
Re: How to create a knife and throw it automaticly?
« Reply #2 on: February 25, 2016, 06:43:46 am »
Thanks :)