Jump to content

Newbie Modder, Scripting Help for Settlement Mod


EternalGuard

Recommended Posts

Hello there! I am currently making a settlement mod that would, ideally, create a settlement upon the cell reset after you have gained control of the settlement. (I'm doing this because while I love the many settlement creation mods that exist, I have a friend who rejects the settlement system entirely but loves the other mechanics of the game and so this idea grew from there.) While I'm not a stranger to the creation kit itself, scripting - papyrus particularly - is something I am extremely new to and couldn't find any other questions on this specific topic through the combined magics of Google, Bing, and DuckDuckGo.

 

Currently, I have restricted myself to the settlements that are simple clearing settlements, (i.e. Taffington Boathouse, Croup Manor, Murkwater Construction Site, etc.) but I will run out of these in short order. I am using the following script for the cleared settlements:

Scriptname MCC01:MCC01EnabledClearedSettlement extends ObjectReference Const
{This script is used by my mod to enable the settlement once the workshop is player owned.}

Event OnCellDetach()
	if self.isEnabled()
		self.Enable()
	Else
		getLinkedRef().isDisabled()
		self.enable()
	endif
EndEvent

As you can see, it's an extremely basic script as I just started my delve into the wonderful ball of yarn that is Papyrus. The linked ref this refers to is the xmarker that is disabled after the site is cleared.

 

My question, as I see it, is: Do any of you wonderful (or not wonderful people if that's your thing) know of a way to run the script (enabling the xmarker) off of workshop ownership rather than banking on an existing reference being disabled?

 

A few of the settlements may need to be tied to quests (namely the Airport and Sanctuary) but I'm seeking others' experience in seeing if I can get a general script that activates off of the player owning the workshop.

 

Any advice that anyone can provide would be very much appreciated!

 

Thank you for taking your time to read this at least!

 

-EternalGuard

Link to comment
Share on other sites

Hey there, Pepperman! Thanks for the advice! I've read up on and watched tutorials on these two topics - seeing how to fix them through FO4edit or at least mitigate the damage. Thanks for the link though, I'll be sure to read through it so as to educate myself further on the matter!

Edited by EternalGuard
Link to comment
Share on other sites

You are looking for custom event WorkshopPlayerOwnershipChanged generated by WorkshopParentScript if you are limiting this to registered workshops (not isloated player homes).

 

This can get complex for a scripting noob, so here is a sample script you can attach to a placed ObjectReference:

Quest 		Property pWorkshopParent  Auto Const Mandatory
ObjectReference Property MyWorkshopREF 	  Auto 

Event OnInit() 
	Self.RegisterForCustomEvent((pWorkshopParent as WorkshopParentScript), "WorkshopPlayerOwnershipChanged") 
EndEvent

Event WorkshopParentScript.WorkshopPlayerOwnershipChanged(WorkshopParentScript akSender, Var[] akArgs)
	If (akArgs.Length > 0)
		bool bPlayerOwned = akArgs[0] as Bool
		WorkshopScript WorkshopREF = akArgs[1] as WorkshopScript

		If WorkshopREF == MyWorkshopREF && (WorkshopREF.OwnedByPlayer == TRUE)
			Self.UnRegisterForCustomEvent((pWorkshopParent as WorkshopParentScript), "WorkshopPlayerOwnershipChanged") ;cleanup
			MyWorkshopREF = none ;cleanup
			;do my stuff here, probably set a script state to enable the next OnCellDetach or OnUnload event for a layer swap.
		Endif
	EndIf
EndEvent
Link to comment
Share on other sites

 

You are looking for custom event WorkshopPlayerOwnershipChanged generated by WorkshopParentScript if you are limiting this to registered workshops (not isloated player homes).

 

This can get complex for a scripting noob, so here is a sample script you can attach to a placed ObjectReference:

Quest 		Property pWorkshopParent  Auto Const Mandatory
ObjectReference Property MyWorkshopREF 	  Auto 

Event OnInit() 
	Self.RegisterForCustomEvent((pWorkshopParent as WorkshopParentScript), "WorkshopPlayerOwnershipChanged") 
EndEvent

Event WorkshopParentScript.WorkshopPlayerOwnershipChanged(WorkshopParentScript akSender, Var[] akArgs)
	If (akArgs.Length > 0)
		bool bPlayerOwned = akArgs[0] as Bool
		WorkshopScript WorkshopREF = akArgs[1] as WorkshopScript

		If WorkshopREF == MyWorkshopREF && (WorkshopREF.OwnedByPlayer == TRUE)
			Self.UnRegisterForCustomEvent((pWorkshopParent as WorkshopParentScript), "WorkshopPlayerOwnershipChanged") ;cleanup
			MyWorkshopREF = none ;cleanup
			;do my stuff here, probably set a script state to enable the next OnCellDetach or OnUnload event for a layer swap.
		Endif
	EndIf
EndEvent

Hey SKK50! Thank you for the sample script! Scripting really is a whole new language to learn. Still struggling to learn it but not giving up. I've plugged your sample script into the game and attempted to add a script state but my skills are sub-par at the moment (though that does not deter me - it is simply 4:00 am where I am and so I will sleep on it and awaken tomorrow to work at making it successful) so I'm reaching mismatched input, expecting EndIf errors - though I'll learn keep on working on it tomorrow, I am good at bashing my head into walls until I'm through them at the very least!

 

Thanks again for your help!

 

P.S. My friend whose hatred of the settlement system inspired me to make this mod is a huge fan of your Killable Preston mod!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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