[TUTORIAL] Adding a new stat

Post » Wed Sep 18, 2013 9:38 am

This tutorial explains how to add a new stat to one of the pages in the vanilla stats menu. It requires SKSE to function, but the way it's implemented means that it will only run if the user is currently running SKSE. In other words, it won't add SKSE dependency to your mod, just an extra feature for those users who do use it

First of all you need to have a GlobalVariable that stores the current value of your stat.

Stat Quest
1. Make a new quest. Untick everything then tick Allow Repeated Stages
2. Add the following script to it (dont forget to edit the stat name and the stat category index to suite your mod):
Scriptname StatQuestScript extends Quest  GlobalVariable Property myStatGlobal  AutoString sValuefunction Register()	RegisterForMenu("Journal Menu")	;Debug.Notification("Registered")endFunctionfunction Unregister()	UnregisterForMenu("Journal Menu")endFunctionevent OnMenuOpen(string a_menuName)	;Debug.Notification("Menu")	UpdateCurrentInstanceGlobal(myStatGlobal) ; Not sure if this is necessary?	sValue = http://forums.bethsoft.com/topic/1473779-tutorial-adding-a-new-stat/myStatGlobal.GetValueInt() as string	string[] args = new string[4]	args[0] ="My Stat" ; Stat name	args[1] = sValue	args[2] = "0" ; stat category index as string 0 = "General"	args[3] = ""	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", args)endEvent
3. Make two quest stages. Make one the start up stage and the other the shut down stage.
4. In the kmyQuest drop down select the quest script. Then add "kmyQuest.Register()" to the first stage and "kmyQuest.Unregister()" to the last

Maintenence Quest
1. Make a new global called "runningSKSE"
2. Make a new quest. Tick "StartGameEnabled" and make everything else blank
3. Add the following script:
Scriptname MaintenanceQuestScript extends Quest  Float fVersionInt iSKSEGlobalVariable Property runningSKSE  AutoQuest Property statQuest  Auto Event OnInit()	Maintenance() ; OnPlayerLoadGame will not fire the first timeEndEvent Function Maintenance()	If fVersion < 1.00 ; <--- Edit this value when updating		fVersion = 1.00 ; and this		; Update Code	EndIf	iSKSE = SKSE.GetVersionRelease()	If iSKSE		;Debug.Notification("SKSE Detected")		If runningSKSE.GetValueInt() == 0			runningSKSE.SetValueInt(1)			statQuest.Start()		EndIf	Else		If runningSKSE.GetValueInt() == 1			runningSKSE.SetValueInt(0)			statQuest.Stop()		EndIf	EndIfEndFunction
5. Add a new Alias. Call it "Player". Fill Type = Specific Reference (cell = (any), Ref = PlayerRef)
6. Add the following script to it:
Scriptname MaintenanceAliasScript extends ReferenceAlias   MaintenanceQuestScript Property QuestScript Auto Event OnPlayerLoadGame()	QuestScript.Maintenance()EndEvent
SKSE String file
1. Make a new txt document and add the following (remember it needs a TAB to separate the string from the translation, not a bunch of spaces):
$My Stat	My Stat
2. Use sublime to save it as "UTF16 LE with BOM", name it "yourEspName" + "_ENGLISH" (eg. myMod_ENGLISH.txt")
3. Now place it in ...data/interface/translations

The reason for the string file is to circumvent PopulateStatsList's habit of affixing whatever you write in the code with a "$"


Right i think thats it. Let me know if I missed anything

- Hypno
User avatar
Alyesha Neufeld
 
Posts: 3421
Joined: Fri Jan 19, 2007 10:45 am

Post » Wed Sep 18, 2013 8:07 pm

Multiple Stats

To add multiple stats just edit the StatQuestScript's OnMenuOpen() event as follows (example of 3 stats):

event OnMenuOpen(string a_menuName)	;Debug.Notification("Menu")	UpdateCurrentInstanceGlobal(stat1Global)	UpdateCurrentInstanceGlobal(stat2Global)	UpdateCurrentInstanceGlobal(stat3Global)	sValue1 = stat1Global.GetValueInt() as string	sValue2 = stat2Global.GetValueInt() as string	sValue3 = stat3Global.GetValueInt() as string	string[] args = new string[12]	args[0] = "Stat 1"	args[1] = sValue1	args[2] = "0" ; stat category index as string	args[3] = ""	args[4] = "Stat 2"	args[5] = sValue2	args[6] = "0" ; stat category index as string	args[7] = ""	args[8] = "Stat 3"	args[9] = sValue3	args[10] = "0" ; stat category index as string	args[11] = ""	UI.InvokeStringA("Journal Menu", "_root.QuestJournalFader.Menu_mc.StatsFader.Page_mc.PopulateStatsList", args)endEvent
- Hypno
User avatar
Chloe Yarnall
 
Posts: 3461
Joined: Sun Oct 08, 2006 3:26 am

Post » Wed Sep 18, 2013 12:27 pm

very cool, thx a lot :-))

User avatar
Tyrel
 
Posts: 3304
Joined: Tue Oct 30, 2007 4:52 am


Return to V - Skyrim