Нахождение локации упавшего с4

Статус
В этой теме нельзя размещать новые ответы.

vertigo

Участник
Сообщения
32
Реакции
29
Я работаю над плагином ... который добавляет некоторый эффект на упал с4. (Игра: CS: Source)
Но эффект появляется в неправильном месте.

public void OnBombDropped(Event event, const char[] name, bool dontBroadcast)
{
int Dropped_C4 = FindEntityByClassname(Dropped_C4, "weapon_c4");
float C4_Location[3];
GetEntPropVector(Dropped_C4, Prop_Data, "m_vecOrigin", C4_Location);
PrintToServer("Location = %f, %f, %f", C4_Location[0], C4_Location[1], C4_Location[2]);
effect(C4_Location);
}
public void effect(float location[])
{
// Do something
}

И проблема в том, что он печатает одно и то же местоположение каждый раз ... а не фактическое выбранное местоположение c4. Где я хочу, чтобы мой эффект.

Location = 0.000000, 0.000000, 52.000000
Location = 0.000000, 0.000000, 52.000000
Location = 0.000000, 0.000000, 52.000000
Location = 0.000000, 0.000000, 52.000000

Нет журналов ошибок.
Как я могу получить точное местоположение выпавшего с4?
 

Kruzya

Участник
Сообщения
12,970
Реакции
10,924
  • Команда форума
  • #2
Are you tried to get entity position in next frame? RequestFrame() should help with this.
P.S.: Please, don't use Google Translator, if you understand russian language.
 

vertigo

Участник
Сообщения
32
Реакции
29
Yes @Kruzya
Я попробую RequestFrame ().
В настоящее время я создал таймер в текущем коде. И прохождение локации.
C-подобный:
float C4_Location[3];
Handle EffectTimer = INVALID_HANDLE;
public void OnBombDropped(Event event, const char[] name, bool dontBroadcast)
{
    int Dropped_C4 = FindEntityByClassname(Dropped_C4, "weapon_c4");
    GetEntPropVector(Dropped_C4, Prop_Data, "m_vecOrigin", C4_Location);
    PrintToServer("Location = %f, %f, %f", C4_Location[0], C4_Location[1], C4_Location[2]);
    Timer_BombEffect(INVALID_HANDLE);
    EffectTimer = CreateTimer(1.0, Timer_BombEffect, _, TIMER_REPEAT);
}

public Action Timer_BombEffect(Handle timer)
{
    TE_SetupBeamRingPoint(C4_Location, ,...);
    TE_SendToAll();
}

Эффект, который мне нужен, появляется. Но всегда в одном месте.
RequestFrame () с таймером? Извините, я новичок в SourcePawn.

P.S I Don't know Russian.
 

Reiko1231

AlexTheRegent
Сообщения
508
Реакции
1,336
@vertigo, you should get position of c4 inside the timer. You can do this by passing c4 index as reference to timer using EntIndexToEntRef function. Or you can find C4 entity index looping through all entities inside timer using FindEntityByClassname function.

Samlpe using EntIndexToEntRef -> EntRefToEntIndex functions
C-подобный:
public void OnBombDropped(Event event, const char[] name, bool dontBroadcast)
{
    int c4 = FindEntityByClassname(-1, "weapon_c4");
    EffectTimer = CreateTimer(1.0, Timer_BombEffect, EntIndexToEntRef(c4), TIMER_REPEAT);
}
public Action Timer_BombEffect(Handle timer, int c4ref)
{
    int c4 = EntRefToEntIndex(c4ref);
    if ( IsValidEntity(c4) ) {
        // put your code here
    }
}

Sample using FindEntityByClassname
C-подобный:
public void OnBombDropped(Event event, const char[] name, bool dontBroadcast)
{
    EffectTimer = CreateTimer(1.0, Timer_BombEffect, _, TIMER_REPEAT);
}
public Action Timer_BombEffect(Handle timer)
{
    int c4 = FindEntityByClassname(-1, "weapon_c4");
    if ( IsValidEntity(c4) ) {
        // put your code here
    }
}

By the way, if you reuse Dropped_C4 as first argument for FindEntityByClassname function (int Dropped_C4 = FindEntityByClassname(Dropped_C4, "weapon_c4");), you must reset Dropped_C4 to -1 every round. This is because entities' indexes starts from 0 every round and increments with each entity. It may be possible that c4 index will be lesser than in previous round and your code will fail.
 
Последнее редактирование модератором:

vertigo

Участник
Сообщения
32
Реакции
29
@Reiko1231 Thanks a lot.
Using FindEntityByClassname inside the timer worked.
I was completely un-aware of the fact that the entity index must be reset If it is being reused.

Everything working now. Thanks again.🙂
 
Статус
В этой теме нельзя размещать новые ответы.
Сверху Снизу