Difference between revisions of "Scripting Tutorial: Updating your leveled items"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>ZuTheSkunk
(New page: You probably know about level scalling used in entire game. And you probably know about common problem which comes with leveled rewards from quests - once you receive one particular versio...)
 
imported>ZuTheSkunk
m
Line 212: Line 212:


And this is all. Below you will find my example of complete script, to be absolutely sure that you have understood everything correctly.
And this is all. Below you will find my example of complete script, to be absolutely sure that you have understood everything correctly.
== Example of completed script ==
<pre>
<pre>
scn aaaTestScriptUpdater
scn aaaTestScriptUpdater

Revision as of 07:27, 2 June 2010

You probably know about level scalling used in entire game. And you probably know about common problem which comes with leveled rewards from quests - once you receive one particular version of the item, including low-leveled ones, then it remains the same forever, what can be quite annoying when your character reaches 30-th level or higher and you still possess that stupid 10-th level version of the sword. If you wish to make level scalling less annoying - no matter for what purpose you might need it, for your own pleasure, or maybe also for other users of your mod - then you should consider creating a script which updates specific leveled items every time your character reaches enough high level. And this is what I am going to show in this tutorial.


Tools used in this tutorial

Required


Requirements

Basic knowledge of:

Commands and Functions used

Tutorial

The idea of the script itself is simple - it runs all the time, checking if you are possessing a specified item with too high level, and if yes, then replaces it with better version. For example, if you type to check does you are possessing a steel longsword while having level 16 or higher, the script will notify if those two conditions are true and will perform the desired result. For the purpose of this tutorial, I have created a custom script of updating the Blackwater Blade from quest "Unexpected Voyage". You can take a look on him at the bottom of this article and see for your own.

  • Start Construction Set as usual. Checking Oblivion.esm as master file is required.
  • Open Script Window and use the File Menu (those buttons at the top) to create a new one.
  • First of all, you need to type name of the script:
 scn <Name of your script> 
  • Okay, we have the most basic part of the script. For the purpose 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, what means you have reached another level. It is not essential for your script and I am using it to simplify the progress, so you will not need to type every time "player.getlevel", but just "LVL". With this part, our script will look this way so far:

scn <Name of your script>

short LVL

Begin GameMode

	if ( LVL != player.getlevel )
		set LVL to player.getlevel
	endif
  • Now it is a time to create first part of script which checks does the player is possessing a specified item with too high level. Since it has been reported that riding a horse when such script runs might create problems, we will add the condition which blocks the script while player is on the horse. Also, to prevent situations when player is currently holding the item in his hand or wearing it and the script suddenly unequips the item from him, we will add the condition which checks does the player is currently using the specified item. So, we need to type this:
	if ( player.IsRidingHorse == 0 )
		if ( player.getitemcount IDofLowLevelItem > 0 && LVL >= NumberOfLevelWhenPlayerShouldn'tHaveThisItem )
			if ( player.getequipped IDofLowLevelItem == 1 )

Obviously, in "IDofLowLevelItem" we need to type the ID name of item that should be replaced with better version, and in "NumberOfLevelWhenPlayerShouldn'tHaveThisItem" we need to type the number of minimum level, when this item becomes too low-level for player and must be replaced with better one.

  • Okay, so we have our first conditions in our script. Now we need to type the lines which takes the low-level item away from player and gives the better version instead. The most simple version may look this way:
	if ( player.IsRidingHorse == 0 )
		if ( player.getitemcount IDofLowLevelItem > 0 && LVL >= NumberOfLevelWhenPlayerShouldn'tHaveThisItem )
			if ( player.getequipped IDofLowLevelItem == 1 )
				player.unequipitem IDofLowLevelItem
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
				player.equipitem IDofBetterItem
			else
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
			endif

As you may guess, "IDofBetterItemOrLeveledList" means ID name of specific better item if there is only one such item, or of the leveled list if there are many of those better versions. "IDofBetterItem" means ONLY a specific better item.

This part of script does following: first, it unequips the item and takes him away, then it adds the better item or the leveled list to the player, and finally it equips this better item on the player (assuming that he is actually using it, otherwise it will just remove the low-level version and add the better one). You must remember that if there are many of those better versions, then you need to type every single one for the part when script must equip it on the player - it will not guess which one should be equipped, and if player is not currently possessing the version typed for "equipitem" function, then player will just remain with not held/worn item.

That was the most simple version. For this one, it will just do what it should and you will be notified with this by "XXX removed" and "XXX added" messages. If you would like to remove them, there are two ways to perform that, and you can learn about both of them by checking Message Spam article.

  • Okay, it is time to check what we have made 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 IDofLowLevelItem > 0 && LVL >= NumberOfLevelWhenPlayerShouldn'tHaveThisItem )
			if ( player.getequipped IDofLowLevelItem == 1 )
				player.unequipitem IDofLowLevelItem
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
				player.equipitem IDofBetterItem
			else
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
			endif
		endif
  • Now if you wish to add more versions to replace, then just copy/paste the part after "if ( player.IsRidingHorse == 0 )", and do not forget about replacing "if" with "elseif".
  • To complete the script, finish it with enough "endif" and 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 IDofLowLevelItem > 0 && LVL >= NumberOfLevelWhenPlayerShouldn'tHaveThisItem )
			if ( player.getequipped IDofLowLevelItem == 1 )
				player.unequipitem IDofLowLevelItem
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
				player.equipitem IDofBetterItem
			else
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
			endif
		endif
	elseif ( player.getitemcount IDofAnotherLowLevelItem > 0 && LVL >= NumberOfLevelWhenPlayerShouldn'tHaveThisItem )
		(...)
		endif
	endif

End

And at this point, your script should be correct.

  • There is only one thing to do - you must add it to the quest in order to make it working. Set type of your script as "Quest" at the File Menu.
  • Add new quest by clicking RMB on the list and checking "New".
  • Click this quest and in "Script" part choose your script from the list.
  • You did it! Now save your mod and you are free to go.

There is one more feature to add, if you wish. Such updating script can be a bit problematic for the game and can make it working slower if there are many such scripts working in the background. To avoid such problem, you should do following:

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

In this case, your script will look this way:

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 IDofLowLevelItem > 0 && LVL >= NumberOfLevelWhenPlayerShouldn'tHaveThisItem )
			if ( player.getequipped IDofLowLevelItem == 1 )
				player.unequipitem IDofLowLevelItem
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
				player.equipitem IDofBetterItem
			else
				player.removeitem IDofLowLevelItem 1
				player.additem IDofBetterItemOrLeveledList 1
			endif
		endif
	elseif ( player.getitemcount IDofAnotherLowLevelItem > 0 && LVL >= NumberOfLevelWhenPlayerShouldn'tHaveThisItem )
		(...)
		else
			set NotPerform to 1
		endif
	endif

End

Remember that in this version, this script will replace your item ONLY if you are currently possessing it while gaining a new level, because we have forced the script to block itself after completing his task and to not run again unless you have reached another level.

  • To avoid this, you should also add this script to the item:
scn <Name of your another script>

Begin OnAdd Player

	set IDofTheQuest.NotPerform to 0
	
End

"IDofTheQuest" is a ID name of the quest you have just created. This script will cause game to make quest script running whenever you add the item to your inventory.

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

Example of completed script

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