using hrc = std::chrono::high_resolution_clock; decltype(hrc::now()) invincible_before; if (take_damage()) { auto now = hrc::now(); if (now > invincible_before) { hp -= damage; invincible_before = now + std::chrono::seconds(3); // invincible in next 3s, for example } else { // player is invincible now! }