Scripting Tutorial: Updating your leveled items

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

You probably know about the level scaling used in the entire game. And you probably know about the common problem regarding the leveled rewards from quests - once you receive one particular version of the item, including low-leveled ones, then it remains the same forever. That can be quite annoying when your character reaches 30-th level or higher and you still have that stupid 10-th level version of the sword.

If you wish to make the level scaling less annoying - regardless of whether it's just for your own use or for a mod that others can download - then you should consider creating a script that updates specific leveled items every time your character reaches high enough level. And this is what I am going to show you in this tutorial.


Tools used in this tutorial

Required


Requirements[edit | edit source]

Basic knowledge of:

Commands and Functions used[edit | edit source]

Tutorial[edit | edit source]

The idea of the script itself is simple - it runs all the time, checking if you are in possession of a specified item while your level is too high, and if you do, then it will replace it with a better version.

For example, let's say that your script checks two conditions: whether a steel longsword lies in your inventory, and whether your level is 16 or higher. If both of these conditions are true, then it will perform the desired result.

For the purpose of this tutorial, I have created a custom script that updates the Blackwater Blade from the quest "Unexpected Voyage". You can take a look at the finished script at the bottom of this article.

Okay, let's get started!

Start the Construction Set as usual. Open the Script Window and use the File Menu (those buttons at the top) to create a new script.

First of all, you need to type the name of your new script:

 scn <Name of your script> 

Also, since we want to make the script run all the time, we need to type this:

 Begin GameMode 

Okay, so we have the most basic part of the script. For the purposes of what we are going to achieve, we need to check the player's level. We need to type this:

	if ( LVL != player.getlevel )
		set LVL to player.getlevel
	endif

This part will run whenever the "LVL" variable is not equal to the player's level, which means that you have reached another level. This part is not essential to your script and I am only using it to simplify the progress, so that you don't have to type "player.getlevel" every single time, but instead just "LVL".

If we are going to include this, then we have to include also this:

short LVL

The above creates a variable named "LVL" for this specific script.

With all these parts included, this is how our script should look so far:

scn <Name of your script>

short LVL

Begin GameMode

	if ( LVL != player.getlevel )
		set LVL to player.getlevel
	endif

Now it's time to create our first check. Remember these two conditions I mentioned earlier? That's what this part is going to be about.

Since it has been reported that riding a horse when such script runs might create problems, we will add a condition that blocks the script while player is riding a horse. Also, to prevent situations when the player is currently wearing the item and the script suddenly unequips it, we will add a condition that checks whether the player currently uses the specified item.

Here's how it looks:

	if ( player.IsRidingHorse == 0 )
		if ( player.getitemcount ID_Of_The_Item > 0 && LVL >= LevelValue )
			if ( player.getequipped ID_Of_The_Item == 1 )

Obviously, in "ID_Of_The_Item" we need to type in the ID name of the item that should be replaced with a better version. In "LevelValue" we need to type in the minimum level when this item becomes too low-level for the player and must be replaced with a better version.

Okay, so we have our first conditions in our script. Now we need to make sure that the low-level item will be taken away from the player and replaced with a better version. It's highly recommended to make a leveled list and have it contain all of the item's versions; the following script is written with this in mind.

The simplest version should look like this:

	if ( player.IsRidingHorse == 0 )
		if ( player.getitemcount ID_Of_The_Item > 0 && LVL >= LevelValue )
			if ( player.getequipped ID_Of_The_Item == 1 )
				player.unequipitem ID_Of_The_Item
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
				player.equipitem ID_Of_The_Better_Item
			else
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
			endif

This part of the script does the following: if the player is wearing the item, then it will first unequip it and only then take it away, followed by the new item from the leveled list being added and subsequently equipped. If the player doesn't have it equipped, then it will merely remove the old version and add the better one from the leveled list.

Remember that if you have a leveled list with many different versions of the item, then you need to type in every single one of them for the part where the script must equip it on the player - it will not guess which one should be equipped, and if the player is not currently in possession of the version affected by the "equipitem" function, then the player will end up with an unequipped item.

There is another thing you must know: in its current state, the script will notify the player about the replacements with "XXX removed" and "XXX added" messages. There are two ways to remove them; you can learn about them from the Message Spam article.

Okay, let's take a look at what we got so far:

scn <Name of your script>

short LVL

Begin GameMode

	if ( LVL != player.getlevel )
		set LVL to player.getlevel
	endif

	if ( player.IsRidingHorse == 0 )
		if ( player.getitemcount ID_Of_The_Item > 0 && LVL >= LevelValue )
			if ( player.getequipped ID_Of_The_Item == 1 )
				player.unequipitem ID_Of_The_Item
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
				player.equipitem ID_Of_The_Better_Item
			else
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
			endif
		endif

Now, if you want to include more old versions to be replaced with better ones, then just copy/paste the part after "if ( player.IsRidingHorse == 0 )" and change the values and IDs appropriately. Don't forget to replace the first "if" with "elseif".

To complete the script, finish it by typing "endif" enough times and then just one "END":

scn <Name of your script>

short LVL

Begin GameMode

	if ( LVL != player.getlevel )
		set LVL to player.getlevel
	endif

	if ( player.IsRidingHorse == 0 )
		if ( player.getitemcount ID_Of_The_Item > 0 && LVL >= LevelValue )
			if ( player.getequipped ID_Of_The_Item == 1 )
				player.unequipitem ID_Of_The_Item
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
				player.equipitem ID_Of_The_Better_Item
			else
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
			endif
		elseif ( player.getitemcount ID_Of_Another_Item > 0 && LVL >= LevelValue )
		(...)
		endif
	endif

End

And at this point, your script should be correct (don't forget to save!). There is only one thing to do - you must add it to a quest in order to make it work. This "quest" will not appear in the player's journal and will simply work silently in the background.

  • Set the type of your script as "Quest" in the File Menu.
  • Open the Quest Menu by clicking the "Q" button at the top.
  • Add a new quest by right-clicking on the list and choosing "New".
  • Select the new quest, and under "Script" choose your script from the list.
  • You did it! Now save your mod and you are free to go.

There is one more feature that can be added, if you want. Your script can be a bit problematic for the game and can make it run slower if there are many such scripts working in the background. To avoid such a problem, you should do the following:

  • Add "short NotPerform" below "short LVL"
  • Add "set NotPerform to 0" below "set LVL to player.getlevel"
  • Add "&& NotPerform == 0" after "if ( player.IsRidingHorse"
  • At the end of the script, after the last replaced item, add instead of another "elseif":
	else
		set NotPerform to 1

In this case, your script should look like this:

scn <Name of your script>

short LVL
short NotPerform

Begin GameMode

	if ( LVL != player.getlevel )
		set LVL to player.getlevel
		set NotPerform to 0
	endif

	if ( player.IsRidingHorse == 0 && NotPerform == 0 )
		if ( player.getitemcount ID_Of_The_Item > 0 && LVL >= LevelValue )
			if ( player.getequipped ID_Of_The_Item == 1 )
				player.unequipitem ID_Of_The_Item
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
				player.equipitem ID_Of_The_Better_Item
			else
				player.removeitem ID_Of_The_Item 1
				player.additem ID_Of_The_Leveled_List 1
			endif
		elseif ( player.getitemcount ID_Of_Another_Item > 0 && LVL >= LevelValue )
		(...)
		else
			set NotPerform to 1
		endif
	endif

End

Remember that in this case, this script will replace your item ONLY if it's in your possession while you're gaining a new level - this is because we have forced the script to block itself after completing its task and to not run again until you reach another level.

To avoid this, you should also add this script to the item itself:

scn <Name of the script>

Begin OnAdd Player

	set ID_Of_The_Quest.NotPerform to 0
	
End

"ID_Of_The_Quest" is the ID name of the quest you have just created. This item script will force the quest script to run whenever you add the item to your inventory.

If the item already has a script, then you will have to simply add the contents of the above script to the existing one. (Do not copy "scn <Name of the script>", since the original script already has it.) Note that this is not always a viable option, since only one mod can modify an item's script.

And this is all. Below you will find my example of a complete script, to be absolutely sure that you understood everything correctly.

Example of a completed script[edit | edit source]

scn aaaTestScriptUpdater

short LVL
short NotPerform

Begin GameMode

	if ( LVL != player.getlevel )
		set LVL to player.getlevel
		set NotPerform to 0
	endif

	if ( player.IsRidingHorse == 0 && NotPerform == 0 )
		if ( player.getitemcount MS31BlackwaterBlade01 > 0 && LVL >= 5 )
			if ( player.getequipped MS31BlackwaterBlade01 == 1 )
				message " "
				message " "
				player.unequipitem MS31BlackwaterBlade01
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade01 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
				message " "
				message " "
				player.equipitem MS31BlackwaterBlade05
				player.equipitem MS31BlackwaterBlade10
				player.equipitem MS31BlackwaterBlade15
				player.equipitem MS31BlackwaterBlade20
				player.equipitem MS31BlackwaterBlade25
			else
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade01 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
			endif
		elseif ( player.getitemcount MS31BlackwaterBlade05 > 0 && LVL >= 10 )
			if ( player.getequipped MS31BlackwaterBlade05 == 1 )
				message " "
				message " "
				player.unequipitem MS31BlackwaterBlade05
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade05 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
				message " "
				message " "
				player.equipitem MS31BlackwaterBlade10
				player.equipitem MS31BlackwaterBlade15
				player.equipitem MS31BlackwaterBlade20
				player.equipitem MS31BlackwaterBlade25
			else
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade05 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
			endif
		elseif ( player.getitemcount MS31BlackwaterBlade10 > 0 && LVL >= 15 )
			if ( player.getequipped MS31BlackwaterBlade10 == 1 )
				message " "
				message " "
				player.unequipitem MS31BlackwaterBlade10
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade10 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
				message " "
				message " "
				player.equipitem MS31BlackwaterBlade15
				player.equipitem MS31BlackwaterBlade20
				player.equipitem MS31BlackwaterBlade25
			else
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade10 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
			endif
		elseif ( player.getitemcount MS31BlackwaterBlade15 > 0 && LVL >= 20 )
			if ( player.getequipped MS31BlackwaterBlade15 == 1 )
				message " "
				message " "
				player.unequipitem MS31BlackwaterBlade15
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade15 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
				message " "
				message " "
				player.equipitem MS31BlackwaterBlade20
				player.equipitem MS31BlackwaterBlade25
			else
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade15 1
				message " "
				message " "
				player.additem MS31RewardBlackwaterBladeLeveled 1
			endif
		elseif ( player.getitemcount MS31BlackwaterBlade20 > 0 && LVL >= 25 )
			if ( player.getequipped MS31BlackwaterBlade20 == 1 )
				message " "
				message " "
				player.unequipitem MS31BlackwaterBlade20
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade20 1
				message " "
				message " "
				player.additem MS31BlackwaterBlade25 1
				message " "
				message " "
				player.equipitem MS31BlackwaterBlade25
			else
				message " "
				message " "
				player.removeitem MS31BlackwaterBlade20 1
				message " "
				message " "
				player.additem MS31BlackwaterBlade25 1
			endif
		else
			set NotPerform to 1
		endif
	endif
	
End