I don't think there are any reliable ways of detecting when a potion is drank in the inventory. The closest would be to use a looping timer to continuously check if HasItem is false after they pick it up, which would tell you when it is no longer in the inventory of the player. But looping a timer over a long time is risky business, as it may cause the game to crash if they loop over 65 000 times. But I suppose looping it only once a second should be fine, since it would take you like 20 hours to hit that crash limit.
Starts similarly to Rom's code:
void OnStart()
{
SetEntityCallbackFunc("potion_health_1", "PickUpEvent");
}
void PickUpEvent(string &in asEntity, string &in Type)
{
// Start the timer loop
TimerLoopCheckItem("my_timer_name");
}
void TimerLoopCheckItem(string &in asTimer)
{
if(HasItem("potion_health_1") == false)
{
// Item no longer exists in the player's inventory
}
else
{
AddTimer(asTimer, 1.0f, "TimerLoopCheckItem");
}
}
This checks every 1 second if the item exists, which means it may take up to a second before the game detects it after you close the inventory. Unfortunately it won't automatically close the inventory or anything, but wait until it's closed manually.