Найти владельца ентити

Mr_panica

XenForo one 💖
Сообщения
925
Реакции
441
Всем привет, хочу найти игрока, который запустил прожектаил.
Но возникла проблема, что возвращает -1.

Получить владельца ентити нужно когда оно касается чего-либо.
В SDKHook_Spawn возвращает игрока нормально, но в SDKHook_Touch -1

Примерный код:
C-подобный:
#include <sdktools>
#include <sdkhooks>

public void OnEntityCreated(int entity, const char[] classname)
{
    if (StrEqual(classname, "tf_projectile_pipe_remote", false))
    {
        SDKHook(entity, SDKHook_Spawn, Hook_OnSpawn);
        SDKHook(entity, SDKHook_Touch, Hook_OnTouch);
    }
}

public Action Hook_OnSpawn(int entity)
{
    int owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
    PrintToChatAll("entity: %i, Parent: %i", entity, owner);
    return Plugin_Continue;
}

public Action Hook_OnTouch(int toucher, int touchee)
{
    int owner = GetEntPropEnt(toucher, Prop_Send, "m_hOwnerEntity");
    PrintToChatAll("toucher:%i, Parent: %i", toucher, owner);
    return Plugin_Continue;
}

1637933761586.png



SM 1.10 - build 6528
Игра: Team Fortress 2
 

Grey83

не пишу плагины с весны 2022
Сообщения
8,557
Реакции
5,050
только перенеси создание хука касания в каллбэк спавна
м/б поможет
C-подобный:
#include <sdkhooks>

public void OnEntityCreated(int entity, const char[] classname)
{
    if(StrEqual(classname, "tf_projectile_pipe_remote", false)) SDKHook(entity, SDKHook_Spawn, Hook_OnSpawn);
}

public Action Hook_OnSpawn(int entity)
{
    PrintToChatAll("Spawned entity: %i Parent: %i", entity, GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"));
    SDKHook(entity, SDKHook_Touch, Hook_OnTouch);
}

public Action Hook_OnTouch(int entity, int other)
{
    PrintToChatAll("Touched entity: %i Parent: %i", entity, GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"));
}
 

Mr_panica

XenForo one 💖
Сообщения
925
Реакции
441
только перенеси создание хука касания в каллбэк спавна
м/б поможет
C-подобный:
#include <sdkhooks>

public void OnEntityCreated(int entity, const char[] classname)
{
    if(StrEqual(classname, "tf_projectile_pipe_remote", false)) SDKHook(entity, SDKHook_Spawn, Hook_OnSpawn);
}

public Action Hook_OnSpawn(int entity)
{
    PrintToChatAll("Spawned entity: %i Parent: %i", entity, GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"));
    SDKHook(entity, SDKHook_Touch, Hook_OnTouch);
}

public Action Hook_OnTouch(int entity, int other)
{
    PrintToChatAll("Touched entity: %i Parent: %i", entity, GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"));
}
Не, я так тоже пробовал - не прокатило, но почему так?

1637937322957.png


Или может быть есть другой способ найти владельца?

Пока как-то так получается?
C-подобный:
#include <sdktools>
#include <sdkhooks>

int entitis[2048];

public void OnEntityCreated(int entity, const char[] classname)
{
    if (StrEqual(classname, "tf_projectile_pipe_remote", false))
    {
        SDKHook(entity, SDKHook_Spawn, Hook_OnSpawn);
        SDKHook(entity, SDKHook_Touch, Hook_OnTouch);
    }
}

public Action Hook_OnSpawn(int entity)
{
    int owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
    entitis[entity] = owner;
    PrintToChatAll("entity: %i, Parent: %i", entity, owner);
    return Plugin_Continue;
}

public Action Hook_OnTouch(int toucher, int touchee)
{
    //int owner = GetEntPropEnt(toucher, Prop_Send, "m_hOwnerEntity");
      PrintToChatAll("toucher:%i, Parent: %i", toucher, entitis[toucher]);
    return Plugin_Continue;
}
 
Последнее редактирование:
Сверху Снизу