Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

GetItemCount problems on Containers


Cliffworms
 Share

Recommended Posts

Greetings!

I've been trying to get a script to work on a container. The script checks if the container has two particular items. But for some reason, the GetItemCount condition is not working.

Here are the details:

The script is attached on a container. The player is tasked with placing a fake letter in a sack and removing the real letter.

The script sets a Int to 1 if it sees that the sack has the fake letter, sets another Int to 0 if it sees it does not have the real letter and when the conditions are met, it updates the quest stage to confirm the player has succesfully done his job.

Here is the script, followed by the error report:

Scriptname TOSInn01CourierSackScript extends ObjectReference


Quest Property TOSInn01Quest  Auto

Container Property ContainerTOSInn01CourierSack  Auto 

Book Property BookTOSInn01RealLetter  Auto

Book Property BookTOSInn01FakeLetter  Auto


Int Property FakeLetterPlaced  Auto  

Int Property RealLetterPlaced  Auto;   Set to 1 by default


Event OnInit()

	RegisterForUpdate(1)

	GoToState("InventoryCheck")

EndEvent


State InventoryCheck


	Event OnUpdate()

		If FakeLetterPlaced == 0

			If (ContainerTOSInn01CourierSack.GetItemCount(BOOKTOSInn01FakeLetter) == 1)

				FakeLetterPlaced = 1

			else

				FakeLetterPlaced = 0

			Endif

		Endif


		If RealLetterPlaced == 1

			If (ContainerTOSInn01CourierSack.GetItemCount(BOOKTOSInn01RealLetter) == 0)

				RealLetterPlaced = 0

			else

				RealLetterPlaced = 1

			Endif

		Endif


		If FakeLetterPlaced == 1 && RealLetterPlaced == 0

				TOSInn01Quest.SetStage(20)

		Endif

	EndEvent


EndState

And the error report:

Starting 1 compile threads for 1 files...

Compiling "TOSInn01CourierSackScript"...

d:\jeux\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\TOSInn01CourierSackScript.psc(20,36): GetItemCount is not a function or does not exist

d:\jeux\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\TOSInn01CourierSackScript.psc(20,73): cannot compare a none to a int (cast missing or types unrelated)

d:\jeux\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\TOSInn01CourierSackScript.psc(28,36): GetItemCount is not a function or does not exist

d:\jeux\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\TOSInn01CourierSackScript.psc(28,73): cannot compare a none to a int (cast missing or types unrelated)

No output generated for TOSInn01CourierSackScript, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.

Failed on TOSInn01CourierSackScript

I'm confused. :P

Link to comment
Share on other sites

You should be using OnClose instead.

The script you have would try to run constantly when its not needed.

With OnClose, you can check the status of the container contents when the player closes the container.

Your probably getting errors becuase not all functions are available in an OnUpdate event.

Link to comment
Share on other sites

Why would certain functions not be available in an OnUpdate event? He's getting errors because Container inherits from Form. GetItemCount() is a part of ObjectReference (first error). The compiler can't find the function he's trying to use so it's replacing the result of the call with null (second error).

If TOSInn01CourierSackScript is being attached directly to ContainerTOSInn01CourierSack, you could use self.GetItemCount() (self isn't necessary, I'm just using it to show who's making the call). You also wouldn't need the ContainerTOSInn01CourierSack property that way.

I also second WillieSea's suggestion of using the OnClose event. It was written for these types of scenario and, overall, will be more accurate and less resource-intensive than OnUpdate.

Edit: My grammars. And I accidentally some words.

Edited by trira
Link to comment
Share on other sites

The problem with OnClose is that the event initiates only when the object finishes its closing animation. In the case of most containers, there is no such animation so the event never initiates. In this case, the sack does not have a close animation.

Thank you for the tips, Will and Trira, I'll try with these modifications and let you know what happens. :thumbup:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...