
13.01.2025, 16:37
|
|
Участник форума
Регистрация: 08.10.2019
Сообщений: 139
С нами:
3474377
Репутация:
98
|
|
plugin.cpp:
Код:
uint16_t
get_nearest_driver
(
)
{
auto
player_pool
=
c_netgame
::
get
(
)
->
ref
(
)
->
get_player_pool
(
)
;
if
(
!
player_pool
)
return
65535
;
// invalid id
auto
my_ped
=
player_pool
->
get_local_player
(
)
->
get_ped
(
)
;
if
(
!
my_ped
)
return
65535
;
std
::
map
nearest
;
for
(
int
i
=
0
;
i
MAX_PLAYERS
;
i
++
)
{
auto
target
=
player_pool
->
get_player
(
i
)
;
if
(
!
target
||
!
target
->
does_exist
(
)
)
continue
;
auto
target_ped
=
target
->
m_pPed
;
if
(
!
target_ped
)
continue
;
c_vector my_position
;
my_ped
->
get_bone_position
(
8
,
&
my_position
)
;
c_vector target_position
;
target_ped
->
get_bone_position
(
8
,
&
target_position
)
;
auto
distance
=
my_position
.
distance_to
(
target_position
)
;
nearest
[
distance
]
=
target
->
m_nId
;
}
if
(
nearest
.
empty
(
)
)
return
65535
;
return
nearest
.
begin
(
)
->
second
;
}
все нужные функции есть тут: https://github.com/BlastHackNet/SAMP...api/0.3.7-R3-1
c_vector:
[CODE]
class
c_vector
{
public
:
float
x
,
y
,
z
;
c_vector
(
)
:
x
(
0
)
,
y
(
0
)
,
z
(
0
)
{
}
c_vector
(
float
x
,
float
y
,
float
z
)
:
x
(
x
)
,
y
(
y
)
,
z
(
z
)
{
}
;
void
set
(
float
_x
,
float
_y
,
float
_z
)
{
x
=
_x
;
y
=
_y
;
z
=
_z
;
}
float
get_length_squared
(
)
const
{
return
x
*
x
+
y
*
y
+
z
*
z
;
}
float
get_length
(
)
const
{
return
std
::
sqrt
(
get_length_squared
(
)
)
;
}
void
normalize
(
)
{
float
len
=
get_length
(
)
;
x
/=
len
;
y
/=
len
;
z
/=
len
;
}
float
dot
(
const
c_vector
&
vec
)
const
{
return
x
*
vec
.
x
+
y
*
vec
.
y
+
z
*
vec
.
z
;
}
c_vector
cross
(
const
c_vector
&
vec
)
const
{
return
c_vector
(
y
*
vec
.
z
-
vec
.
y
*
z
,
z
*
vec
.
x
-
vec
.
z
*
x
,
x
*
vec
.
y
-
vec
.
x
*
y
)
;
}
void
zero_near_zero
(
)
{
if
(
std
::
abs
(
x
)
P.S по желанию можешь сделать проверку на seat_index
|
|
|