[TG] Chief (alex) -Admin- TG Leader
Posts : 1525 Reputation : 59 Join date : 2009-05-17 Age : 31 Location : I am from norway, north norway!
| Subject: It is done! Sat Jan 16, 2010 12:46 am | |
| The people have spoken. This is the first code! Requested by Tatoma: It finds the closest player: - Code:
-
function ClosestPlayer( ply ) local target = nil local playerpos = ply:GetPos() local Distance_shortest = 999999999 for k,v in pairs(ents.FindByClass("player")) do local TargetPos = v:GetPos() local Now_Distance = playerpos:Distance( TargetPos ) if Now_Distance <= Distance_shortest then Distance_shortest = Now_Distance target = v end end if !(target == nil) then print("The closest player is: "..target:Nick()) print("He/She is "..Distance_shortest.." units away!") else print("You have no target") end end | |
|
tatoma4
Posts : 208 Reputation : 9 Join date : 2009-09-23 Age : 29 Location : Finland
| Subject: Re: It is done! Sat Jan 16, 2010 12:53 am | |
| Yeippee, now we can provide other with code. Easier to spot bugs in bigger group of coders. | |
|