glewisguy Posted June 22, 2016 Share Posted June 22, 2016 Hi all, I'm having some trouble with some scripts for a mod I've been making. I've managed to complete all of the other scripts I needed apart from this one which is proving to be very difficult. What I need to do is produce a list of all of the settlements owned by the player (as in which ones they can build on). My first thought for doing this was to create an ObjectReference array and manually set each element as the workbenches available in the vanilla fallout world. I then created a second array of booleans of the same length. This did not work, I can't think of any other ideas that would work. If anyone is able to help me out and is able to do so in a way that the script can support settlements added in through mods too that would be great. Many thanks, Grant Link to comment Share on other sites More sharing options...
Engager Posted June 22, 2016 Share Posted June 22, 2016 Sure i can help you man, here is part of the script from my War Of the Commonwealth mod: Event OnInit() StoryFactionForce = new float [4] WorkShopIDs = new ObjectReference[27] WorkShopIDs[0] = Game.GetForm(0x00168945) as ObjectReference ;Coastal Cottage 1 WorkShopIDs[1] = Game.GetForm(0x001654B8) as ObjectReference ;Kingsport Lighthouse 2 WorkShopIDs[2] = Game.GetForm(0x001654BD) as ObjectReference ;Croup Manor 3 WorkShopIDs[3] = Game.GetForm(0x0009B197) as ObjectReference ;Slog 4 WorkShopIDs[4] = Game.GetForm(0x0009B19D) as ObjectReference ;Finch Farm 5 WorkShopIDs[5] = Game.GetForm(0x0009B1F1) as ObjectReference ;Greentop Nursery 6 WorkShopIDs[6] = Game.GetForm(0x0009B1DB) as ObjectReference ;Country Crossing 7 WorkShopIDs[7] = Game.GetForm(0x0009B1BE) as ObjectReference ;Nordhagen Beach 8 WorkShopIDs[8] = Game.GetForm(0x00135A90) as ObjectReference ;Taffington BoatHouse 9 WorkShopIDs[9] = Game.GetForm(0x000E0505) as ObjectReference ;Covenant 10 WorkShopIDs[10] = Game.GetForm(0x00024A26) as ObjectReference ;Zimonja 11 WorkShopIDs[11] = Game.GetForm(0x0009B1AC) as ObjectReference ;Tenpines Bluff 12 WorkShopIDs[12] = Game.GetForm(0x0009B1A5) as ObjectReference ;Warwick Homestead 13 WorkShopIDs[13] = Game.GetForm(0x00066EB6) as ObjectReference ;Castle 14 WorkShopIDs[14] = Game.GetForm(0x0016D28E) as ObjectReference ;Murkwater Construction Site 15 WorkShopIDs[15] = Game.GetForm(0x001654CF) as ObjectReference ;Jamaica Plain 16 WorkShopIDs[16] = Game.GetForm(0x001E81EA) as ObjectReference ;Summerville Place 17 WorkShopIDs[17] = Game.GetForm(0x00164321) as ObjectReference ;Egret Tours Marina 18 WorkShopIDs[18] = Game.GetForm(0x00019956) as ObjectReference ;Bunker Hill 19 WorkShopIDs[19] = Game.GetForm(0x001F0711) as ObjectReference ;Hangman 20 WorkShopIDs[20] = Game.GetForm(0x0009B1D1) as ObjectReference ;Oberland Station 21 WorkShopIDs[21] = Game.GetForm(0x0009B18F) as ObjectReference ;Graygarden 22 WorkShopIDs[22] = Game.GetForm(0x001654D5) as ObjectReference ;Sunshine Tidings 23 WorkShopIDs[23] = Game.GetForm(0x0001D0E2) as ObjectReference ;Starlight Drivein 24 WorkShopIDs[24] = Game.GetForm(0x0006F5C5) as ObjectReference ;Abernathy Farm 25 WorkShopIDs[25] = Game.GetForm(0x00054BAE) as ObjectReference ;RedRocket 26 WorkShopIDs[26] = Game.GetForm(0x000250FE) as ObjectReference ;Sanctuary 27 EndEvent ; Function part that gets number of settlers, happiness etc: Int I = 0 int NSettler = 0 int NHappiness = 0 float MinutemenTotalScore = 0 workshopscript WorkshopScriptRef workshopparentscript WorkshopParent workshopdatascript:workshopratingkeyword[] ratings ; Set to workshopdatascript:workshopratingkeyword[] for CK compile. I = 0 While (I <= 26) WorkshopScriptRef = WorkShopIDs[I] as workshopscript if (WorkshopScriptRef) WorkshopParent = WorkshopScriptRef.WorkshopParent if (WorkshopParent) ratings = WorkshopParent.WorkshopRatings NSettler = WorkshopScriptRef.GetBaseValue(ratings[WorkshopParent.WorkshopRatingPopulation].resourceValue) as int NHappiness = WorkshopScriptRef.GetBaseValue(ratings[WorkshopParent.WorkshopRatingHappiness].resourceValue) as int MinutemenTotalScore = MinutemenTotalScore + ((NSettler * NHappiness) / 2000) endif endif I = I + 1 EndWhile ratings = None WorkshopParent = None WorkshopScriptRef = None Link to comment Share on other sites More sharing options...
glewisguy Posted June 22, 2016 Author Share Posted June 22, 2016 Sure i can help you man, here is part of the script from my War Of the Commonwealth mod: Event OnInit() StoryFactionForce = new float [4] WorkShopIDs = new ObjectReference[27] WorkShopIDs[0] = Game.GetForm(0x00168945) as ObjectReference ;Coastal Cottage 1 WorkShopIDs[1] = Game.GetForm(0x001654B8) as ObjectReference ;Kingsport Lighthouse 2 WorkShopIDs[2] = Game.GetForm(0x001654BD) as ObjectReference ;Croup Manor 3 WorkShopIDs[3] = Game.GetForm(0x0009B197) as ObjectReference ;Slog 4 WorkShopIDs[4] = Game.GetForm(0x0009B19D) as ObjectReference ;Finch Farm 5 WorkShopIDs[5] = Game.GetForm(0x0009B1F1) as ObjectReference ;Greentop Nursery 6 WorkShopIDs[6] = Game.GetForm(0x0009B1DB) as ObjectReference ;Country Crossing 7 WorkShopIDs[7] = Game.GetForm(0x0009B1BE) as ObjectReference ;Nordhagen Beach 8 WorkShopIDs[8] = Game.GetForm(0x00135A90) as ObjectReference ;Taffington BoatHouse 9 WorkShopIDs[9] = Game.GetForm(0x000E0505) as ObjectReference ;Covenant 10 WorkShopIDs[10] = Game.GetForm(0x00024A26) as ObjectReference ;Zimonja 11 WorkShopIDs[11] = Game.GetForm(0x0009B1AC) as ObjectReference ;Tenpines Bluff 12 WorkShopIDs[12] = Game.GetForm(0x0009B1A5) as ObjectReference ;Warwick Homestead 13 WorkShopIDs[13] = Game.GetForm(0x00066EB6) as ObjectReference ;Castle 14 WorkShopIDs[14] = Game.GetForm(0x0016D28E) as ObjectReference ;Murkwater Construction Site 15 WorkShopIDs[15] = Game.GetForm(0x001654CF) as ObjectReference ;Jamaica Plain 16 WorkShopIDs[16] = Game.GetForm(0x001E81EA) as ObjectReference ;Summerville Place 17 WorkShopIDs[17] = Game.GetForm(0x00164321) as ObjectReference ;Egret Tours Marina 18 WorkShopIDs[18] = Game.GetForm(0x00019956) as ObjectReference ;Bunker Hill 19 WorkShopIDs[19] = Game.GetForm(0x001F0711) as ObjectReference ;Hangman 20 WorkShopIDs[20] = Game.GetForm(0x0009B1D1) as ObjectReference ;Oberland Station 21 WorkShopIDs[21] = Game.GetForm(0x0009B18F) as ObjectReference ;Graygarden 22 WorkShopIDs[22] = Game.GetForm(0x001654D5) as ObjectReference ;Sunshine Tidings 23 WorkShopIDs[23] = Game.GetForm(0x0001D0E2) as ObjectReference ;Starlight Drivein 24 WorkShopIDs[24] = Game.GetForm(0x0006F5C5) as ObjectReference ;Abernathy Farm 25 WorkShopIDs[25] = Game.GetForm(0x00054BAE) as ObjectReference ;RedRocket 26 WorkShopIDs[26] = Game.GetForm(0x000250FE) as ObjectReference ;Sanctuary 27 EndEvent ; Function part that gets number of settlers, happiness etc: Int I = 0 int NSettler = 0 int NHappiness = 0 float MinutemenTotalScore = 0 workshopscript WorkshopScriptRef workshopparentscript WorkshopParent workshopdatascript:workshopratingkeyword[] ratings ; Set to workshopdatascript:workshopratingkeyword[] for CK compile. I = 0 While (I <= 26) WorkshopScriptRef = WorkShopIDs[I] as workshopscript if (WorkshopScriptRef) WorkshopParent = WorkshopScriptRef.WorkshopParent if (WorkshopParent) ratings = WorkshopParent.WorkshopRatings NSettler = WorkshopScriptRef.GetBaseValue(ratings[WorkshopParent.WorkshopRatingPopulation].resourceValue) as int NHappiness = WorkshopScriptRef.GetBaseValue(ratings[WorkshopParent.WorkshopRatingHappiness].resourceValue) as int MinutemenTotalScore = MinutemenTotalScore + ((NSettler * NHappiness) / 2000) endif endif I = I + 1 EndWhile ratings = None WorkshopParent = None WorkshopScriptRef = None Many thanks for your help! I never thought to use Game.GetForm and cast it as an Objectreference.. I'll give it a try now and report back when I've finished the rest of the mod! Expect a shoutout in the final version :D Link to comment Share on other sites More sharing options...
Engager Posted June 22, 2016 Share Posted June 22, 2016 (edited) Where is a propery in workshopscript that shows if workshop is owned by player. In general routine is: 1. Get workshop object as ObjectReference using some method, for example: ObjectReference myWorkShop = Game.GetForm(0x0009B1A5) as ObjectReference2. Create link to instance of attached workshop script, by casting in form: workshopscript WorkshopScriptRef = myWorkShop As workshopscript3. Access OwnedByPlayer property in that script by the link you made: bool myWorkShopIsOwnedByPlayer = WorkshopScriptRef.OwnedByPlayer4. Destroy used links: myWorkShop = None , WorkshopScriptRef = None. Also you can access settler count, resources, happiness values as i shown above, that includes setting up one more cast to get workshopparent and getting ratings out of it. Edited June 22, 2016 by Engager Link to comment Share on other sites More sharing options...
glewisguy Posted June 22, 2016 Author Share Posted June 22, 2016 Where is a propery in workshopscript that shows if workshop is owned by player. In general routine is: 1. Get workshop object as ObjectReference using some method, for example: ObjectReference myWorkShop = Game.GetForm(0x0009B1A5) as ObjectReference2. Create link to instance of attached workshop script, by casting in form: workshopscript WorkshopScriptRef = myWorkShop As workshopscript3. Access OwnedByPlayer property in that script by the link you made: bool myWorkShopIsOwnedByPlayer = WorkshopScriptRef.OwnedByPlayer4. Destroy used links: myWorkShop = None , WorkshopScriptRef = None. Also you can access settler count, resources, happiness values as i shown above, that includes setting up one more cast to get workshopparent and getting ratings out of it.I wasn't far off, all I was missing was Game.GetForm (I was trying to just use the Creation Kit's reference ID for each workbench, please don't judge it was 3am haha). I also didn't cast each object to a workshopscript (I had the OwnedByPlayer check though). Thanks again for everything, I'm wondering is there a way to script for every workbench? Like in psuedo code something like int workshopCount = 0;RandomVariable WorkshopUseList = Creation Kit Use Info window for workshop object; workshopCount = WorkshopUseList.Length;WorkShopIDs = new ObjectReference[workshopCount]; Naturally that psuedo code is very messy and doesn't actually work but it's more of me trying to translate my thoughts from the gibberish in my head into a coherent idea :P If it helps you to explain it I'm competent in programming itself, I'm only now learning Papyrus since I never cared much for Skyrim modding. Link to comment Share on other sites More sharing options...
DarthWayne Posted June 23, 2016 Share Posted June 23, 2016 Might be a better idea to get the workshop refs directly from the WorkshopParentScript. That way you get all workshops, no matter if they are vanilla or added by a DLC or mod. Every workshop that is initialized properly should be added to the Workshops array in WorkshopParentScript. Here is an untested example: WorkshopParentScript property WorkshopParent auto const WorkshopScript[] OwnedWorkshops WorkshopScript[] Function getOwnedWorkshops() if (!OwnedWorkshops) OwnedWorkshops = new WorkshopScript[30] int i = 0 While (i < WorkshopParent.Workshops.length) if (WorkshopParent.Workshops[i].OwnedByPlayer) OwnedWorkshops.add(WorkshopParent.Workshops[i]) endif i += 1 EndWhile return OwnedWorkshops EndFunction Link to comment Share on other sites More sharing options...
glewisguy Posted June 24, 2016 Author Share Posted June 24, 2016 (edited) Might be a better idea to get the workshop refs directly from the WorkshopParentScript. That way you get all workshops, no matter if they are vanilla or added by a DLC or mod. Every workshop that is initialized properly should be added to the Workshops array in WorkshopParentScript. Here is an untested example: WorkshopParentScript property WorkshopParent auto const WorkshopScript[] OwnedWorkshops WorkshopScript[] Function getOwnedWorkshops() if (!OwnedWorkshops) OwnedWorkshops = new WorkshopScript[30] int i = 0 While (i < WorkshopParent.Workshops.length) if (WorkshopParent.Workshops[i].OwnedByPlayer) OwnedWorkshops.add(WorkshopParent.Workshops[i]) endif i += 1 EndWhile return OwnedWorkshops EndFunction Thank you for your idea, one question regarding that script though. By setting the length of the array to 30, am I not limiting myself? Could I instead create the script the following way (please note I added comments and edited the script below): WorkshopParentScript property WorkshopParent auto const; WorkshopScript[] OwnedWorkshops; Int Count = WorkshopParent.Workshops.Length(); WorkshopScript[] Function getOwnedWorkshops() if (!OwnedWorkshops) OwnedWorkshops = new WorkshopScript[Count + 3]; // the + 3 is for the workshops in Diamond City, Goodneighbour, and Bunker Hill. If no workshop exists in goodneighbour or bunker hill they can be added but never set to owned. If this causes problems I will create a separate array for these cities using the map markers and will then create a parent array of ObjectReference which contains both arrays. int i = 0; While (i < WorkshopParent.Workshops.length) if (WorkshopParent.Workshops[i].OwnedByPlayer) OwnedWorkshops.add(WorkshopParent.Workshops[i]); endif i += 1; EndWhile return OwnedWorkshops; EndFunction Edited June 24, 2016 by glewisguy Link to comment Share on other sites More sharing options...
DarthWayne Posted June 24, 2016 Share Posted June 24, 2016 Fallout 4 papyrus uses dynamic arrays. I just used 30 as a start value, because that's roughly the number of settlements to expect. That way the size of the array doesn't have to be increased for every settlement. Your script should also work though :D Link to comment Share on other sites More sharing options...
glewisguy Posted June 24, 2016 Author Share Posted June 24, 2016 Fallout 4 papyrus uses dynamic arrays. I just used 30 as a start value, because that's roughly the number of settlements to expect. That way the size of the array doesn't have to be increased for every settlement. Your script should also work though :DI see, I was unaware of that, I believe I'll just use the script I made as knowing my luck with previous programming experience I'll end up with 30 empty elements LOL. Link to comment Share on other sites More sharing options...
Recommended Posts