Jump to content

[LE] Misc item losing its script


MaxShadow09

Recommended Posts

Hi people. I'm having a little problem with a mod I'm making. I have a misc item with a script attached. This script executes a little piece of code with the event OnContainerChanged. When I give myself a few of these items with the console, they work fine and do what they are supposed to do when I put them in a container. However, after playing for a while, keeping the item in my inventory, I put it inside another container and it does nothing. I have to give myself the item so it starts working again. It's like it is losing the script after a while. Do anyone know why this happens?

Edited by MaxShadow09
Link to comment
Share on other sites

Without seeing the script and knowing the exact scenario it would be impossible to make a remotely accurate guess.

 

Could be anything from the instance you have in your inventory existed prior to adding the script to the object. In which case, there is no script to run.

Could be that whatever conditions may be in place on the script for your stuff to happen are not being met at this particular time.

Could be way too much going on and the script processing is being delayed by an unknown amount of time.

Link to comment
Share on other sites

Inventory is a really strange beast in Bethesda's games. When you have a set of identical items in your inventory the game will eventually stack them together and if they have scripts attached only one script will run for the entire stack. One instance of the script should run unless there's some other problem, but if the player might have more than one of the item and you expect all copies of the script to fire individually you'll be very disappointed.

Link to comment
Share on other sites

This is the script:

Scriptname GSELinkerScript extends ObjectReference  

Perk Property GSE_Perk Auto
Message Property GSE_Menu1 Auto
Message Property GSE_Menu2 Auto
Message Property GSE_Menu3 Auto
Message Property GSE_Menu4 Auto
Message Property GSE_MenuWeapons Auto
Message Property GSE_MenuArmor Auto
Message Property GSE_MenuPotions Auto
Message Property GSE_MenuCrafting Auto
Message Property GSE_MenuFood Auto
Message Property GSE_CloseMessage Auto
FormList Property GSE_BannedContainers Auto
MiscObject Property GSE_Token Auto
MiscObject Property GSE_Linker Auto

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	if akOldContainer && akOldContainer == Game.GetPlayer() && akNewContainer && akNewContainer.GetBaseObject() as Container && !GSE_BannedContainers.HasForm(akNewContainer.GetBaseObject() as Container)
		if !Game.GetPlayer().HasPerk(GSE_Perk)
			Game.GetPlayer().AddPerk(GSE_Perk)
		endIf
		Menu(0,akNewContainer)
	endIf
endEvent

Function Menu(Int num = 0, ObjectReference akNewContainer)
	; stuff
EndFunction

Basically, when you put it inside a container, it gives a perk to the player, if he doesn't have it already, and then it shows a menu to select what "type" of container this will be (its for cloud storage and autosorting). The Menu() function has all the options that the player can choose, it's irrelevant now since the menu is not even shown unless I give myself the item again.

 

This is attached to the misc item in Creation Kit. As far as I can tell, it's not a script lag problem (I waited a long time and the menu still didn't show, then I give myself the same item and it starts working again). If I place the items from the same stack into different containers without leaving the cell, it works fine. It stops working after playing for a while. I'm aware of the stack bug, but I always place individual items, so that doesn't seem to be the problem.

Link to comment
Share on other sites

That really does sound like one version of the stack bug. One of the easiest solutions (if your mod concept allows it) is to only let the player ever have one copy of the item at a time and just automatically give a new copy whenever the first one is used. Another is to check how many of the item remain in the player's inventory when at least one is dropped/transferred and let the script remove all of the remaining items and add a new batch. In my Storage Helpers mod I eventually decided to monitor items being dropped through a ReferenceAlias on the player instead of scripts on the container token objects themselves.

 

I would personally try that second solution with something like this and see if it fixes the problem.

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	Actor PlayerRef = Game.GetPlayer()
	if akOldContainer == PlayerRef && akNewContainer && akNewContainer.GetBaseObject() as Container && !GSE_BannedContainers.HasForm(akNewContainer.GetBaseObject() as Container)
		if !PlayerRef.HasPerk(GSE_Perk)
			PlayerRef.AddPerk(GSE_Perk)
		endIf
		int i = PlayerRef.GetItemCount(GSE_Token) ; or should this be GSE_Linker?
		if i > 0
			PlayerRef.RemoveItem(GSE_Token, i, true)
			PlayerRef.AddItem(GSE_Token, i, true)
		endIf
		Menu(0,akNewContainer)
	endIf
endEvent
Link to comment
Share on other sites

GSE_Linker is the item that the player has to place inside the container to make it a cloud storage container (using General Stores framework). GSE_Token is an invisible item used to identify the container (the amount of token items inside the container is used by a perk to tell what kind of cloud storage we're interacting with). The player should be able to carry more than one linker, as it is a craftable item. Now that I remember, you were the one who gave me the idea of using tokens to identify containers. I was working on this mod for Oldrim, a couple of years ago, but then I lost it due to a hard drive failure. Now I'm doing it again for SSE.

 

Anyway, I just noticed something. When I give myself a couple of linker items, and I already have some in my inventory, I place them all in containers (one by one) and only 2 of them work, so only the last 2 I got have the script attached. It is possible that I recompiled the script at some point, and that made it detach from the old items somehow. I may be experiencing this problem because I have "old" items in my inventory, which don't have any script attached. I'll replace them all and play for a few hours to see if the problem persist.

Link to comment
Share on other sites

Nope, that was not the problem. I removed all my linker items from my inventory, and used the console to give myself 10 more. After playing for a while, I try to place them in a container (one by one), and only one of them worked. I still don't know what makes it lose the script. I tried these things:

Saving and then loading.
Leaving a cell and returning.

Restarting the game.

 

And in all cases the items were still working fine. There's something that makes it stop working at some point, but I don't know what it is.

 

EDIT: I noticed something weird. I had a quicksave from yesterday. When I load it today, the linker items were not working (only one of them worked). So, I remove them from my inventory and give myself 5 more. They all start working again. After that, I load a previous save (before the quicksave), and surprisingly, all the items were working fine. Once I readd them to my inventory, they start working for all my saves, but after playing for a while, they bug out again. Now I'm not sure if the items are losing the attached script, or there's something else causing this problem.

Edited by MaxShadow09
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...