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...

A little scripting help


ThomasKaira
 Share

Recommended Posts

Okay, I've just set up a "container crawler" function whose objective is to check the containers found in the MerchContainers FormList for any items found in the MerchBase FormList, and if it finds any, replace them with the equivalent item in the MerchImports FormList.

Here is the code (which compiles):

scriptname aaTKMerchantOverwatchScript extends Quest


FormList property aaTKWRMerchants auto

FormList property aaTKRFMerchants auto

Formlist property aaTKWHMerchants auto

FormList property aaTKMKMerchants auto

FormList property aaTKSLMerchants auto


FormList property aaTKWRBase auto

FormList property aaTKRFBase auto

Formlist property aaTKWHBase auto

FormList property aaTKMKBase auto

FormList property aaTKSLBase auto


FormList property aaTKWRImports auto

FormList property aaTKRFImports auto

Formlist property aaTKWHImports auto

FormList property aaTKMKImports auto

FormList property aaTKSLImports auto


Event On<something>


CheckContainers(aaTKWRMerchants, aaTKWRImports, aaTKWRBase)

CheckContainers(aaTKRFMerchants, aaTKRFImports, aaTKRFBase)

CheckContainers(aaTKRFMerchants, aaTKRFImports, aaTKRFBase)

CheckContainers(aaTKRFMerchants, aaTKRFImports, aaTKRFBase)

CheckContainers(aaTKRFMerchants, aaTKRFImports, aaTKRFBase)


RegisterForSingleUpdate(10)


EndEvent


Function CheckContainers(FormList MerchContainers, FormList MerchImports, Formlist MerchBase)


	int i = 0

	int x = 0


	While i < MerchContainers.getSize()


		ObjectReference Target = MerchContainers.GetAt(i) as ObjectReference


		While x < MerchBase.GetSize()


			ObjectReference ItemTarget = MerchBase.getAt(x) as ObjectReference

			ObjectReference ImportTarget = MerchImports.getAt(x) as ObjectReference


			If Target.GetItemCount(ItemTarget) != 0


				Int ItemCountInt = Target.GetItemCount(ItemTarget)


				Target.RemoveItem(ItemTarget, ItemCountInt, true)

				Target.AddItem(ImportTarget, ItemCountInt, true)


			EndIf


		x += 1


		EndWhile


	i += 1


	EndWhile


EndFunction

My question is: how would I set this script up so that it runs only at the end of a barter session (if possible)? I don't want to waste resources by having it run constantly in the background.

I still need to set up the properties, of course.

EDIT: cleaned up a little whoopsie. My RemoveItem/AddItem lines were referring to the base formlists, not the actual items. XD

EDIT2: Filled in the properties and set up the event, all I need now is to get the <something> value filled in.

Edited by ThomasKaira
Link to comment
Share on other sites

Well, I could always check what this other guy did. I checked my script against his while writing it up (since he has a script that does something similar to mine), so that should clue me in.

EDIT: Well, he has it attached to a dummy quest, so I know it can function as a simple quest script.

EDIT2: Ahh, I see now, he calls for the script to run from a parent script, and triggers the operation through a Papyrus Fragment.

And that also solves how I can get around the issues of using OnInit() to kickstart the scripts.

Edited by ThomasKaira
Link to comment
Share on other sites

Okay, I've got some code that compiles and runs, but it doesn't really seem to do anything. The goal is to check if the merchant containers in FormList A have items found in FormList B, and if they do, replace them with items in FormList C.

Scriptname aaTKMerchantOverwatchScript extends Quest


FormList property aaTKSLMerchants auto

FormList property aaTKMKMerchants auto

FormList property aaTKWHMerchants auto

FormList property aaTKRFMerchants auto

FormList property aaTKWRMerchants auto


FormList property aaTKSLBase auto

FormList property aaTKSLImports auto

FormList property aaTKMKBase auto

FormList property aaTKMKImports auto

Formlist property aaTKWHBase auto

Formlist property aaTKWHImports auto

FormList property aaTKRFBase auto

FormList property aaTKRFImports auto

FormList property aaTKWRBase auto

FormList property aaTKWRImports auto


Event OnUpdate()


CheckContainers(aaTKSLMerchants, aaTKSLBase, aaTKSLImports)

CheckContainers(aaTKMKMerchants, aaTKMKBase, aaTKMKImports)

CheckContainers(aaTKWHMerchants, aaTKWHBase, aaTKWHImports)

CheckContainers(aaTKRFMerchants, aaTKRFBase, aaTKRFImports)

CheckContainers(aaTKWRMerchants, aaTKWRBase, aaTKWRImports)


Debug.Notification("Updating merchant item prices")


RegisterForSingleUpdate(10)


EndEvent


Function MerchStartCheck()


	RegisterForSingleUpdate(1)


EndFunction


Function CheckContainers(FormList MerchContainer, FormList Base, FormList Imports)


	int i = 0

	int x = 0


	While i < MerchContainer.getSize()


		ObjectReference Target = MerchContainer.getAt(i) as ObjectReference


		If Target != none && Target.IsEnabled()


			While x < Base.GetSize()


				ObjectReference ItemTarget = Base.getAt(x) as ObjectReference

				ObjectReference ImportTarget = Imports.getAt(x) as ObjectReference


				If Target.GetItemCount(ItemTarget) != 0


					Int ItemCount = Target.GetItemCount(ItemTarget)


					Target.RemoveItem(ItemTarget, ItemCount)

					Target.AddItem(ImportTarget, ItemCount)


				EndIf


			x += 1


			EndWhile


		EndIf


		i += 1


	EndWhile


EndFunction



Link to comment
Share on other sites

Okay, I think I can very much say I am extraordinarily stuck. No matter what I try, absolutely nothing works. I've changed the FormLists, I've redefined what is on them for the script, but it still resolutely refuses to work.

Scriptname aaTKMerchantOverwatchWeapon extends Quest


FormList property MKMerchants auto


FormList property MKBase auto


FormList property MKImports auto



Event OnUpdate()


CheckContainers(MKMerchants, MKBase, MKImports)


RegisterForSingleUpdate(10)


EndEvent


Function MerchStartCheck()


	RegisterForSingleUpdate(1)


EndFunction


Function CheckContainers(FormList Merchants, FormList Base, FormList Imports)


	int i = 0

	int x = 0


	While (i < Merchants.getSize())


		ObjectReference Target = Merchants.getAt(i) as ObjectReference


		;Debug.Trace("Form " + i + " is " + Merchants.GetAt(i))


		i = i + 1


		While x < Base.GetSize()


			If Target != none && Target.IsEnabled()


			Weapon ItemTarget = Base.getAt(x) as Weapon

			Weapon ImportTarget = Imports.getAt(x) as Weapon


				If Target.GetItemCount(ItemTarget) != 0


					Int ItemCount = Target.GetItemCount(ItemTarget)


					Target.RemoveItem(ItemTarget, ItemCount)

					Target.AddItem(ImportTarget, ItemCount)

					Disable()

					Enable()


				Debug.Notification("Updating Merchant Prices")


				EndIf


			x = x + 1


			EndIf


		EndWhile


	EndWhile



EndFunction

And the total silence I've received about this issue is beginning to make me wonder if what I am trying to do is even possible.

Link to comment
Share on other sites

What you're trying to do should be possible. How far are you getting in the script? By that I mean do you see this in-game: "Debug.Notification("Updating Merchant Prices")"? If you don't, then your script isn't initializing or it's runnning into a run-time error before it reaches that statement. One thing to try would be inserting Debug.Notification() statements at certain parts of your code. See which ones show up.

Also, I don't think you can cast from Form to ObjectReference. It's a one-to-many relation (one Form can have many ObjectReferences pointing to it) so the game probably wouldn't know which reference to choose. I could be wrong though and it might be possible to cast from Form to ObjectReference. Try making an ObjectReference property that points to a specific merchant/merchant's chest and try it out with that merchant.

I hope any of this helps.

Link to comment
Share on other sites

  • 1 month later...

Well, not sure I need to make a new thread, so I bump this one.

I need some help with script in dialogue. I type in the Papyrus window this line:

akSpeaker.additem(aaKey,1)

akSpeaker.removeitem(Gold001,6000)

IVaN1l.png

Compilation is okey, but nothing happens in game, no adding, no removing. What's wrong?

P.S. Not sure, maybe i should post it in Quest section, sorry.

Link to comment
Share on other sites

I don't see anything obvious wrong wtih the script. Your properties look to be setup right.

I am not a 'dialog' or 'quest' maker, but where is 'akSpeaker' pointing? Is it auto-generated within the quest script?

It seems that the person saying the dialog would get the key and gold, not the player.

You did not really say what you expect to happen.

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...