I have a mod in the works which requires quite some scripting. Most of it is done, however, I am having a few bugs. I'll explain in detail what the purpose of this all is.
I wanted to create a container, which you can pick up and take with you and drop and use as a container again everywhere you want. This container gets gold added every day, which you can take out of the container. But I don't want players to be able to add items to the container, except for gold.
The way I tried to do this, using the Bag of Holding mod as an example, was creating the container and adding a script to it. Next I created a misc item with a script attached to it. Then I put the container in the world and named the reference MyContainerREF. I also created three messages, one call MyMessage acting as a menu, which activates when trying to open the container, asking the player if he/she wants to open the container or take it. Next message, called MyGrabMessage, is shown once, explaining to the player that using the grab key on the container will make it show the menu again, allowing you to take it. Last message, called MyNoItemsMessage, is a notification which is shown when the player tries to add anything but gold to the container. Lastly, I created a quest which handles the adding of gold to the container.
Now, I've a few bugs going on here and that's where I need help. The container works fine the first time you take it, showing the menu, being able to take out gold and being able to take the container, which adds the misc item to your inventory and disables the container. However, despite me trying and although the notification works, you can still add items to the container. This is the first bug. The second bug involves dropping the misc item and using the container again. When dropping the misc item, the misc item gets removed from the world and the container is moved to the player and enabled. However, sometimes it stays invisible and most of the time it is or floating in mid air, or it's stuck halfway in the ground. When this happens, sometimes the menu still works, but most of the time it doesn't work anymore, you can't take it or open it and it will often go invisible. So it's bugged. I've added all the code I used on here, and put comments next to the sections that don't work or don't work correctly. The first script is the script on the container, the next script is the script on the misc item. I am totally clueless on what's causing these problems and I would really appreciate any help you guys can give me. Thanks in advance.
Also, I'm mainly looking for suggestions on how to prevent items to be added in a container and how to move the container in a way that it doesn't get stuck in midair or in in the ground. Maybe PlaceAtMe is a better way then moveto? But the most important thing is to fix the swapping between container and misc item not working.
Also, I'm mainly looking for suggestions on how to block items being added to the container, except for gold, and on how to move the container to the player in such a way, it doesn't get stuck in the ground or floats in midair.Also, I'm mainly looking for suggestions on how to block items being added to the container, except for gold, and on how to move the container to the player in such a way, it doesn't get stuck in the ground or floats in midair.
The container script:
Scriptname MyContainerScript extends ObjectReferenceInt iCount = 0Int iButton = 0Int bMessage = 0Int bShowOnce = 1MiscObject Property MyMiscItem AutoMiscObject Property Gold AutoMessage Property MyMessage AutoMessage Property MyGrabMessage AutoMessage Property MyNoItemsMessage AutoEvent OnGrab()bMessage = 1BlockActivation(True)EndEvent;===========================================Event OnActivate(ObjectReference akActionRef)If akActionRef == Game.GetPlayer()If Game.GetPlayer().GetItemCount(MyMiscItem)BlockActivation(False)ElseIf bMessageiButton = MyMessage.Show()If (iButton == 0) ; OpenBlockActivation(False)Activate(Game.GetPlayer())bMessage = 0If bShowOncebShowOnce = 0MyGrabMessage.Show() ;<- This does not workEndIfElseIf (iButton == 1) ; TakeDisable()bMessage = 1Game.GetPlayer().AddItem(MyMiscItem, 1)BlockActivation(False)EndIfEndIfEndIfEndEvent;==========================================Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) ;This event does not work, except for the messageIf (akBaseItem == Gold)ReturnElseif (akBaseItem != Gold)RemoveItem(akItemReference, aiItemCount)Game.GetPlayer().AddItem(akItemReference, aiItemCount, True)MyNoItemsMessage.Show()EndifIf (akBaseItem == MyMiscItem)RemoveItem(MyMiscItem, aiItemCount)Game.GetPlayer().AddItem(MyMiscItem, aiItemCount, True)EndIfEndEvent
The misc item script:
Scriptname MyMiscItemScript extends ObjectReferenceInt iCountObjectReference Property MyContainerREF AutoMiscObject Property MyMiscItem AutoEvent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)If akNewContainerIf akOldContainerIf (akOldContainer == Game.GetPlayer())akOldContainer.RemoveItem(MyMiscItem, 1, True, akOldContainer)EndIfElseIf (akNewContainer == Game.GetPlayer())iCount = akNewContainer.GetItemCount(MyMiscItem)If (iCount > 0)iCount -= 1akNewContainer.RemoveItem(MyMiscItem, iCount, True)EndIfEndIfElseIf !akNewContainerIf MyContainerREF.IsDisabled() MyContainerREF.Enable()EndIf MyContainerREF.MoveTo(Self)Disable()Delete()EndIfEndEvent
