Jump to content

Scripting question


niston

Recommended Posts

I didn't tested it, because I didn't had the actual furniture, I was afraid that OnActivate and OnSit could be firing at the same time, and therefore it would be registering OnSit after being fired, so I've decided to simply register it in OnBeginState. I'm glad to know that it just works as you want. (It just works. Todd. ^^)

Link to comment
Share on other sites

Yeah, I think the player mining script is ok for now. I'll say it again, you've been very helpful. Thank you! :smile:

 

For some reason, the forum ate 98% of my post I was going to reply with. Oh well, long story short:

 

https://pastebin.com/SGd1JHRe

 

This is for the NPC mining script.

 

Problem is, CanProduceForWorkshop() wont be reliable once the cell gets unloaded and just return false. I work around by caching the return value on cell detach and then using that whenever 3d is not loaded.

 

Wondering if there's a better way instead of using that cached value. Could I somehow check if the furniture is still assigned to somebody (or maybe the other way around - if anybody is assigned to this particular furniture), even tho it's unloaded?

 

EDIT:

 

After taking a look at Settlement Management Software, I tried using this:

 

WorkshopObjectScript thisObj = parent as WorkshopObjectScript
canProduce = thisObj.IsActorAssigned()
It doesn't seem to work tho, probably because I'm not properly acquiring the WorkshopObjectScript reference. From what I understand, the NPC mining script is attached to the mining furniture because I added it under "scripts" in the furniture editor thing in CK. But I'm not sure how WorkshopObjectScript ties in. It seems to me that the furniture is a workshop object and I should be able to cast a reference to the furniture as WorkshopObjectScript. But even if this is true, where do I get the furniture reference from?
Funny thing also, I can see iin CK the workshopobjectscript being attached to the mining furniture, too. Which makes total sense, because what I wrote above.
Now...How do I access the little bugger ???
Not sure how to proceed. Please advise :smile:
Edited by niston
Link to comment
Share on other sites

It doesn't seem to work tho, probably because I'm not properly acquiring the WorkshopObjectScript reference. From what I understand, the NPC mining script is attached to the mining furniture because I added it under "scripts" in the furniture editor thing in CK. But I'm not sure how WorkshopObjectScript ties in. It seems to me that the furniture is a workshop object and I should be able to cast a reference to the furniture as WorkshopObjectScript. But even if this is true, where do I get the furniture reference from?

 

I guess you could try with Self instead of Parent:

WorkshopObjectScript thisObj = Self as WorkshopObjectScript

canProduce = thisObj.IsActorAssigned()

Link to comment
Share on other sites

Yeah, tried it.

 

Compiler doesn't seem to like it tho: "cannot cast a pq_miningbynpc to a workshopobjectscript, types are incompatible"

 

Makes me think that "self" is a reference to the actual script. But when googling, I also found the info that self would be the object that the script is attached to.

Edited by niston
Link to comment
Share on other sites

Maybe:

ObjectReference SelfRef = Self As ObjectReference

WorkshopObjectScript thisObj = SelfRef as WorkshopObjectScript

 

Or in a single line:

WorkshopObjectScript thisObj = (Self As ObjectReference) as WorkshopObjectScript

 

??

Link to comment
Share on other sites

Trying now. At least the compiler accepted this.

 

It does work. Just not as intended; I get false returned on objects that have a settler assigned.

 

This is also true for the settlement software. It just says "no actor assigned" when listing object details on a remote settlement, so it can't get the info either. :sad:

 

Next idea: Temporarily moving the object near the player, so it will get loaded. In theory. And then, after checking assignment, restoring it to it's former coordinates. Sounds like something from a horror movie tho.

Edited by niston
Link to comment
Share on other sites

I would then have to remove the attached workshopobjectscript, yes? Because my extension would take it's place.

 

But I don't think it will work. I mean, settlement management software can't get the info either, using the same IsActorAssigned() function call. So the function just seems to return false when the object is not loaded; exactly like CanProduceForWorkshop().

 

Still an improvement if I cache the result of IsActorAssigned() instead of CanProduceForWorkshop(). The later will return false when the actor is wounded, so when the assigned settler gets wounded as you leave the cell, production will stop until you revisit that cell. This won't be an issue if I cache IsActorAssigned() instead.

 

Also, it seems impossible to unassign a remote settler through SMS, despite what I thought at first. The only settler that actually gets listed and can be managed for any remote settlement is the provisioner. But not sure if that's just my game.

Edited by niston
Link to comment
Share on other sites

I would then have to remove the attached workshopobjectscript, yes?

 

Afaik, no. I mean just changing the header on your script (Scriptname YourScript extends WorkshopObjectScript), not literally extending it.

Link to comment
Share on other sites

Yeah that seems pretty straight forward. But YourScript then inherits from WorkshopObjectScript, no?

 

Inheritance should mean that YourScript can do everything (has all the functions and properties) that workshopobjectscript does, unless a function or a property gets overridden in YourScript.

 

https://www.creationkit.com/fallout4/index.php?title=Extending_Scripts_(Papyrus)

 

So, the workshopobjectscript that's attached to the furniture becomes obsolete, because my miningbynpc script could then take it's place (while offering extended functionality)

Edited by niston
Link to comment
Share on other sites

  • Recently Browsing   0 members

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