Author Topic: Two Useful Functions  (Read 1754 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Two Useful Functions
« on: December 22, 2009, 11:45:44 pm »
This function takes a name fragment and returns the ID of the player that matches it, if none exists it returns 0. For example if there was a player named !';\\]]>-DOG-<\\][ and you needed your script to be able to recognize his name from player input you would just need to send 'dog' into the function and it will result in his ID. Capitalization is unimportant.

SYNTAX: target := idbyname(
name name\name fragment to check for
);

Code: [Select]
function IDByName(Name: string): byte;
var i: byte;
begin
result := 0;
for i := 1 to 32 do if getplayerstat(i,'active')=true then begin
if containsstring(lowercase(getplayerstat(i,'name')),lowercase(name)) then begin
result := i;
break;
end;
end;
end;

This procedure creates a bullet at a specific x and y and sends it flying in the direction of another x,y position.

SYNTAX: dirbullet(
sx starting X
sy starting Y
dx destination X
dy destination Y
speed directional speed
damage damage multiplier
bulletstyle bulletstyle
owner owner's ID
);

Code: [Select]
procedure DirBullet(sx,sy,dx,dy,speed,damage: single; bulletstyle,owner: byte);
var i: integer; dist,xx,yy,vx,vy,k: single;
begin
xx := sx - dx;
yy := sy - dy;
dist := sqrt((xx*xx)+(yy*yy));
if dist > 0 then begin
k := speed / dist;
vx := (dx - sx) * k;
vy := (dy - sy) * k;
createbullet(sx,sy,vx,vy,damage,bulletstyle,owner);
end;
end;