CSGO: Distance between two players

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

CSGO: Distance between two players

Postby Kami » Tue Oct 13, 2015 3:16 pm

Hey guys, I'm currently trying to find a way to get the distance between two players. I could propably do it via some vector math, but maybe there is already something in the modules?

Thank you :)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Oct 13, 2015 3:31 pm

https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/mathlib/mathlib_wrap.cpp#L177

That will return in "game units", so you will have to adjust it to get the feet/meters (or whatever type of distance you are looking for).
Image
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Tue Oct 13, 2015 3:55 pm

Thank you very much!

I'm afraid I am more than rusty with all of this so could you please tell me if this is the right use:

Syntax: Select all

from mathlib import Vector
import players

player_orig = players.get_abs_origin(player_index)
other_orig = players.get_abs_origin(other_index)
distance = player_orig.Vector.get_distance(other_orig)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Oct 13, 2015 3:58 pm

Syntax: Select all

from players.entity import PlayerEntity

first_player = PlayerEntity(player_index)
second_player = PlayerEntity(other_index)
distance = first_player.origin.get_distance(second_player.origin)
Image
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Tue Oct 13, 2015 4:05 pm

Awesome, thank you!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 45 guests