fusronson Posted September 7 Share Posted September 7 Hi everyone, I'm working on a script to remove a key from the player's inventory after 1 hour, the code below is attached to the key. But after the hour the key still remain in the inventory. I added the message only to check if works but i haven't make it work. Am i missing something or there's a better way to do this?. Any help will be appreciated. Scriptname RemoveItem extends ObjectReference Key Property KeyDoor Auto Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) if akNewContainer == Game.GetPlayer() Debug.Messagebox("I just got put in the player's inventory!") RegisterForSingleUpdateGameTime(1.0) endIf endEvent Event OnUpdateGameTime() if (Game.GetPlayer().GetItemCount (KeyDoor) == 1) Debug.Messagebox("I just got removed from the player's inventory!") Game.GetPlayer().RemoveItem(KeyDoor, 1) endIf EndEvent Link to comment Share on other sites More sharing options...
xkkmEl Posted September 7 Share Posted September 7 Items in containers or inventories don't handle events very well. I am unsure of the details about what works and doesn't, but I am not surprised you are having difficulties with OnUpdateGameTime. I suggest you simply move your timer event handling to another form... a running quest for example... Do test whether the OnContainerChanged event is reliable... I think it is (at least to detect the item being picked up) but I haven't tested it extensively. Link to comment Share on other sites More sharing options...
greyday01 Posted September 7 Share Posted September 7 I think the problem is that the key with the script is a specific reference but when it is added to the player's inventory that reference no longer exists. The container has a listing of all the base objects inside it with the number of each type. Maybe a quest with the script on the player would work. Link to comment Share on other sites More sharing options...
xkkmEl Posted September 7 Share Posted September 7 Well, the game does keep "special" references intact when they move in/out/through inventory. However, event handling is compromised in some ways for anything not in a loaded cell. Being in the inventory of a reference that is in a loaded cell does not appear to count for "in a loaded cell" as far as events go. I think some events do work as long as the ref is in ram... I just don't have the details of which need the attached cell and which don't. There are also events that depend on the object being in contact with the nav mesh... or be 3dloaded... it's confusing mess Link to comment Share on other sites More sharing options...
scorrp10 Posted September 8 Share Posted September 8 One option is to have a running quest with player loaded as alias and on that alias, a script with 'OmItemAdded' event handler, that uses RegisterForSingleUpdateGameTime to set a timer for itself, and then OnUpdate handler would remove the key. Or, when player obtains the key, place an ability-type magic effect on the player - and it is the script for this magic effect that will register for a singleupdate in one hour, and remove the key before dispelling itself. This approach is better if you potentially have several of those 'timed' items. Link to comment Share on other sites More sharing options...
Evangela Posted September 9 Share Posted September 9 On 9/7/2024 at 6:41 PM, greyday01 said: I think the problem is that the key with the script is a specific reference but when it is added to the player's inventory that reference no longer exists. The container has a listing of all the base objects inside it with the number of each type. Maybe a quest with the script on the player would work. This is one of the many bugs with GetItemCount in regards to using ObjectReferences to check for. However Key property in that script is only pointing to the form which GetItemCount works well for. Items in the inventory aren't references anymore but forms. Link to comment Share on other sites More sharing options...
fusronson Posted September 9 Author Share Posted September 9 (edited) Hi guys, thanks for the responses. I'm actually creating the quest to add the script, i'll let you know if works or not. Thanks to everyone (I edit the original message because i didn't create the SEQ file with the SSEEdit and the option now appears). Edited September 9 by fusronson Link to comment Share on other sites More sharing options...
fusronson Posted September 9 Author Share Posted September 9 Hi guys, me again. I created the quest for the key script but i couldn't make work. BUT!, i could create an script directly to the Key and this work. I left the script if someone needs. Scriptname aaakeyscript extends ObjectReference Key Property aaaTestKey Auto Import Utility Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) Utility.WaitGameTime(10) ;-> this value will wait 10 game hours if akNewContainer == Game.GetPlayer() Game.GetPlayer().RemoveItem(aaaTestKey, 1) EndIf EndEvent Link to comment Share on other sites More sharing options...
PeterMartyr Posted September 22 Share Posted September 22 On 9/7/2024 at 12:05 PM, fusronson said: the code below is attached to the key. Your making two mistakes your using a Key property instead of an ObjectReference you do not need an ObjectReference property in a script that extends ObjectReference since Papyrus is Object Orientated Code Scriptname RemoveItem extends ObjectReference Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) if akNewContainer == Game.GetPlayer() Debug.Messagebox(Self+" just got put in the player's inventory!") Self.RegisterForSingleUpdateGameTime(1.0) ElseIf akOldContainer == Game.GetPlayer() ;incase the player removes it Debug.Messagebox(Self+" just got removed from the player's inventory!") Self.UnregisterForUpdateGameTime() endIf endEvent Event OnUpdateGameTime() If GetItemCount(Self) == 1 Debug.Messagebox(Self+" just got removed from the player's inventory!") Game.GetPlayer().RemoveItem(self) Else Debug.MessageBox("failed to remove item on update") EndIf EndEvent your were so close)) Noticed I replace the Key with "Self" as an Object? Plus I even used it the debug.... Edit Just in case, do not add the script to Key Record, in the cell window, add the script to Key ObjectReference that will be in the Game Link to comment Share on other sites More sharing options...
Recommended Posts