Coding Notes: Object Mods, Dynamic Retextures and OnEquipped Events
What I want:
- I want a single top with which I can change the color and design at the armor bench
- I want one that changes from "Fertile" to "Breeder" and back, according to the state of the wearer's womb
- Ultimately, I'd like a control doodad that let's me change someone's top and tats on the fly
What I did:
I made one top, and set it up with two Object Mods, one for "Breeder" and one for "Fertile". That lets me create the top, and then customize the text at an armor workbench. It's fiddly to get right the first time, but fun once it works, and not that complicated once you get your head around it. I followed the instructions from Using Material Swaps in Fallout 4
over on Nexus.
Then I scripted the top
Scriptname rrs:pregswap2 extends ObjectReference import Overlays ObjectMod property fertile auto ObjectMod property preggers auto FPFP_Player_Script property fpe = None auto
Overlays is from LooksMenu and is going to handle the tattoo application. FPFP_Player_Script is from Familiy PLanning and represents the API for the mod. All we want from it is the pregnant faction, at least for now.
The OnEquipped event has to do a few things:
- Make a note of the actor, since she won't be passed to some later events
- Get the Family Planning API
- Determine the fertilization state of the wearer
- Change the shirt mod if needed
- Set the tats
Event OnEquipped(Actor a)
;
; make a note of the wearing actor
;
; hopefully this won't evaporate when the actor loses her 3d
;
wearer = a
;
; get the FPE main quest
;
if fpe == None
fpe = FPFP_Player_Script.GetAPI()
endif
if fpe == None
debug.traceUser("rrs", "Can't find FPE API")
debug.notification("Can't find FPE API")
return
endif
;
; get the pregnancy data for this actor
;
bool is_pregnant = a.IsInFaction(fpe.fpfp_preggo)
;
; should probably add - I mean fertile in the "able to be fertilized" sense of the word
; not the FPE sense of "particularly likely to get pregnant"
;
set_shirt_mod(a, is_pregnant)
;
; now do the tats
;
set_breeder_tats(a, is_pregnant)
;
; now check for a named raider who gets their name on their ass
;
set_ass_name(a)
;
; and finally, update
;
debug.traceUser("rrs", "updating")
Overlays.Update(a)
endevent
Setting the mod is simple enough:
function set_shirt_mod(actor a, bool is_pregnant)
objectmod wanted = None
if is_pregnant
wanted = preggers
else
wanted = fertile
endif
;
; if the mod we want is the mod we got
; we don't need to do nothing
;
; we need to do this or changing the mod counts as a re-equip
;
if ! mod_is_equipped(wanted)
debug.traceUser("rrs", "changing mod")
attachMod(wanted)
endif
endfunction
The big gotcha there is that changing the mod counts as removing and re-equipping the item, which fires off the OnEquipped event again. It is possible to just attach the mod you want and displace whatever was there before ... but that re-equips the shirt again and we get an infinite loop of OnEquipped Events. So we need to check what mod is equipped and only change it if necessary.
That much gets the top changing properly, which is cool. The tats still have problems though. You still get an onEquip and OnUneqip event firing while you're trying to set up the tats and some horrible race conditions develop.
I ended up setting up a state so I could ignore those events while I was still handing the first equip event
;
; turns out that changing an OMOD on worn garment causes it to unequip and re-equip behind the scenes
;
; so this stops the events from firing while we're first setting up the design and tats
; otherwise we get all sorts of race conditions and unexpected outcomes
;
state equipping
Event OnEquipped(Actor a)
debug.traceUser("rrs", "OnEquip Event ignored - equipping state")
endEvent
Event OnUnequipped(Actor a)
debug.traceUser("rrs", "OnUnequip Event ignored - equipping state")
endEvent
endstate
Event OnEquipped(Actor a)
;
; stop equip and unequip events from firing due to changing OMODs
;
gotostate("equipping")
;
; previous stuff here
;
utility.wait(1.0)
gotostate("")
endevent
And that works just fine. Stick a top on a girl and you can see instantly if she's fertile, and when you impregnate her, the top updates itself almost as soon as you finish having sex.
0 Comments
Recommended Comments
There are no comments to display.