0 Members and 1 Guest are viewing this topic.
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;
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);beginif (Text = '!near') thenCalculateNearest(NameToID(Name),1,2);End;
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:Code: [Select]procedure OnPlayerSpeak(ID: byte; Text: string);begin if Text = '!near' then SayToPlayer( ID, IDToName(CalculateNearest(ID, 1, 2)) );end;