Pokepika01 Posted April 10 Posted April 10 I'm trying to create a race mod based on a game I played recently. Long story short, I want to use Blockhead to swap the equipment replacer based on a stat, sorta like a primitive version of Skyrim's Mana Tanks mod. Unfortunately, I'm... not really that good at scripting? I'm not bad, but man, this is kinda out of my depth. I'm looking at the documentation, and all this stuff about registering functions is kinda going over my head. Can someone give me a "For Dummies" of Blockhead's Equipment Override system, or like a simple template I can use or something? Yes, I do realize I have gone waaay beyond my skill level, but I'm in too deep to back down now.
AndalayBay Posted April 11 Posted April 11 I just did a quick search and found this mod. Another option is to go to the Blockhead download page and click on Requirements. That will list all the mods that require Blockhead. You can have a look at the code to see how others have done it.
RomanR Posted April 12 Posted April 12 I never worked with Blockhead, but I was able to make this working example. It consist of four scripts: Spoiler Spoiler scn RomRModelOverrideInstall short pluginPresent short handlerRegistered short result short new float fQuestDelayTime long handlerID ref handlerScript begin MenuMode 1044 set fQuestDelayTime to 0.05 if GetGameRestarted set pluginPresent to -1 set handlerRegistered to 0 set handlerID to -1 SetEventHandler "PostLoadGame" RomRFnPostLoadHandler SetEventHandler "OnNewGame" RomRFnNewGameHandler endif if pluginPresent == -1 if IsPluginInstalled "Blockhead" set pluginPresent to 1 else set pluginPresent to 0 Message "Model Override Test: You need to install BlockHead OBSE plugin first." endif endif if handlerRegistered == 0 && handlerID == -1 if pluginPresent != 0 set handlerScript to RomRFnHandler let handlerID := RegisterEquipmentOverrideHandler handlerScript if handlerID != 0 set handlerRegistered to 1 Message "Model Override Test: All handlers ready." endif endif endif end begin MenuMode 1036 set fQuestDelayTime to 0.05 if new != 0 set new to 0 if pluginPresent != 0 set handlerScript to RomRFnHandler let handlerID := RegisterEquipmentOverrideHandler handlerScript if handlerID != 0 set handlerRegistered to 1 else set handlerRegistered to 0 endif endif endif end First one is a main installer, it checks presence of plugin and registers rest of handlers after restart (there are three total). Also registers override handler anew when a new game starts and player reaches race menu. It's attached to a quest with priority 100. scn RomRFnPostLoadHandler short success ref script long ID begin function { success } if success != 0 if IsPluginInstalled "Blockhead" set RomRModelQST.pluginPresent to 1 set script to RomRFnHandler let ID := RegisterEquipmentOverrideHandler script if ID != 0 set RomRModelQST.handlerRegistered to 1 set RomRModelQST.handlerID to ID else set RomRModelQST.handlerRegistered to 0 set RomRModelQST.handlerID to ID endif else set RomRModelQST.pluginPresent to 0 set RomRModelQST.handlerRegistered to 0 set RomRModelQST.handlerID to -1 endif endif end Post load handler. As old override handler stops working after load this one ensures registering a new as soon as possible after load. As info stored in quest variables will not match an actual state, it checks these infos on its own and updates quest variables to match them. scn RomRFnNewGameHandler begin function {} if RomRModelQST.new == 0 set RomRModelQST.new to 1 endif end This one just sets a new game flag for main installer. scn RomRFnHandler ref item ref actor ref race int female int size array_var retField string_var modelPath begin function {item, actor, race, female} if actor != 0 && item != 0 && female != 0 if GetEquipmentSlot item == 2 ; she wears something on chest let modelPath := GetBipedModelPath 1 item if sv_Length modelPath == 0 ;return field construction let size := ar_Size retField if size == -1 let retField := ar_Construct Array let size := ar_Size retField endif if size == 0 let retField[0] := 100 ;priority let retField[1] := ElvenCuirass SetFunctionValue retField endif endif endif endif sv_Destruct modelPath end And the override handler at last. It does nothing special - it checks if female actor wears something on her chest and if model for females isn't defined, it will show female Elven Cuirass model instead. Made to work with one slot items only. Some last notices: Override handler doesn't checks if NPC is a creature. As docs only speaks of NPCs, I'm assuming a plugin does this check before triggering an event. Blockheads docs are quite silent about when you need to unregister override handler (if it's ever need). But as old handler stops working after entering new game session (new game or load) and I need to register new again, I'm assuming that the old one will be unregistered automaticaly, as in case after game load there's practicaly no way to pass right handler ID afterwards anyway. I also noticed that Blockhead always pass higher handler ID then before after registering (unregistering old handler by hand had no effect), but maybe it's normal.
Recommended Posts