Raised This Month: $ Target: $400
 0% 

Check distance between two players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
matsi
Thinkosaur
Join Date: Sep 2006
Old 09-14-2010 , 07:52   Check distance between two players
Reply With Quote #1

I've already created code that checks distance between two players when you press +use. I need to check that distance constantly to see if the other player gets out of that range. What would be the best way to do it?

Last edited by matsi; 09-15-2010 at 04:37.
matsi is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-14-2010 , 08:12   Re: Check distance between two players
Reply With Quote #2

Depending on what you really want to do.

But, a global set_task() looping through each player would do.
__________________
Hunter-Digital is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 09-14-2010 , 09:12   Re: Check distance between two players
Reply With Quote #3

Quote:
Originally Posted by Hunter-Digital View Post
Depending on what you really want to do.

But, a global set_task() looping through each player would do.
I'm trying to check if player can be 5 seconds in certain 'radius' of the other player. And of course i wanna know the best way of doing that.
matsi is offline
Prajch
Senior Member
Join Date: Dec 2007
Location: anger++
Old 09-14-2010 , 12:34   Re: Check distance between two players
Reply With Quote #4

You'll have to use a set_task, or if once every 0.1 seconds isn't often enough, you'll have to either do it in prethink (can be costly) or create a timer entity with its own think function so that you can set the interval yourself.
Prajch is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 09-14-2010 , 13:31   Re: Check distance between two players
Reply With Quote #5

Quote:
Originally Posted by Prajch View Post
You'll have to use a set_task, or if once every 0.1 seconds isn't often enough, you'll have to either do it in prethink (can be costly) or create a timer entity with its own think function so that you can set the interval yourself.
Which one is better? task or timer entity?
matsi is offline
Mati_
Member
Join Date: Sep 2010
Old 09-14-2010 , 22:41   Re: Check distance between two players
Reply With Quote #6

A set_task with 0.1s should be sufficient, much easier and less code than creating a custom entity with its think function.

A custom entity would be "more correct" and professional, and also more performant I suppose.

Last edited by Mati_; 09-14-2010 at 22:43.
Mati_ is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-14-2010 , 23:16   Re: Check distance between two players
Reply With Quote #7

Use a thinking entity. Search the forums or look at my bullet pogo plugin for an example.
__________________
Bugsy is offline
Old 09-14-2010, 23:20
Mxnn
This message has been deleted by Mxnn. Reason: I missunderstood
matsi
Thinkosaur
Join Date: Sep 2006
Old 09-15-2010 , 04:28   Re: Check distance between two players
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
Use a thinking entity. Search the forums or look at my bullet pogo plugin for an example.
Thanks for the answer/tip. I've used thinking entity once to create countdown so i know how to make it.
matsi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode