Sunday 14 August 2011

My Simple Creature Companion Tutorial - Oblivion

PLEASE DO NOT POST THIS TUTORIAL ANYWHERE ELSE WITHOUT ASKING ME FIRST.

This tutorial outlines the system I use to create my creature companions. It uses activation to Follow and Wander (stay) so you won't find a menu system here. I don't like menus for creature companions and I find it totally unnecessary.

The scripts are included, but there's also some latitude in what you can do with them. For example you can add or subtract spells, sounds or shaders etc inside the main and magic scripts if you wanted to, but I haven't included it here. My House Cats mod and a couple of others adds sounds like a bell that rings on activation or purring sounds as Idles and/or on activation.

You could also add extra functions to the creature script and it already includes Sneak. This function depends entirely on your own Sneak Skill.

This Tutorial is quite long and detailed. The main part has the script for the original mod it's based on, but the last part (UPDATE) includes the updated script with the sneak function as well as having the summon spell added to it rather than an item.

Also located at:
TES Alliance
http://www.tesalliance.org/

Waalx Animals and Creatures Forum
http://waalx.com/RealSwordsForum/index.php
 It has been translated to French by Sita Kaos, but I don't currently have a link.


CREATURE COMPANION TUTORIAL BASED ON MY SHER JA - MOUNTAIN LION COMPANION MOD.

***This tutorial assumes the user knows very little about using the Construction Set so I've tried to be as detailed as possible.***

Click the screenshots for a better view so you can see what I'm referring to. If you think you've made a mistake in any open form, click Cancel instead of OK, but generally you can go back and make the necessary changes without problems. There is an exception to this. If you move an object unintentionally when placing the creature in the world you can go to Edit/Undo in the File Menu as long as you realize immediately you've done it. Otherwise you'll need to "clean" the mod afterwards. It's no fun if you find you've moved a door or house by accident and don't find out until later.

CREDITS:

Sher Ja - Mountain Lion Companion was my first mod besides some save games and has been updated and experimented with several times until found I was finally happy with it.

The scripts used here for the companion are adapted from the Fenrir the Wolf Companion mod by delphinus with his permission. They were created with OBSE by Jumonji, but have been changed so they no longer require OBSE which mainly dealt with fast healing after battle. This is now dealt with by adding a Healing Ability and making him Essential. Jumonji helped me to do this.
The Add Summon Spell script is by WillieSea. I found it on the Official CS forums where I also find a lot of other helpful information.
Thank You.

Fenrir the Wolf by delphinus and Jumonji
http://www.tesnexus.com/downloads/file.php?id=14192

Sher Ja - Mountain Lion Companion by Maigrets
See my mods section here on this blog.



STARTING OUT:
This will create a simple creature companion that can be activated to stay and follow. It will fight anything that is your enemy or that attacks you in Follow mode. It will NOT be aggressive to friends or yourself, and is player owned. Otherwise, if you resist arrest for a crime, it will attack the guards who are chasing you, or if you go on a murder spree then you can rely on it to defend you. I make my companions Essential so they don't die, but become unconscious for a short time. That's up to you. I prefer not to have to reload or deactivate and reactivate the mod if it dies, especially when using overhaul mods like I do, where a non essential companion death is almost guaranteed.

In Wander mode it will patrol the area where you left it and will defend itself if necessary. When you first go to find your companion it will also start to wander as soon as you enter the cell it's placed in, so if it's not where you put it just search around a bit or use the summon spell as described below.

There will be a Summon Spell to call your companion if you've left them somewhere, if they get stuck (rare), or to remove them from battle. If they do happen to get lost, for example, falling from a great height, they will teleport to you or return on entering a new cell. Or, of course, you can summon them back.
This spell can be added to an object and you can create a quest to find it if you like, or you can place the object near the creature. Make sure to mention it in your readme if you plan to release the mod.

I am including the option of adding the spell to an object to this tutorial. When the object is taken the spell is automatically added to your spellbook. The item doesn't need to be in your inventory afterwards, so you can throw it away or keep it depending on the item used.

The spell can also be added via a quest script which will add it as soon as you load your save, but will not be included in this tutorial. I prefer not to add the Summon Spell by a quest because I like to put my creatures somewhere to find, rather than an easier location like the Waterfront District.

Quest related options will be included in another tutorial which will outline a simple quest to find a companion or object with a small story attached to a note or book. This can be added to your inventory when you load your game with the mod active or you can use the quest to search for it. It will also include how to add spells via a quest and other options like sounds and messages which can be added to the scripts.
NOTE: I haven't gotten around to doing this addition yet.

I used to make it a habit to take screen shots of all my open windows in the Construction Set. For example: scripts, spells, stats etc. I can see at a glance what I've done for future reference, without loading the mod. But that's just me. I sometimes still do it for new mods depending on what I add to them.

Regarding Shivering Isles and companions: I haven't played SI for some time, but I know if you tell the companion to wait before entering the portal and then summon it when you are in the SI world there should be no problems. I've done this with Sher Ja and a couple of others and it was fine. That also relates to Oblivion Gates. Make the companion wait, enter the gate, then summon. Do the reverse BEFORE taking the sigil stone and summon once outside. Unlike other types of companions they obviously have no inventory that can be reset when the cells update.

FIRST STEPS:

This tutorial will create a lion companion, but can be used for any creature. I've never bothered making a companion from a Shivering Isles creature, but I know someone who did using this tutorial and it worked out as far as I'm aware.

It's a good idea to name all References and ID's with a prefix. For example - JJMyLion. Don't use numerals at the beginning of the ID, and have no spaces in the ID field. Using the JJ, or any other prefix makes it easier to find your entries. You can use AA or aa, or your initials as long as it's always the same for consistency.

Load the Construction Set and go to File/Save and create a new esp with the name of your choice. This will automatically make it active.
Click OK and Oblivion ESM will load automatically because you are loading a mod that requires it. Otherwise you can select Oblivion ESM only to load and choose to save your esp when you've started work on your mod.

Go to the Object Window on the left and expand the Actors\Creature\creature tree. Select the CreatureMountainLion and double click to open it's Stats Form.


In the ID field give it a NEW unique ID. If you don't give it a new ID every lion will be a clone of yours. Close the window by clicking OK, and you will prompted to make a new form because you've changed the ID. Click YES to create a new object. In the NAME field give it a name which will appear in game.

Open the lion's Stats Form again.
Here you can change the Essential status and whether he will Check Corpses. I leave it checked for dogs and wolves, but not the lion because it does nothing and can slow the creature down. Canines have animations so it works well and they only do it after combat is over. Check swimming so they can follow in water. Again, canines seem to be better for this since they do actually swim while other creatures sink like a stone or have to find another path, but they will catch up.

Take the tick out of No Low Level processing and Respawns. Leave his Combat Style at Default for the mountain lion.
Tick PC Level Offset to have him level with you. Choose whether you want him to level above or below you by entering a number in the Offset box. For example, 1 to stay at your level or -1 to be one level below you.
In the Calc Min box type 1 and in the Calc Max box type 0. This will adjust his health, speed and fatigue modifiers on the right of the window.

Starting out it's probably best to leave his health and other stats as they are. You can adjust them later if you want. Although, I give my creatures an Intelligence of at least 30 so they can follow up stairs and through doors. They will even open gates. This also relates to successful fast travel so they zone with you instead of getting lost and having to be summoned.

Always leave Personality at 20 or even at the default as anything higher can make him passive, and enemies, depending on their Faction will ignore him when you want him to fight.


From now on I'm referring to the Lion as Leo to make things a bit easier. The abbreviation, CS, will refer to the Construction Set.


Go to the Factions Tab and right click to delete anything in there which is usually Creature Faction.

Next go to the CS Menu at the top of the screen and select Character -- Factions. Scroll down the list until you find Playerfaction. With Leo's page still open drag it to his Factions Tab. You can make a custom Faction, but it's not necessary. Player Faction gives Leo all the rights and privileges as the Player.


 Select the Inventory Tab. You can leave anything there or delete it. If you make him Essential he can't be looted anyway.

Select the Spell Tab. Depending on your choice of creature there may be a Disease listed. If so, delete it. The mountain lion has a Resist Frost ability which you can leave intact. Other creatures may have their own Abilities which can stay as well. This can depend on whether you decide to give him a Defensive spell that includes what he already has or boosts it. In that case remove the default spells.

There's no need to do anything with the other Tabs except if you want to add new meshes and textures for your creature, but this tutorial deals with the default Mountain Lion..
You can preview him moving and attacking by selecting the Animations Tab and clicking each movement to see him in the preview window. Tick the Preview Full box to do this.

**Remember to save often. Make regular backups of the esp so you can revert to a previous file if you make a mistake and have saved it! **


NEXT:

AI Tab:

At the bottom of the stats Form is the AI Tab. Click to change the values at the top of the new window.




Aggression -- I've found 5 or 10 works well. Some companions use zero, but I found it causes the companion to be passive at the most inopportune times. Anything above can cause him to attack indiscriminately, including friends.
Confidence -- the higher the setting the less likely he is to run from a fight. 75 is a good number. If he's Essential and you want him to break off a fight if you decide to run or come back to fight another day, you could try a lower number. I have several Pet Only mods. Their aggression and confidence settings are different so they will flee when danger approaches and return when combat is over. It's not necessary to script this.
Energy Level -- This determines how much he moves around and animates when idle. Actors with low energy levels idle more often. You can leave it at the default for your creature.
Responsibility -- leave this at zero otherwise you will be reported for crimes by Leo and he can also accrue a bounty which applies to you being the owner.

At the bottom is the AI Package List. Right click on any packages in the list and delete all of them.

**Click SAVE and OK at the Stats page. Save the esp.

THE PACKAGES THAT MAKE LEO FOLLOW AND WANDER:

You will need to create a new Global Value first. Go to the Gameplay menu at the top of the main CS window and choose Globals.
Right click on any one and choose New.
Call it "LionFollow". Click OK. If you're using another name or creature, it still must be **Follow. In my House Cats mod I called them by their individual names..eg CleoFollow, PepperFollow etc. They must all be different otherwise the same value will relate to them all and the Follow and Wander commands for one will be used by them all of them. So, if you make two dog companions or even companion separate mods, they must be named for that creature so problems don't occur if using the mods together in game.

Now you have to make two AI packages.....Follow and Wander.

FOLLOW PACKAGE:

Open your creature entry again and return to the AI Window:

Right click again in the AI Package List and select NEW.
Select at least, Allow Falls, Defensive Combat and Allow Swimming.

At the top right where it says Package type select "Follow" from the drop down list.

In the ID tab give it a name for example (yourprefix)LeoFollow.

You'll then see four tabs:

SCHEDULE, CONDITIONS, LOCATION and TARGET.

Go to the CONDITIONS Tab -

At the very bottom click on the "NEW" button and select "GetGlobalValue" from the list.
The next box "Function Parameters" will say Invalid....click it and select the Global Value you made before. ie LionFollow
Leave the Comparison box as is and change the Value to 1.0000.


 Go to the TARGET Tab and select Specific Reference then select PlayerRef in the "ref" tab.
At the bottom right where it says Distance enter a number. This is how far Leo will be behind you when he follows. The number I use is 170 which is the distance the mod I based Sher Ja on uses. I assume it's feet, but we're metric in Australia. Anyway, it's a good distance because the companion is not under your feet or bumping into you all the time. This is also good if you use horses, because he won't be pushing the horse from behind when you are stationary. You can make it smaller or larger if you like.



Click OK . You can go onto the next Package or click SAVE and come back to it. Remember to save and backup your esp.

WANDER PACKAGE:

Do exactly the same again, but this time call the ID "LeoWander". Choose the Package Type as Wander.


 Do the same at the Conditions Tab, but leave the Value at 0.0000.

Click the LOCATION Tab and select Near Current Location. Give it a distance. Again mine is 1800. This is how far he will wander around when you activate him to tell him to wait. Some mods use 1200 or less...it's up to you. When you have the summon spell you can call him to you anyway if he's wandered off into dense forest. In fact I have lowered this distance in my more recent mods myself.


 Make sure Defensive Combat, Allow Falls and Allow Swimming are selected here as well. Click OK and SAVE to close the window.

PLACE LEO IN THE WORLD:

NOTE:
He must be placed in the world before you can make the Summon Spell and especially before using the updated script adding the spell and sneak component to the main script posted after this tutorial. This because you need his Editor Reference to add to the spell script.

In the Cell View window where it says World Space and in the selection box, find and select Tamriel.
You can click on any name to select it then type the 1st letter of the area you want to load......For example "I"...then scroll down to the IC Waterfront01.

Double click to load the area in the Render Window on the right. It may take a few seconds to load depending on your system.

Zoom in to the location you want to place your creature. Try to get as close as possible to where you want to place him, then drag the creature (the text) from the Object Window to the world and press F to drop him. Don't drop him from way up high or you might have trouble finding him, especially in an exterior. If that happens you can find him by looking in the left side of the Cell View Window where you are placing him. Find his ID and double click it and the CS will locate him for you.

Press the A key to turn on the lights so you can see what you are doing.
Use a combination of Shift + Mouse Wheel (held) alternately to manipulate the screen to get as close as possible to the desired position. Scroll the mouse wheel to zoom in and out.
Click the creature so it is selected to move it around, and use the Right Mouse Button to rotate it if necessary. Or use the Z, X and Y keys for other movement.

When he's in the world double click him and give him an Editor Reference ID. This can be the same as his stats form ID, but put REF at the end. No spaces. Select Persistent Reference so he won't disappear when cells respawn. You should also select the Ownership Tab and make him Player owned. This will ensure he doesn't attack friendlies and will even defend you from guards if you resist arrest.


 Now it's a good idea to open his Stats Form and check Quest Item. Making him a quest item gives him loading priority, so he always gets loaded at game start. Otherwise he can also be forgotten by the game engine when cells respawn.
Don't do it before putting him in the world or the CS will prompt you about Quest items and possibly give an error message.

Save your plugin and test it. At this point we haven't added the Summon Spell, but you should make sure he is where you want him. He can be activated to Stay and Follow without the spell once the script is added.

NOW ADD THE SCRIPT



It's a good idea to type or copy the script to a text editor like Notepad first. That way you can make alterations if necessary before adding it to the creature and risking errors when you try to save it.

You'll see where it says LionFollow you must change it to the name of the Global Value you made for your creature. The message as you see can be whatever you like, but should not go to another line.

Give the script a name. It should have SCRIPT at the end no matter what you call it.

The bottom part of this script also tells him not to attack you if you hit him, but is probably not necessary because making him Player Owned does the same thing. However, I was advised to leave it in and it doesn't appear to have any adverse effects. When I get to it I will test without that part of the script, but for the moment it's probably not doing anything anyway.

NOTE: "scn" means script name. You can also use the word ScriptName instead.

Code:

scn AASherJaScript

ref rEnemy

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

begin OnActivate

   if IsActionRef player
      SetIgnoreFriendlyHits 1
      if LionFollow == 1
         set LionFollow to 0
         Message "'Sher Ja, wait for me.'"
      elseif  LionFollow == 0
         set LionFollow to 1
         Message "'Sher Ja, come with me.'"
      endif
      EvaluatePackage
      playGroup Idle 1
            else
      activate
           endif
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

begin OnStartCombat

;make sure not to attack friends after accidental hits.

   set rEnemy to getCombatTarget
   if GetShouldAttack rEnemy == 0 && Player.GetShouldAttack rEnemy == 0
      StopCombat
      StopCombatAlarmOnActor
      playGroup Idle 1
      return
   endif
end


NEXT

In the creature's Stats Form click on the little box with "......" on it, next to the Script field, beneath the NAME field.
Select New from the Menu. Copy and paste the script into the box. Make sure it is an Object Script. Select this from the Script Type list at the top right of the script window.
Select Save from the Menu or use the disk Icon. You can also just click the cross and if there are no errors it will save.

DO NOT EVER SELECT RECOMPILE ALL WHEN SAVING -- This will compile every script in the game and your plugin will be extremely large not to mention problematic.

You'll have to close the stats form and re-open it to select the script from the drop down list in the Script Field below your creature's name.

Close the Stats Form, SAVE and backup again.


NEXT:

CREATE THE ITEM TO HOLD THE SUMMON SPELL

If everything is working correctly we can go ahead and create the object that contains the spell and the spell itself.

**If you have Shivering Isles installed be careful about using items from the expansion unless you plan to use a creature and object from SI. Items, objects and spells etc from SI are usually prefixed with SE. If you plan to release the mod using SI items make sure to add that to the Readme.
From the OBJECT LIST choose an item from the ITEMS list which will hold the Summon Spell script. It can be virtually anything, for example a gemstone or a bone which I used for Sher Ja or a shoe which I used for a dog companion. As long as a script can be added, it will work.

***Be careful about using Quest Objects as you must be sure to remove the tick from Quest Item first otherwise it will interfere with the related quest.
Once you've decided what you will use, double click to open the item's Form. As described above for Leo, give the item a unique ID and a name that will be displayed in the game. When prompted to create a new item, click YES. Leave the item for now. We have to create the Summon Spell before we can add the script to it.


CREATE THE ACTUAL SUMMON SPELL

In the OBJECT Window got to Magic/Spell. I usually make a Summon Spell a Lesser Power because it's easier to find if you have a lot of spells like I do. Otherwise it can be a basic spell.

Right click on any spell and select NEW.

Give your spell a unique ID and a name which will appear in your spell book. Select the type of spell eg Lesser power. Select Script Effect Always Applies.
Remove the tick from Auto Calculate. This negates the Magicka cost of casting the spell unless you want it to have one. Close the Spell Form and reopen it. This saves your changes.

Right Click in the text field on the right and select NEW. From the Effect List select Script Effect. The Range is on SELF because we are casting the spell on ourselves. There is no need for a duration for this spell.
Leave the Script and Effect names for now. Choose the school of magic, eg Conjuration and a visual effect if you want one. I sometimes choose Command Creature for my companions, but this is better for Summoned Creatures only rather than constant companions. It's up to you though.

Remove the tick from Effect is Hostile. Again, close the Form and reopen it.

Now we add the script. In the text field it will say Script: NONE. Right click and select EDIT.

Click on the "..." next to the Script drop down box and a Script Editor window will open the same way as when we created the companion.
Select NEW from the menu and copy and paste this script into the blank box. Make sure to choose MAGIC from the drop down box on the right.

Code:
scn SummonSherJaScript
Begin ScriptEffectStart
AALionref.moveto player, 100, 0, 0
End
Begin ScriptEffectFinish
End

Give your script a unique name. It should have Script at the end as shown. Change AALionref to the Editor Reference you made when you placed your creature in the world.
Save your script and close the Script Editor. Click OK to close the Effect Item Box and OK again to close the Spell Form. This saves the information.

The distance in the script is sufficient so that it won't land on top of you but a few feet away.

Once again open your spell and the Effect Item Box. Select the script you just made from the drop down list. Give the effect a name in the Effect Name field, eg Summon Creature or Summon "It's name."
Now the script will show in the text field of the Spell Form. You can click OK to close it now.


ADD THE SUMMON SPELL TO YOUR ITEM

Find your item in the ITEM list and open it's Form. Add this script to it the same way as we added the previous scripts. This one must be an OBJECT script.

Code:
scn AASummonSpellScript

short doOnce

begin OnActivate
if doOnce == 0
Message "Friendship will be your reward"
Player.addspell AASherJaSpell
set doOnce to 1
endif
activate
end

Once again give it a unique name and add it to your item the same way as the previous scripts.
You can add a message as shown, which will show in game at the top left of the screen when you take the object. You will also receive a message to say the spell has been added to your spell book. If you prefer not to have the message in the script you can delete that line, but make sure not to leave the line blank. Move the next line up.
Click OK to close and save the information.

Place the item in the world the same way as you placed your creature. Drag the name of the item into the Render Window and place it wherever you like.

***Save your esp and now test it to make sure everything works as intended.

EXTRA NOTES

Your companion will start to wander as soon as you enter the cell where you placed him. If he has wandered off, just pick up your item containing the Summon Spell to bring him to you.
Activate him to make him Follow and again to make him Stay. He will take care of the rest.

I usually create a Healing Ability Spell even though my companions are Essential. Even Essential companions can very often become unconscious when you really don't want them to, and some of the WAC enemies are pretty hard.

See the screen shot for the Healing Ability I added to Sher Ja. You can make it weaker if desired, but this keeps him going in most heavy battles. I have in fact made changes to this ability in all my companions, but the following screen shot is the original.

They are still essential with this change, but can be knocked out more easily and now their health bar will show. I've added Resist Poison 75% and Resist Magicka 50%. The reason for this is I've been finding certain custom poisons and some enchantments in some mods cause lasting damaging effects to companions and in Essential companions they can become permanent requiring a reboot of the mod. Sometimes you'll see it happen with NPC companions where they will get up and fall down constantly because they've been damaged. Plus other odd effects.

For example My Dog Rosie was hit by a weapon with Damage Speed several times and ended up running as though in a pool of molasses, so I added the resistances which have worked so far. It's only happened once, but that was enough.


 Create a spell as described for the Summon Spell, but not a Script effect. Make it an Ability and drag the Spell to the companion's Spell Tab in his Stats form

If there are any problems or something seems unclear, please ask and I'll do my best to clarify.


UPDATE:   The following is to add the spell and sneak function to the main script. 

This is the updated script with the sneak function as well as adding the summon spell when activating your companion that I'm now using for all my companions. With this script it's not necessary to make an object to hold the spell. It's directly added to the companion and when activated it will be added to your spell book. It also means you have to find the companion before getting the spell so if it's wandered off you need to look around.

If you choose to use this script for the sneak function, but wish to still have an object for the spell you must remove the part of the script referring to the summon spell.

The sneak function works. If you are sneaking you can get right up to an enemy before the companion will react, and then only when you are detected or you attack first. Then he will enter combat mode. I've tested this extensively before releasing my updates and I know it works. I never noticed whether the sneak eye remains lit when sneaking with the companion, and I don't think there's much I can do about it anyway. I also don't add Chameleon because I don't think it's necessary. However, you can add the Chameleon shader via the script only when sneaking if you wish.

NOTE: This relies entirely on your sneak skill so if it's low and you are detected in a dungeon full of vampires expect havoc.

In the updates to my companions I also altered the Healing Ability as described in the main tutorial. They are detailed in my Readme texts, but it's your choice in that regard.


Code:
scn AASherJaScript

ref rEnemy
short doOnce
ref GetSelf


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

begin OnActivate

   if IsActionRef player
      SetIgnoreFriendlyHits 1
      if doOnce == 0
         Player.addspell AASherJaSpell
      set doOnce to 1
      endif
   if (GetSelf.GetForceSneak == 0) && (player.IsSneaking == 1)
         GetSelf.SetForceSneak 1
        elseif (GetSelf.GetForceSneak == 1) && (player.IsSneaking == 0)
         GetSelf.SetForceSneak 0
      endif
      if LionFollow == 1
         set LionFollow to 0
         Message "'Sher Ja, wait for me.'"
      elseif  LionFollow == 0
         set LionFollow to 1
         Message "'Sher Ja, come with me.'"
      endif
      EvaluatePackage
      playGroup Idle 1
            else
      activate
           endif
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

begin OnStartCombat

;make sure not to attack friends after accidental hits.

   set rEnemy to getCombatTarget
   if GetShouldAttack rEnemy == 0 && Player.GetShouldAttack rEnemy == 0
      StopCombat
      StopCombatAlarmOnActor
      playGroup Idle 1
      return
   endif
end






Thank you for reading and I hope someone finds it useful. 

No comments:

Post a Comment