HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 
 

 It is done!

View previous topic View next topic Go down 
AuthorMessage
[TG] Chief (alex) -Admin-
TG Leader
TG Leader
avatar

Posts : 1525
Reputation : 59
Join date : 2009-05-17
Age : 25
Location : I am from norway, north norway!

PostSubject: 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
Back to top Go down
View user profile http://www.thegoatriders.com
tatoma4

avatar

Posts : 208
Reputation : 9
Join date : 2009-09-23
Age : 22
Location : Finland

PostSubject: 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.
Back to top Go down
View user profile http://koti.mbnet.fi/tatoma/jtnepic.flv
 
It is done!
View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: Coding-
Jump to: