Official Soldat Forums
Server Talk => Scripting Releases => Topic started by: Avarax on May 08, 2007, 07:59:18 am
-
Script Name: function CalculateNearest
Script Description: calculates the nearest player next to the chosen ID, depending on some parameters
Original Author(s): Avarax, taken from Hexer mod
Core Version: 2.6.1, compatible with 2.6.0.
function CalculateNearest(ID,team,dead: byte): byte;
var X1,Y1,X2,Y2,temp: single;
i: integer;
begin
GetPlayerXY(ID,X1,Y1);
temp:=999999
result:=0;
for i:=1 to 32 do
If (i<>ID) and (((GetPlayerStat(i,'Alive')=true) and (dead = 0)) or ((GetPlayerStat(i,'Alive')=false) and (dead = 1)) or (dead>1)) and (((GetPlayerStat(i,'Team')=team) and (team>0)) or (team=0)) then
begin
GetPlayerXY(i,X2,Y2);
If Distance(X1,Y1,X2,Y2) < temp then
begin
temp:=Distance(X1,Y1,X2,Y2);
result:=i;
end;
end;
end;
Parameters:
function CalculateNearest(ID,team,dead: byte): byte;
ID:
Player ID whos coordinates are used to search nearest player
team:
1: Searches for nearest Alpha player
2: Searches for nearest Bravo player
3: Searches for nearest Charlie player
4: Searches for nearest Delta player
0: Searches for nearest player of any team
dead:
0: Searches for alive players only
1: Searches for dead players only
higher than 1: Searches for any players
Returned is the player ID of the nearest player. If no player matching the chosen parameters was found, the function will return 0 as result.
-
Hm, I can't make scripts well and i need help.
It is my NetworkCore.pas:
function CalculateNearest(ID,team,dead: byte): byte;
var X1,Y1,X2,Y2,temp: single;
i: integer;
begin
GetPlayerXY(ID,X1,Y1);
temp:=999999
result:=0;
for i:=1 to 32 do
If (i<>ID) and (((GetPlayerStat(i,'Alive')=true) and (dead = 0)) or ((GetPlayerStat(i,'Alive')=false) and (dead = 1)) or (dead>1)) and (((GetPlayerStat(i,'Team')=team) and (team>0)) or (team=0)) then
begin
GetPlayerXY(i,X2,Y2);
If Distance(X1,Y1,X2,Y2) < temp then
begin
temp:=Distance(X1,Y1,X2,Y2);
result:=i;
end;
end;
end;
procedure OnPlayerSpeak(Name,Text: string);
begin
if (Text = '!near') then
CalculateNearest(NameToID(Name),1,2);
End;
Server version 2.6.0
In game it doesnt work. Can you help me?
-
It works, but you arent actually echoing it anywhere.... do WriteLn(inttostr(CalculateNearest(NameToID(Name),1,2)));
-
I think you are using an old prototype for the OnPlayerSpeak event. You should do something like this:
procedure OnPlayerSpeak(ID: byte; Text: string);
begin
if Text = '!near' then
SayToPlayer( ID, IDToName(CalculateNearest(ID, 1, 2)) );
end;
-
I think you are using an old prototype for the OnPlayerSpeak event. You should do something like this:
procedure OnPlayerSpeak(ID: byte; Text: string);
begin
if Text = '!near' then
SayToPlayer( ID, IDToName(CalculateNearest(ID, 1, 2)) );
end;
Yeah it works. Thx.