Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "singleton.hpp"
- #include "MiscClasses.h"
- #include "Interfaces.h"
- #include "Interface.h"
- #include "Logging.h"
- #include "bulletshow.h"
- #include <sstream>
- #pragma comment(lib, "winmm.lib")
- std::vector<cbullet_tracer_info> logs;
- char* HitgroupToName(int hitgroup)
- {
- switch (hitgroup)
- {
- case 1:
- return "head";
- case 2:
- return "chest";
- case 3:
- return "stomach";
- case 4:
- return "left arm";
- case 5:
- return "right arm";
- case 6:
- return "left leg";
- case 7:
- return "right leg";
- default:
- return "body";
- }
- }
- class item_purchase
- : public singleton<item_purchase>
- {
- class item_purchase_listener
- : public IGameEventListener2
- {
- public:
- void start()
- {
- g_EventManager->AddListener(this, "item_purchase", false);
- g_EventManager->AddListener(this, "player_hurt", false);
- g_EventManager->AddListener(this, "bullet_impact", false);
- g_EventManager->AddListener(this, "weapon_fire", false);
- g_EventManager->AddListener(this, "player_death", false);
- g_EventManager->AddListener(this, "bomb_planted", false);
- g_EventManager->AddListener(this, "bomb_exploded", false);
- g_EventManager->AddListener(this, "bomb_dropped", false);
- g_EventManager->AddListener(this, "bomb_defused", false);
- g_EventManager->AddListener(this, "bomb_begindefuse", true);
- g_EventManager->AddListener(this, "bomb_abortdefuse", true);
- g_EventManager->AddListener(this, "round_freeze_end", false);
- g_EventManager->AddListener(this, "round_start", false);
- }
- void stop()
- {
- g_EventManager->RemoveListener(this);
- }
- void FireGameEvent(IGameEvent *event) override
- {
- singleton()->on_fire_event(event, false);
- }
- int GetEventDebugID(void) override
- {
- return 42;
- }
- };
- public:
- static item_purchase* singleton()
- {
- static item_purchase* instance = new item_purchase;
- return instance;
- }
- void initialize()
- {
- listener.start();
- }
- void remove()
- {
- listener.stop();
- }
- void on_fire_event(IGameEvent* event, bool drawing)
- {
- static AppLog log;
- if (drawing)
- {
- }
- else
- {
- }
- if (g_Options.Misc.player_log) {
- g_Engine->ClientCmd_Unrestricted("con_filter_enable 2");
- static auto damagefilter = g_CVar->FindVar("con_filter_text");
- damagefilter->SetValue("SHOCKWAVE");
- }
- else {
- g_Engine->ClientCmd_Unrestricted("con_filter_enable 0");
- }
- if (!drawing) {
- C_BaseEntity* local = g_EntityList->GetClientEntity(g_Engine->GetLocalPlayer());
- if (!strcmp(event->GetName(), "item_purchase")) {
- auto buyer = event->GetInt("userid");
- std::string gun = event->GetString("weapon");
- if (strstr(gun.c_str(), "molotov")
- || strstr(gun.c_str(), "nade")
- || strstr(gun.c_str(), "kevlar")
- || strstr(gun.c_str(), "decoy")
- || strstr(gun.c_str(), "suit")
- || strstr(gun.c_str(), "flash")
- || strstr(gun.c_str(), "vest")
- || strstr(gun.c_str(), "cutter")
- || strstr(gun.c_str(), "defuse")
- ) return;
- auto player_index = g_Engine->GetPlayerForUserID(buyer);
- C_BaseEntity* player = (C_BaseEntity*)g_EntityList->GetClientEntity(player_index);
- player_info_t pinfo;
- if (player && local && g_Engine->GetPlayerInfo(player_index, &pinfo)) {
- gun.erase(gun.find("weapon_"), 7);
- if (g_Options.Misc.player_log) {
- if (player->GetTeamNum() == local->GetTeamNum()) {
- g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
- g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """%s bought %s\n", pinfo.name, gun.c_str());
- std::stringstream string;
- string << " " << pinfo.name << " bought " << gun.c_str();
- visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
- }
- }
- }
- }
- if (!strcmp(event->GetName(), "round_start")) {
- if (g_Options.Misc.player_log) {
- g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
- g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """round has been started\n");
- std::stringstream string;
- string << " round has been started ";
- visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
- }
- }
- if (!strcmp(event->GetName(), "bomb_dropped")) {
- if (g_Options.Misc.player_log) {
- g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
- g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """bomb has been dropped\n");
- std::stringstream string;
- string << " bomb has been dropped ";
- visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
- }
- }
- if (!strcmp(event->GetName(), "bomb_planted")) {
- if (g_Options.Misc.player_log) {
- g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
- g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """bomb has been planted\n");
- std::stringstream string;
- string << " bomb has been planted ";
- visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
- }
- }
- if (!strcmp(event->GetName(), "bomb_abortdefuse")) {
- if (g_Options.Misc.player_log) {
- g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
- g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """defuse has been aborted\n");
- std::stringstream string;
- string << " defuse has been aborted ";
- visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
- }
- }
- if (!strcmp(event->GetName(), "bomb_defused")) {
- if (g_Options.Misc.player_log) {
- g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
- g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """bomb has been defused\n");
- std::stringstream string;
- string << " bomb has been defused ";
- visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
- }
- }
- if (!strcmp(event->GetName(), "player_hurt")) {
- auto bitch = event->GetInt("userid");
- auto coolguy49 = event->GetInt("attacker");
- int entityid = g_Engine->GetPlayerForUserID(coolguy49);
- auto hitbox = HitgroupToName(event->GetInt("hitgroup"));
- int health = event->GetInt("health");
- int damage = event->GetInt("dmg_health");
- auto bitch_index = g_Engine->GetPlayerForUserID(bitch);
- auto coolguy49_index = g_Engine->GetPlayerForUserID(coolguy49);
- C_BaseEntity* bitch_ = (C_BaseEntity*)g_EntityList->GetClientEntity(bitch_index);
- C_BaseEntity* coolguy49_ = (C_BaseEntity*)g_EntityList->GetClientEntity(coolguy49_index);
- player_info_t killed_info = GetInfo(g_Engine->GetPlayerForUserID(bitch));
- player_info_t bitch_info;
- player_info_t coolguy49_info;
- if (coolguy49_ == local) {
- G::hitmarkeralpha = 1.f;
- if (g_Options.Misc.player_log) {
- g_Engine->ClientCmd_Unrestricted("play buttons\\arena_switch_press_02.wav");
- }
- }
- if (entityid == g_Engine->GetLocalPlayer()) {
- if (coolguy49 || bitch) {
- if (g_Options.Misc.player_log) {
- g_CVar->ConsoleColorPrintf(Color(255, 50, 50), "[SHOCKWAVE] ");
- g_CVar->ConsoleColorPrintf(Color(255, 255, 255), """hit %s in the %s for %i (%i remaining)\n", killed_info.name, hitbox, damage, health);
- std::stringstream string;
- string << " hit " << killed_info.name << " in the " << hitbox << " for " << damage << " (" << health << " remaining)";
- visuals::instance().events.push_front(visuals::loginfo(string.str(), Color(255, 255, 255), g_Globals->curtime));
- }
- }
- }
- }
- if (!strcmp(event->GetName(), "bullet_impact")) {
- C_BaseEntity* LocalPlayer = g_EntityList->GetClientEntity(g_Engine->GetLocalPlayer());
- if (LocalPlayer) {
- auto index = g_Engine->GetPlayerForUserID(event->GetInt("userid"));
- if (index != g_Engine->GetLocalPlayer())
- return;
- auto local = static_cast<C_BaseEntity*>(g_EntityList->GetClientEntity(index));
- if (!local)
- return;
- Vector position(event->GetFloat("x"), event->GetFloat("y"), event->GetFloat("z"));
- Ray_t ray;
- ray.Init(local->GetEyePosition(), position);
- CTraceFilter filter;
- filter.pSkip = local;
- trace_t tr;
- g_EngineTrace->TraceRay(ray, MASK_SHOT, &filter, &tr);
- logs.push_back(cbullet_tracer_info(local->GetEyePosition(), position, g_Globals->curtime, 255.0f));
- if (!local)
- return;
- for (size_t i = 0; i < logs.size(); i++) {
- auto current = logs.at(i);
- current.color = Color(255, 255, 255);
- BeamInfo_t beamInfo;
- beamInfo.m_nType = TE_BEAMPOINTS;
- beamInfo.m_pszModelName = "sprites/physbeam.vmt";
- beamInfo.m_nModelIndex = -1;
- beamInfo.m_flHaloScale = 0.0f;
- beamInfo.m_flLife = 3.f;
- beamInfo.m_flWidth = 1.f;
- beamInfo.m_flEndWidth = 1.f;
- beamInfo.m_flFadeLength = 0.0f;
- beamInfo.m_flAmplitude = 2.0f;
- beamInfo.m_flBrightness = 155.f;
- beamInfo.m_flSpeed = 0.2f;
- beamInfo.m_nStartFrame = 0;
- beamInfo.m_flFrameRate = 0.f;
- beamInfo.m_flRed = current.color.r();
- beamInfo.m_flGreen = current.color.g();
- beamInfo.m_flBlue = current.color.b();
- beamInfo.m_nSegments = 2;
- beamInfo.m_bRenderable = true;
- beamInfo.m_nFlags = FBEAM_ONLYNOISEONCE | FBEAM_NOTILE | FBEAM_HALOBEAM;
- beamInfo.m_vecStart = LocalPlayer->GetEyePosition();
- beamInfo.m_vecEnd = current.dst;
- if (g_Options.Misc.player_log) {
- auto beam = g_pViewRenderBeams->CreateBeamPoints(beamInfo);
- if (beam)
- g_pViewRenderBeams->DrawBeam(beam);
- }
- logs.erase(logs.begin() + i);
- }
- }
- }
- }
- }
- private:
- item_purchase_listener listener;
- };
- item_purchase purchase;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement