Гайд Damage indicator

Пользователь
Пользователь
Статус
Оффлайн
Регистрация
13 Янв 2018
Сообщения
198
Реакции
75
Мой(на 10%) исходник дамаге индикатора. База csgosimple. (сори за говоно код, я уверен он где-то есть и его много, но в силу своей тупости я его не исправлю)
Демонстрация в 20 фпс -

Ориг который я взял за основу -
Пожалуйста, авторизуйтесь для просмотра ссылки.


Переменные которые используются для настройки
C++:
Expand Collapse Copy
bool enable = false;

float show_time = 5.f;
float speed = 0.2f;
float max_pos_y = 20.f;
float range_offset_x = 10.f;
float offset_if_kill = 10.f;
float offset_hit = 0.f;

//upd
float text_size = 12.f;
Color standart_color = Color(255, 255, 255, 255);
Color kill_color = Color(255, 50, 50, 255);

struct и std::vector
C++:
Expand Collapse Copy
struct damage_indicator_t {
    int damage;
    bool initialized;
    float erase_time;
    float last_update;
    C_BasePlayer* player;
    int hit_box;
    Color col;
    Vector position;
    Vector end_position;
};

std::vector<damage_indicator_t> indicators;

event player_hurt
C++:
Expand Collapse Copy
if (strstr(pEvent->GetName(), "player_hurt")) {

      C_BasePlayer* hurt = (C_BasePlayer*)g_EntityList->GetClientEntity(g_EngineClient->GetPlayerForUserID(pEvent->GetInt("userid")));
      C_BasePlayer* attacker = (C_BasePlayer*)g_EntityList->GetClientEntity(g_EngineClient->GetPlayerForUserID(pEvent->GetInt("attacker")));

      if (hurt && attacker) {
            bool hurt_dead = pEvent->GetInt("health") == 0;

            if (enable) {
                  if (hurt != g_LocalPlayer && attacker == g_LocalPlayer) {
                        damage_indicator_t DmgIndicator;
                        DmgIndicator.damage = pEvent->GetInt("dmg_health");
                        DmgIndicator.player = hurt;
                        if (!hurt_dead) //upd
                              DmgIndicator.col = standart_color;
                        else
                              DmgIndicator.col = kill_color;
                        DmgIndicator.hit_box = pEvent->GetInt("hitgroup");
                        DmgIndicator.erase_time = g_GlobalVars->curtime + show_time;
                        DmgIndicator.initialized = false;

                        indicators.push_back(DmgIndicator);
                  }
            }
      }
}

Рендер
C++:
Expand Collapse Copy
void Visuals::DrawDamageIndicator()
{
    float CurrentTime = g_GlobalVars->curtime;

    for (int i = 0; i < indicators.size(); i++) {

        if (indicators[i].erase_time < CurrentTime) {
            indicators.erase(indicators.begin() + i);
            continue;
        }

        if (indicators[i].erase_time - 1.f < CurrentTime) {
            indicators[i].col._CColor[3] = Utils::lerp(indicators[i].col._CColor[3], 0, 0.1f);
        }

        if (!indicators[i].initialized) {
            indicators[i].position = indicators[i].player->GetHitboxPos(bone(indicators[i].hit_box));

            if (!indicators[i].player->IsAlive()) {
                indicators[i].position.z -= 39.f; //лично у меня из-за того что игрок умирает, весь его хитбокс прыгает вверх на 39.f

                indicators[i].position.z += offset_if_kill;
            } else {
                indicators[i].position.z += offset_hit;
            }

            indicators[i].end_position = indicators[i].position + Vector(Utils::random(-range_offset_x, range_offset_x), Utils::random(-range_offset_x, range_offset_x), max_pos_y);

            indicators[i].initialized = true;
        }

        if (indicators[i].initialized) {
            indicators[i].position.z = Utils::lerp(indicators[i].position.z, indicators[i].end_position.z, speed);
            indicators[i].position.x = Utils::lerp(indicators[i].position.x, indicators[i].end_position.x, speed);
            indicators[i].position.y = Utils::lerp(indicators[i].position.y, indicators[i].end_position.y, speed);

            indicators[i].last_update = CurrentTime;
        }

        Vector ScreenPosition;

        if (Math::WorldToScreen(indicators[i].position, ScreenPosition)) {
           Render::Get().RenderText("-" + std::to_string(indicators[i].damage), ScreenPosition.x, ScreenPosition.y, text_size, indicators[i].col, true);
        }
    }
}

перевод id'шников костей с event на нормальные
C++:
Expand Collapse Copy
int bone(int event_bone)
{
    switch (event_bone)
    {
    case 1:
        return HITBOX_HEAD;
    case 6:
        return HITBOX_RIGHT_THIGH;
    case 7:
        return HITBOX_LEFT_THIGH;
    case 2:
        return HITBOX_UPPER_CHEST;
    case 3:
        return HITBOX_LOWER_CHEST;
    case 4:
        return HITBOX_RIGHT_FOREARM;
    case 5:
        return HITBOX_LEFT_FOREARM;
    case 8:
        return HITBOX_NECK;
    default:
        return HITBOX_STOMACH;
    }
}
 
Последнее редактирование:
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
привет) давай вместе строить проект? знания в с++ имеются. могу выполнить задания которые ты дашь
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Вещь прикольная, задумка норм. Чуть доделать и будешь вещь)
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
перенос строки убери перед скобкой, уже хотябы чтото будет
 
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Сори, я в глаза ебусь, где этот перенос?
1582916614790.png
 
не плохо
 
Назад
Сверху Снизу