Author Topic: Function FindClosestPlayer  (Read 1027 times)

0 Members and 1 Guest are viewing this topic.

Offline Rampage_Terranius

  • Major
  • *
  • Posts: 69
  • The Strategist
    • Soldat Noob Servers
Function FindClosestPlayer
« on: October 20, 2008, 03:38:27 am »
Script Name: Find Closest Player
Script Description Find the closest player to the id specified
Author: Rampage_Terranius
Compile Test: Passed
Core Version: 2.6.3
Hosted by: Soldat Central - http://soldatcentral.com/

Full Description:
I needed to detect the closest id for a new script im making and since there isnt anything currently to do so i built this to do it it instead

now has an option to change search type
these are the types:
1 = all players count
2 = only Non team mates count
3 = only team mates count

Used like so:
FindClosestPlayer(id of player to find closest player to, type of search)

For example:
FindClosestPlayer(1, 1) will find the closest player to id 1 no matter what team they are

FindClosestPlayer(1, 2) will find the closest palyer who is not on the same team as id 1

FindClosestPlayer(1, 3) will find the closest team mate of id 1




(Size 871 B)
- http://soldatcentral.com/index.php?page=script&f=55 -


** Script hosted by Soldat Central! Please visit the author's script page and Rate this script **

finally had time to fix this (was checking 2nd ids x instead of y) and got around to adding the types of searching id wanted to add like 2 weeks ago as usual if you find a bug please let me know

Offline UPNPAD

  • Major(1)
  • Posts: 36
Re: Function FindClosestPlayer
« Reply #1 on: October 20, 2008, 05:08:19 am »
Avarax's NearestPlayer function, with a bit more functionality. This was taken from MMod v1.1

Code: [Select]
//team -> -1 to -5: Player is not of that team.  0: Team doesn't matter.  1 to 5: Player is of that team
//dead -> 0: Player must be alive.  1: Player must be dead.  >1: Doesn't matter.
//bot  -> -1: Doesn't matter.  0: Player is no bot.  1: Player is a bot.
function NearestPlayer(const X1,Y1: single; const team,dead,bot: integer; maxrange: single): byte;
var dist: single;
    i: byte;
begin
  result:=0;
  for i:=1 to MaxID do
    If (GetPlayerStat(i,'Active')=true) and ((bot = -1) or (GetPlayerStat(i,'Human') = true) and (bot = 0) or (GetPlayerStat(i,'Human') = false) and (bot = 1)) 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 ((GetPlayerStat(i,'Team')=team) and (team>0)) or (team=0)) then begin
      dist:=Distance(X1,Y1,GetPlayerStat(i,'X'),GetPlayerStat(i,'Y'));
        If (dist < maxrange) and (dist > 0.001) then
          begin
            maxrange:=dist;
            result:=i;
          end;
    end;
end;

Offline Rampage_Terranius

  • Major
  • *
  • Posts: 69
  • The Strategist
    • Soldat Noob Servers
Re: Function FindClosestPlayer
« Reply #2 on: October 20, 2008, 07:53:48 am »
alright so there was already something out there to detect closest id :-[ well i didnt mean to copy someone elses idea