- Status
- Offline
- Joined
- Apr 18, 2019
- Messages
- 147
- Reaction score
- 249
Hi everyone, now I will show you how to add a timer for molotov. Let's start
- Add a new entity class
Code:struct inferno_t : public entity_t{ OFFSET( float, get_spawn_time, 0x20 ); static float get_expiry_time() { return 7.f; } };
- Find all the molotovs on the map
Code:utils::game::for_every_entity( []( entity_t* ent ) -> void { auto inferno = reinterpret_cast< inferno_t* >( ent ); }, { utils::game::e_entity_iteration_flags::FILTER_CLASSID }, e_class_id::CInferno );
Code:enum e_entity_iteration_flags { FILTER_CLASSID = 1 << 0 }; void for_every_entity( const std::function<void( entity_t* ent )>& func, bitflag_t flags, int classid ) { for ( auto i = 0; i < ctx.csgo.entlist->GetHighestEntityIndex(); i++ ) { auto entity = ctx.csgo.entlist->get<entity_t>( i ); if ( !entity ) continue; if ( flags.has_flag( e_entity_iteration_flags::FILTER_CLASSID ) && classid != entity->GetClientClass()->m_ClassID ) continue; func( entity ); } }
- Making a simple implementation of style and logic. For the example:
-
Code:
utils::game::for_every_entity( []( entity_t* ent ) -> void { auto inferno = reinterpret_cast< inferno_t* >( ent ); const auto origin = inferno->get_abs_origin(); auto screen_origin = vec3_t(); if ( !utils::game::world_to_screen( origin, screen_origin ) ) return; const auto spawn_time = inferno->get_spawn_time(); const auto factor = ( ( spawn_time + inferno_t::get_expiry_time() ) - ctx.csgo.globals->curtime ) / inferno_t::get_expiry_time(); static auto size = vec2_t( 60, 10 ); render::rect_filled( vec2_t( screen_origin.x - size.x * 0.5, screen_origin.y - size.y * 0.5 ), size, col_t::palette_t::grey( ) ); render::rect_filled( vec2_t( screen_origin.x - size.x * 0.5 + 2, screen_origin.y - size.y * 0.5 + 2 ), vec2_t( ( size.x - 4 ) * factor, size.y - 4 ), col_t::palette_t::red() ); render::rect( vec2_t( screen_origin.x - size.x * 0.5, screen_origin.y - size.y * 0.5 ), size, col_t::palette_t::light_black() ); }, { utils::game::e_entity_iteration_flags::FILTER_CLASSID }, e_class_id::CInferno );