How to detect when player uses or drinks potion - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: How to detect when player uses or drinks potion (/thread-56387.html) |
How to detect when player uses or drinks potion - Andris - 06-01-2019 Scenario in my custom story: the player finds a health potion (laudanum) and when they drink it a specific event happens. I just don't know how to detect the moment when player drinks that potion. AddUseItemCallback() function (where asItem is health potion and asEntity is Player) is doesn't work even if player's health isn't full. Or it is not possible to do? RE: How to detect when player uses or drinks potion - Romulator - 06-01-2019 Create a new item in the Model Editor so that it is just an item that you can pickup in the World, then code it so that Daniel automatically drinks it and triggers the event. Spoiler below!
RE: How to detect when player uses or drinks potion - Mudbill - 06-02-2019 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: PHP Code: void OnStart() 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. |