Raised This Month: $51 Target: $400
 12% 

Player coordinates l4d


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alexmy
Senior Member
Join Date: Oct 2014
Location: Russian Federation
Old 12-23-2019 , 08:44   Player coordinates l4d
Reply With Quote #1

HI.
I'm trying to track the coordinates of nearby players. What am I doing wrong?

PHP Code:
public void OnEntityCreated(int entity)
{
    if(
IsValidEntity(entity) && GetEntityClassname(entityclssizeof(cls)))
        if(
StrEqual(cls"prop_physics"))
        {
            if(
GetEntProp(entityProp_Data"m_nModelIndex") == 0)
            {
                for (
int i 1<= MaxClients; ++i)
                {
                    if(
IsClientInGame(i))
                    {
                         static 
float vecDir[3], vecPos[3];
                         
                         
GetEntPropVector(entityProp_Send"m_vecOrigin"vecDir);
                         
vecPos[0]+=vecDir[0]*2.0;
                         
vecPos[1]+=vecDir[1]*2.0;
                         
vecPos[2]+=vecDir[2]*2.0;
                         
                         
GetClientAbsOrigin(ivecDir);
                         
PrintToChat(i"Test");
                    }
                }
            }
        }
        

Alexmy is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 12-23-2019 , 11:35   Re: Player coordinates l4d
Reply With Quote #2

OnEntityCreated is too early to check entprops since they are usually not set up.

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)//OnEntityCreated passes classname anyway
{
    if(
entity 0)// you just need bound check some ents created are refs anyway so -27532542 
    
{
        if(
StrEqual(classname"prop_physics"))
        {
            
SDKHook(entitySDKHook_SpawnPostSpawnPost);// in spawnpost hooks engine usually has vecs done
        
}
    }   
}

public 
void SpawnPost(int entity)// if not eveything is finished like collision groups ect, use a RequestFrame Hook
{
    
SDKUnhook(entitySDKHook_SpawnPostSpawnPost);
    
    if(
GetEntProp(entityProp_Data"m_nModelIndex") == 0)// not sure if this is intended == 0, i think you mean != 0
    
{
        for (
int i 1<= MaxClients; ++i)
        {
            if(
IsClientInGame(i))
            {
                static 
float vecDir[3], vecPos[3];
                
                
GetEntPropVector(entityProp_Send"m_vecOrigin"vecDir);
                
vecPos[0]+=vecDir[0]*2.0;
                
vecPos[1]+=vecDir[1]*2.0;
                
vecPos[2]+=vecDir[2]*2.0;
                
                
GetClientAbsOrigin(ivecDir);
                
PrintToChat(i"Test");
            }
        }
    }

This should do for you unless your checking is wrong.
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-24-2019 , 08:17   Re: Player coordinates l4d
Reply With Quote #3

Можно вывести это за пределы цикла, т.к. результат всегда один и тот же:
Code:
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vecDir);
И там довольно странная математика.
Если тебе нужно найти ближайших к предмету, вычисляешь дистанцию через GetVectorDistance()
И потом сравниваешь с максимальной дистанцией, которая тебе нужна.

Или если тебе надо ограничить каким-то числом игроков, то применяешь любой алгоритм сортировки,
и из шапки результирующего массива забираешь игроков. В sm есть функции сортировки, например SortCustom2D(). Пример можешь глянуть в https://forums.alliedmods.net/showthread.php?p=2559282

И да, m_nModelIndex после SpawnPost там вряд ли будет 0.

--------------------------

You can move it out of cycle, since result is always same:
Code:
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vecDir);
And, there is a strange math.
If you need to find nearest to item, calculate distance with GetVectorDistance().
After, compare it with max distance required.

Or, if you need limit it by max number of players, apply any sort algorithm,
and retrive player indeces from top of resulting array. sm has sort functions integrated, e.g. SortCustom2D(). You can see example in: https://forums.alliedmods.net/showthread.php?p=2559282

And yes, m_nModelIndex is unlikely = 0 after SpawnPost.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Alexmy
Senior Member
Join Date: Oct 2014
Location: Russian Federation
Old 12-25-2019 , 20:37   Re: Player coordinates l4d
Reply With Quote #4

Quote:
Originally Posted by Lux View Post
OnEntityCreated is too early to check entprops since they are usually not set up.

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)//OnEntityCreated passes classname anyway
{
    if(
entity 0)// you just need bound check some ents created are refs anyway so -27532542 
    
{
        if(
StrEqual(classname"prop_physics"))
        {
            
SDKHook(entitySDKHook_SpawnPostSpawnPost);// in spawnpost hooks engine usually has vecs done
        
}
    }   
}

public 
void SpawnPost(int entity)// if not eveything is finished like collision groups ect, use a RequestFrame Hook
{
    
SDKUnhook(entitySDKHook_SpawnPostSpawnPost);
    
    if(
GetEntProp(entityProp_Data"m_nModelIndex") == 0)// not sure if this is intended == 0, i think you mean != 0
    
{
        for (
int i 1<= MaxClients; ++i)
        {
            if(
IsClientInGame(i))
            {
                static 
float vecDir[3], vecPos[3];
                
                
GetEntPropVector(entityProp_Send"m_vecOrigin"vecDir);
                
vecPos[0]+=vecDir[0]*2.0;
                
vecPos[1]+=vecDir[1]*2.0;
                
vecPos[2]+=vecDir[2]*2.0;
                
                
GetClientAbsOrigin(ivecDir);
                
PrintToChat(i"Test");
            }
        }
    }

This should do for you unless your checking is wrong.
Thank you, it helped me a lot.
Alexmy is offline
Alexmy
Senior Member
Join Date: Oct 2014
Location: Russian Federation
Old 12-25-2019 , 20:38   Re: Player coordinates l4d
Reply With Quote #5

Quote:
Originally Posted by Dragokas View Post
Можно вывести это за пределы цикла, т.к. результат всегда один и тот же:
Code:
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vecDir);
И там довольно странная математика.
Если тебе нужно найти ближайших к предмету, вычисляешь дистанцию через GetVectorDistance()
И потом сравниваешь с максимальной дистанцией, которая тебе нужна.

Или если тебе надо ограничить каким-то числом игроков, то применяешь любой алгоритм сортировки,
и из шапки результирующего массива забираешь игроков. В sm есть функции сортировки, например SortCustom2D(). Пример можешь глянуть в https://forums.alliedmods.net/showthread.php?p=2559282

И да, m_nModelIndex после SpawnPost там вряд ли будет 0.

--------------------------

You can move it out of cycle, since result is always same:
Code:
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vecDir);
And, there is a strange math.
If you need to find nearest to item, calculate distance with GetVectorDistance().
After, compare it with max distance required.

Or, if you need limit it by max number of players, apply any sort algorithm,
and retrive player indeces from top of resulting array. sm has sort functions integrated, e.g. SortCustom2D(). You can see example in: https://forums.alliedmods.net/showthread.php?p=2559282

And yes, m_nModelIndex is unlikely = 0 after SpawnPost.
Thank you.
Alexmy 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 15:35.


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