Jump to content

Getting a list of all workshops


Recommended Posts

Hi all. I could really use some help here.

 

I'm working on my first mod at the moment, and I've written a script attached to my quest that compiles successfully. So that you have a picture of what I'm trying to accomplish, this is what I hope the script will do:

 

1) Loops through all workshops,

2) finds workshops with at least 10 settlers,

3) displays a message saying that settlers of the found workshop will clean their settlement up in 2 days,

4) starts a timer (atm it's short, but it will be 48 hours),

5) and at the end of the timer, removes a list of debris and displays another message.

 

I'm attaching the script for reference, as it's a bit long for a post.

 

The problem that I have is that I can't get a list of all of the workshops. Here is the pertinent function:

; Populate workshopList.
WorkshopScript[]  function SetWorkshopList()
    workshopList = WorkshopParent.Workshops
endFunction

I used debug.MessageBox() to display the length of the resulting workshopList variable: 0. As a result, my script never gets through the first step, and nothing happens. What am I doing wrong?

 

Thanks!

 

PS--this thread is a follow-up to this one, and I referenced some of the suggestions in this thread for getting the workshops list and counting the settlers.

Edited by comradezero
Link to comment
Share on other sites

OK, I figured out what my problem was. I forgot to pick the Object for my WorkshopParent property. Now I successfully get a list of all of the settlements. For those who would like to know specifically how:

 

1) Open up the Quest.

2) Navigate to the Scripts tab.

3) Click on Properties.

4) Click on WorkshopParent.

5) Select "WorkshopParent" from the Pick Object drop-down menu.

 

This same process has to be done for reference aliases, messages, and the like.

 

Now I've just gotta get the text replacement to work in my messages.

Link to comment
Share on other sites

Well, I've populated the lost of Workshops, but getting their Location is still eluding me. I've tried 2 methods.

 

Method A:

Location function GetSettlementLocation(WorkshopScript inputSettlement)
    WorkshopScript workshopRef = inputSettlement as WorkshopScript
    if (workshopRef)
        WorkshopParent = workshopRef.WorkshopParent
        if (WorkshopParent)
            Location theLocation = workshopRef.myLocation as Location
        endif
    endif
    return theLocation
endFunction

(I've also tried using GetCurrentLocation() rather than myLocation.)

 

Method B:

Location[] Property WorkshopLocations Auto

; Populate WorkshopLocations. Called before the below function.
function SetWorkshopLocations()
    WorkshopLocations = WorkshopParent.WorkshopLocations
endFunction

Location function GetSettlementLocation(WorkshopScript inputSettlement)
    int index = Workshops.Find(inputSettlement)
    return WorkshopLocations[index]
endFunction

I've used debug.MessageBox() to try to display the location like so (using 0 as an example):

debug.MessageBox(WorkshopLocations[0])

My output is just "[Location" (without the quotes).

 

For the moment, I'm stumped.

Edited by comradezero
Link to comment
Share on other sites

Finally, I did it. My code was fine several hours ago, but I missed a checkbox ("Stores Text") one on of my reference aliases under Quest > Quest Aliases.

 

For those who are curious, I used the WorkshopParent quest as a model (I abandoned the idea of modeling WorkshopGunnerAttack01 that I'd been pursuing, as mentioned in the thread linked in the OP).

 

One hang-up that I ran into was that I couldn't call WorkshopParent.DisplayMessage() and still get successful replacement text. I even passed self into the parameters (e.g. self.MessageName), with no success. So I simply copied the function into my script, and it worked.

 

Now, on to actually removing that pesky debris.

 

 

Link to comment
Share on other sites

Your code is beautiful, strict coding conventions and your commenting is divine!

 

Haven't opened CK yet to look at things you've got me thinking now. Just curious, are MessageRefAlias and MessageLocationAlias part of a 'message struct' somewhere, did you find them in WorkshopParentScript or something else?

 

I've been able to use the <alias.CurrentName=Companion> to fill a message with the appropriate name. I can't seem to find any documentation about using 'Alias' text replacement in messages and what properties (like CurrentName) it has.

 

Thanks for the info, that MessageRefAlias will sure come in handy.

Link to comment
Share on other sites

Thanks. :smile:

 

I couldn't find much documentation on using Alias text replacement, either, other than this and a few other pages on that wiki. So I turned to looking through base scripts, and I did indeed find MessageRefAlias and MessageLocationAlias in WorkshopParentScript. To get them working with text replacement, I set up my own versions of them, along with Messages, in the CK as follows:

 

1) I opened up my Quest from the Object Window > Character > Quest, navigated to the Quest Aliases tab, and created two new Aliases like so:

 

http://motheroforder.net/wp-content/uploads/2016/07/message-location-alias.jpg

 

http://motheroforder.net/wp-content/uploads/2016/07/message-ref-alias.jpg

 

2) Then I navigated to the Scripts tab, selected my script (after compiling it), then Properties, and assigned my script's ReferenceAlias properties to the Aliases that I just created, like so:

 

http://motheroforder.net/wp-content/uploads/2016/07/message-location-alias_property.jpg

 

http://motheroforder.net/wp-content/uploads/2016/07/message-ref-alias-property.jpg

 

3) I created my Messages under Object Window > Miscellaneous > Message:

 

http://motheroforder.net/wp-content/uploads/2016/07/clean-settlement-msg.jpg

 

http://motheroforder.net/wp-content/uploads/2016/07/clean-settlement-pre-msg.jpg

 

4) and set up the Message properties much the same way as I did for my Aliases:

 

http://motheroforder.net/wp-content/uploads/2016/07/clean-settlement-msg_property.jpg

 

http://motheroforder.net/wp-content/uploads/2016/07/clean-settlement-pre-msg_property.jpg

 

The DisplayMessage() function takes care of forcing the Aliases to point at the Location where I want them to point in my script, so the Message text replacement works properly.

 

As you can see, although I set up MessageRefAlias, I haven't set up the corresponding Messages to make use of it, and in my script I'm just using MessageLocationAlias. Still, I just wanted to go ahead and set both Aliases up while I'm working on my mod in case I want to use one or either of them later; I'll eventually trim down to just what I need or anticipate needing in the future. Also, I suppose that I could have tried simply pointing my ReferenceAlias properties to the corresponding Aliases under the WorkshopParent Quest, but I wanted to be safe and set up copies attached to my own Quest, just in case. If I had to guess why I needed to copy DisplayMessage() to my own script and couldn't just call WorkshopParent.DisplayMessage(), I'd say it's because the original function is looking for Aliases attached to its own Quest. But since Messages are attached to Quests, and hence will look for Aliases attached to the same Quests, I think what I did is necessary. I could just create Messages and point them to the WorkshopParent Quest and point my ReferenceAlias properties to the same Quest, and I think that would all work, but like I said, I want to set up these assets separately for my Quest for the time being.

Edited by comradezero
Link to comment
Share on other sites

Hey. Been following this thread with a tangent question. Could I use the WorkshopParent with OnLocationChange to determine if player's present location is inside of an activated settlement? If it is not a settlement, would WorkshopParent return 0 or write to error log?

 

I've tried many ways to keep my Scavver mod from looting settlements, which has resulted in making most areas restricted to him, even if the bench hasn't been activated by the player yet.

Link to comment
Share on other sites

In my script, I use the WorkshopScript boolean property OwnedByPlayer to determine whether a given workshop is owned by the player. Is that what you mean by an activated settlement? Does this answer your question? If not and you're looking for something more specific, I'm still trying to learn Papyrus and the CK (been at it for a few days now) so I'd be happy to try helping with your Scavver looting problem. Don't have to go back to work until October 1. :D

Link to comment
Share on other sites

This thread has been bookmarked for me since this morning and will likely become a permanent reference now. I'd spent about a month banging my head against populating a list of workshops for my own nefarious purposes, and finally set it aside and moved on to other things before I threw my tower out the window... and I think you've just given me what I needed to get back to it.

 

Since your original post was looking for assistance, if I progress into what I wanted to do and it isn't covered by what you figured out yourself, I'll come back here and share the info!

 

Is everyone in this thread injured..? Finally nearly recovered after 4 months of a compressed nerve. Contractor, tho, so the best I got was "I guess you can work from home two days a week."

Link to comment
Share on other sites

  • Recently Browsing   0 members

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