LongDukDong Posted February 6, 2018 Share Posted February 6, 2018 MOD SPELL LOADING NOTES BY A QUACK A LongDukDong Article Have you ever found the need to turn off a mod for a time and turn it back on sometime later? The chances are... yes. Sometimes, you lose data when this happens. And sometimes, the mod may have included a kick-ass spell that was initially loaded when the mod started OR was garnered from a book that was read. Isn't it annoying that a book that may have taught you a custom spell now no longer teaches it? That scroll that allowed you to craft a portal to your Oblivion Temple of Delights now cannot be learned, and it has vanished from your player's memory! It is lost forever!!!! No longer. Or that is, no longer if the creator of the mod uses the OBSE and follows these concepts. * === * === * === * === * Teaching a spell the moment the game begins is an easy task. And the ability to detect if the player already knows the spell is a breeze thanks to the OBSE command 'HasSpell'. It is this command that tests if the player knows a defined spell, and returns a '1' if the spell is known, or a '0' if it is not. Early binary form true/false values. Below, I have presented a simplified Quest script with virtually no frills. It doesn't hold any key values, it doesn't perform any calculations or track any NPCs. All this quest script does is add a spell (CustomSkillYouMade) to the player's spellbook when the game loads or reloads. But it only adds the spell after it has been determined that the player doesn't know the spell already. scn CustomQuestScript Begin GameMode ;; Hey, are we starting or reloading the game? if GetGameLoaded || GetGameRestarted ;; If the player does not know the spell if player.hasspell CustomSkillYouMade == 0 ;; Add to SpellBook. player.addspell CustomSkillYouMade endif endif End Can this be any more basic? This is different than the use of the commonly used 'DoOnce' value in that your typical quest script saves the result of 'DoOnce' so it only executes once, and that's it. True, the value stored within DoOnce vanishes too, so it could be argued that the spell could be relearned. But if an upcoming modder wishes to alter their own custom work, the usefulness of 'HasSpell' becomes more apparent as it specifically tests for the spell desired. And if it was necessary for a new mod to rewrite some other mod/plug-in's main quest script (NOT RECOMMENDED!!!), this technique does become invaluable. Personally, I don't really use this so much in my mods because I like that there may be a cost to acquiring such spell as those I have crafted. I tend to use the latter 'book' system that teaches a spell. But this works quite fine. * === * === * === * === * The ability to learn a custom spell from a book is not really that far off. All the creator must test is if the spell was loaded, just as I had shown how to use the 'HasSpell' command within the mod-loading script above. Whenever I make a book that teaches a spell, the book brings up a choice window which lets the player decide to learn the spell or not. Oh, sure. I could make the spell be taught the moment the book is picked up... but where is the fun in that? Let the player have a choice!!! And the book can have some very fun dialog or pics inside for kicks. Ya know, a book can easily summon a monster with the 'Enchantment' dropdown, or increase your ability with the 'Teaches' dropdown. But can you just pick a spell to learn that way? Nooooo. You need a script to teach the player a spell. Oddly, no original book in Oblivion, The Knights of the Nine, nor Shivering Isles has a book that teaches a spell. We modders did this ourselves! And below is the script I now use that teaches a spell: scn CustomSkillBookScript ; FUNCTION: This is a basic book script, one which allows the player to decide ; whether or not to learn spells as defined within the game mod. ;; Define values for script short buttonPressed ;; Equip Activation Begin OnEquip Player ;; If the player does not know the spell if player.hasspell CustomSkillYouMade == 0 ;; Generate Choice Message: Two options (Yes/No) MessageBox "Wish to learn this custom skill?", "Whoh! Sure!", "Eep! Forget it." endIf End ;; Object Activation Begin OnActivate ;; Activate Object Activate ;; If Subject is Player the player does not know the spell if isActionRef Player == 1 && player.hasspell CustomSkillYouMade == 0 ;; Generate Choice Message: Two options (Yes/No) MessageBox "Wish to learn this custom skill?", "Whoh! Sure!", "Eep! Forget it." endIf End ;; Menu System Action Begin MenuMode ;; Retrieve Player input Set buttonPressed to GetButtonPressed ;; Perform only if Player gives input if buttonPressed > -1 ;; Perform only if first option (Yes) is chosen if buttonPressed == 0 ;; Add to SpellBook. player.addspell CustomSkillYouMade ;; Perform Sound Effect PlaySound SPLDestructionCast endIf endIf End This is the whole 'basic' script I use. Obviously, I have names like 'CustomSkillBookScript' and 'CustomSkillYouMade' as placeholders for the name of the script and the Editor ID for the custom spell which this script is teaching the player. There are plenty of notes within, so it should be easy to understand how it works. The only thing you would wish to customize besides the name of the script and spell ID itself would be the Messagebox dialog and the performed sound effect when the player learns the spell. Other than that, this is pretty much 'it'. * === * === * === * === * The above method for testing whether a spell is loaded or not is pretty straightforward. However, this only works if you have a single spell being learned within that book. This doesn't really work too well if you have a book that teaches a variety of spells. Mayhaps you are working on an Encyclopedia of Cheat Skills. Maybe you need to put in an extra spell you forgot to add last week. So this time, you need a slightly different structure to test the existence of 'multiple' spells. Please notice that I am covering just one of the 'two' routines as both are near mirror images with the exception of the ' if isActionRef Player == 1 ' and ' Activate ' content. ;; Define values for script short buttonPressed short IsMissing ;; Equip Activation Begin OnEquip Player ;; Default test value set IsMissing to 0 ;; If the player does not know the spell if player.hasspell CustomSkillYouMade1 == 0 set IsMissing to 1 endif ;; If the player does not know the spell if player.hasspell CustomSkillYouMade2 == 0 set IsMissing to 1 endif ;; If the player does not know the spell if player.hasspell CustomSkillYouMade3 == 0 set IsMissing to 1 endif ;; If at least one spell is unknown if IsMissing == 1 ;; Generate Choice Message: Two options (Yes/No) MessageBox "Wish to learn this custom skill?", "Whoh! Sure!", "Eep! Forget it." endIf End Okay, now we are using an extra value called 'IsMissing'. This value is merely a test value that tells the system if there is a spell the player doesn't have in his/her spellbook. It may be akin to 'DoOnce', but IsMissing is a flag for testing when encountered and meant to be reset whenever encountered instead of being stored. By default, I prefer to have IsMissing set to '0' when the routine is run. And then we test the various spells, and only turn IsMissing to '1' if any of the spells weren't learned. And after that, I run the messagebox only if IsMissing is set to 1. Not much difference except the extra if...end blocks and an extra value to track. * === * === * === * === * With the comments I added, I hope that this is easy enough for 'intermediate' level modders to understand. Maybe even 'apprentice' level. The use of the OBSE command 'HasSpell' is definitely something I believe has been overlooked when it comes to granting the player skills. Hence, why I felt the need to put virtual pen to virtual paper. But note that custom items from a mod may be lost and found once again if one uses the default 'GetItemCount' command. So while this article is about a method to ensure custom spells are not lost, let it be known that special and unique items loaded at game start (or garnered by means of a treasure chest?) may be protected or saved in the same way. Likewise, being able to re-read a book such as Bravil Underground's "Dwemer Contraptions" and ensure both the Item and Spell are regained would be priceless. Peace. Quack. See also: Book Creation Notes by a Quack Link to comment
TDA Posted February 6, 2018 Share Posted February 6, 2018 How to make the script work, which is attached to the chair, when it is activated by the actors? ========================================================= In general, I did, the opening sarcophagus (not a chair, but the essence is the same, block OnActivate- on the chars, beds, not working with actors) Although I solved the problem, but the solution is perverted ... Link to comment
LongDukDong Posted February 6, 2018 Author Share Posted February 6, 2018 From your post, I am assuming it is an inquiry, and 'tis separate topic in itself. (IE 'Off Topic' ) However, one of the beds at the Brina Cross Inn has a script that is activated when going to sleep, and it uses the IsActionRef command to ensure the user is the player. scn BedDiseaseSCRIPT short diseasechance begin OnActivate Activate if IsActionRef player == 1 set diseasechance to getrandompercent endif end begin menumode if diseasechance > 80 && isPCSleeping == 1 player.addspell DisYellowTick set diseasechance to 0 endif end begin gamemode set diseasechance to 0end When the player clicks/activates the bed, he just randomly rolls the 'chance' to get Yellow Tick disease. When the 'menu' system executes while sleeping, it looks to see if he got bit by a tick, and resets the chance to 0 (so it doesn't repeat). I hope that answers your inquiry. Link to comment
TDA Posted February 7, 2018 Share Posted February 7, 2018 3 hours ago, LongDukDong said: From your post, I am assuming it is an inquiry, and 'tis separate topic in itself. (IE 'Off Topic' ) However, one of the beds at the Brina Cross Inn has a script that is activated when going to sleep, and it uses the IsActionRef command to ensure the user is the player. Reveal hidden contents scn BedDiseaseSCRIPT short diseasechance begin OnActivate Activate if IsActionRef player == 1 set diseasechance to getrandompercent endif end begin menumode if diseasechance > 80 && isPCSleeping == 1 player.addspell DisYellowTick set diseasechance to 0 endif end begin gamemode set diseasechance to 0end When the player clicks/activates the bed, he just randomly rolls the 'chance' to get Yellow Tick disease. When the 'menu' system executes while sleeping, it looks to see if he got bit by a tick, and resets the chance to 0 (so it doesn't repeat). I hope that answers your inquiry. I'm sorry. if offtopic (I thought here about the scripts), Yes on the player it all works, but when the (beds or chairs) activates by the NPS - no. I solved the problem using the trigger zone and its script controller in (OnTrigger and Gamemode). It's just a little uneconomical (on computer resources) ( the sarcophagus has animation and I had to turn it on when the actor lies down in a sarcophagus. https://www.youtube.com/watch?v=KQEZhDAnIRE ) Link to comment
LongDukDong Posted February 8, 2018 Author Share Posted February 8, 2018 A new section within my Article has been added while doing a bit of touch-up here and there. The new section makes mention how to one may test for multiple skills in the event the player might not have one of the skills memorized. And further below, I pointed out how a book (Dwemer Contraptions) could do well to test for the existence of the book's custom spell and item. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.