Jump to content

Anyone interested in helping a beginner write a script?


Recommended Posts

Hey LL Community!

 

I've been working on a simple armor/clothing mod for Fo4 that implements a system of mix-and-match clothing pieces. I was able to create something very basic using the different biped slots, however I feel that this system could be much more efficient and seamless for the user if the mod were able to run [what I think to be] a simple script on equipping an armor/clothing.

I do have full knowledge of the CK and understand which forms need to be created in order to make this work. And I've already written out all the conditions that this script would need to run through. I just need help from anyone that would be willing to help me translate these into papyrus. My background lies primarily in 3d modeling and texture painting, so I'm a noob when it comes to programming (like computer science 101 over here). I'm more than willing to teach myself how to write the script by backtracking through other mods, but I would love a point in the right direction from any proficient papyrus writers out there!

 

So my current version of this mod renders the full body reference from OS with all pant meshes (for users to have the option of being "shirtless" when equipping only the pants). The shirts have zapped the reference body and use a different biped slot - the mesh is simply sized up larger than the ref body to fit on top of the torso. While this certainly works, there tends to be a lot of clipping between the shirt and torso of the ref (especially when users start introducing different body sliders from BS).

In order to avoid this problem, I wanted to split the reference body into torso and legs, rendering each with their respective shirt or pants mesh. In doing so, I'd be able to utilize zap sliders in both the shirt and pant nifs and avoid clipping altogether. However, the limitation here is that if players were to unequip a shirt while wearing pants, the torso would be completely invisible until they either equipped another shirt or unequipped those pants. To stream-line this process, I thought a script would be advantageous if it's possible at all.

Here's my end goal. I'd plan on creating 3 ARMO records for each shirt: one that was simply an inventory item for equipping and unequipping (a toggle essentially), one where the full reference body from OS is rendered, and one where the legs are zapped. And same goes for the pants, with their respective zaps. I'd attach this script to the inventory item, so that when the player equips the ARMO from their inventory, a short script will run to detect what is/isn't already equipped and choose the proper version of said ARMO to render. It would additionally need to detect which items were already equipped and re-render that model with the proper zapped version if needed.

 

In tinkering around on the CreationKit website, I'm thinking this could be done with the GetWornItem function through F4SE? I've seen some similar scripting going on in Kimy's DeviousDevices mod, so I feel like my scripting idea should be possible?

 

I'd appreciate any help I can get.

 

Thanks!

J

 

Link to comment
Share on other sites

Open your Armor >> Papyrus Scripts >> Add >> [New Script]

 

Name: myScript

Extends: ObjectReference

Const: checked

 

Right click on the script "myScript", then click "Edit Source".

 

Paste this code:

 

 

Scriptname myScript extends ObjectReference Const

Armor Property ArmorA Auto Const					                        ; the Armor you'd like to remove
Armor Property ArmorB Auto Const					                        ; the Armor you'd like to add

Event OnEquipped(Actor akActor)					                                ; event sent when the armor (this script is attached to) got equipped.
	Actor PlayerRef = Game.GetPlayer()				                        ; for optimization
	If akActor == PlayerRef					                                ; was the armor equipped by the Player? If so, continue.
		PlayerRef.RemoveItem((Self as ObjectReference).GetBaseObject(), abSilent=True)	; Remove the armor (this script is attached to) from the Player's inventory (abSilent = True means the unequip/equip notification in the upper left corner is suppressed)
		PlayerRef.RemoveItem(ArmorA, abSilent=True)		                        ; Remove ArmorA from the Player's inventory
		PlayerRef.AddItem(ArmorB, abSilent=True)		                        ; Add ArmorB to the Player's inventory
	Else							                                ; it wasn't equipped by the Player
		; you can place additional functions here
	EndIf
EndEvent

 

 

Press Ctrl+S to compile.

 

Close the "Editing script myScript" window. Click Properties >> click on a script property >> click "Edit Value" >> choose an Armor from the dropdown menu next to "Pick Object". Fill the other script property, then click OK.

 

Use the ; character to comment out AddItem, RemoveItem lines like:

; PlayerRef.AddItem(ArmorB, abSilent=True)		; ArmorB won't be added to the Player's inventory

Commented out lines won't be compiled.

 

About OnEquipped, AddItem and RemoveItem.

 

Oh and forgot to write the IsEquipped() function in the code:

 

 

Scriptname myScript extends ObjectReference Const

Armor Property ArmorA Auto Const					; the Armor you'd like to remove
Armor Property ArmorB Auto Const					; the Armor you'd like to add
Armor Property ArmorC Auto Const
Armor Property ArmorD Auto Const

Event OnEquipped(Actor akActor)					                                ; event sent when the armor (this script is attached to) got equipped.
	Actor PlayerRef = Game.GetPlayer()				                        ; for optimization
	If akActor == PlayerRef					                                ; was the armor equipped by the Player? If so, continue.
		PlayerRef.RemoveItem((Self as ObjectReference).GetBaseObject(), abSilent=True)	; Remove the armor (this script is attached to) from the Player's inventory (abSilent = True means the unequip/equip notification in the upper left corner is suppressed)
		PlayerRef.RemoveItem(ArmorA, abSilent=True)		                        ; Remove ArmorA from the Player's inventory
		PlayerRef.AddItem(ArmorB, abSilent=True)		                        ; Add ArmorB to the Player's inventory
		If PlayerRef.IsEquipped(ArmorC) == 1			                        ; if ArmorC is equipped by the Player
			PlayerRef.RemoveItem(ArmorC, abSilent=True)	                        ; Remove ArmorC
			PlayerRef.AddItem(ArmorD, abSilent=True)	                        ; Add ArmorD
		EndIf
	Else							                                ; it wasn't equipped by the Player
		; you can place additional functions here
	EndIf
EndEvent

 

 

Edited by LarannKiar
Link to comment
Share on other sites

@LarannKiar and @SKK50

 

Thank you BOTH for such quick responses!

 

@LarannKiar - this is an AMAZING start thank you so much. (I'm also most excited as reading through this script hasn't gone fully over my head lol)

 

While I think this looks VERY close to what I'm needing, if my understanding is correct, it's not quite right.

 

For example here, let's say the player is already wearing a pair of jeans from my mod but is shirtless (ArmorD). They want to equip a teeshirt. It seems like with your script, the user will need to choose between the 2 different tee shirt ARMOs (either with the reference body or with the legs zapped). The legs zapped option would be correct here, but I don't want them to have to pick between 2 different items in their inventory - I'd like ArmorA to be an inventory version and then the script would decide if it should render ArmorB or ArmorC based on what is already equipped.

 

Additionally, it seems like these properties would limit me to choose only 1 of my many models. I think I'd need some type of array to list out every single model for all of the different "bottoms" in the mod. And on equipping a "top", the script would run through the array of "bottoms" to see if any are equipped.

 

I feel like @SKK50 is on to something here. If I can add a keyword to every armo item that specifies which part of the body is rendered, the script won't need to run through said array of "bottoms" but it would just check for a keyword like "FullBodyRendered" or "LegsZapped" something like that?

 

 

Adding this text doc here if either of you might want to take a look: https://www.dropbox.com/s/b8k0jx8yzmduxvk/BrosOTC_ClothingMod_LogicForPapyrusScript.txt?dl=0

Edited by jcedrone1003
Link to comment
Share on other sites

  • Recently Browsing   0 members

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