Quest Script gone wrong

Post » Fri Jan 18, 2013 9:34 am

I am working on a mod that starts with the beginning of Skyrim. At level 10 the player gets a level 1 spell, and 20 the spell is replaced with a level 2 and so on.

I have created my quest with a player alias, a quest script, and a player alias script. The quest script starts with an "OnInit" which runs through an updateplz() function which essentially figures out the players level and gives them the cooresponding spell. I did this to make it open to higher levels without having them start over. The "OnInit" works and gives me the right stuff and the right stage.

Problem
In the player alias script, I have called the updateplz() function from an OnPlayerLoad() so it essentially re-baselines the character on every load, and a OnStoryIncreaseLevel() which should hopefully do the same when the player levels up. Using messageboxes, I found that the OnPlayerLoad fires like it should, but it doesn't seem to connect with the updateplz() function (which has a debug messagebox). I've read through the CK and to my understanding, this should work. In game, I load up my character, I see the OnPlayerLoad messagebox, but I never see the updateplz() messagebox.

I'm fresh out of ideas and could use some help. I have included both the player alias script and the main script below. Also feel free to turn 10 lines of code into 1 if you see something as I'm just starting out in papyrus and I've learned by cracking open other folk's mods and scripts. I've found a lot of great ways to compress code doing this.

Main Quest Script:
Spoiler

Scriptname AAAMageLife extends Quest
{Main Quest Script for moving up the level ladder}
Quest Property qst Auto ; quest
Spell Property lvl1spl auto ; Level 1 spell
Spell Property lvl2spl auto ; Level 2 spell
Spell property lvl3spl auto ; Level 3 spell
Spell property lvl4spl auto ; Level 4 spell
FormList Property FRMLST Auto ; Formlist with the above spells
Actor Property me Auto ; make my life easier

; On the very first run, re-baseline it all!
Event OnInit()
updateplz()
Utility.wait(1.0)
qst.setstage(updatestage(me))
EndEvent

; Function which removes the older spell, and adds the new one IF the player is above the threshhold.
Function updateplz()
debug.messagebox("I'm in the update loop")
me.removespell(GetKnownSpell(me, FRMLST))
me.addspell(updatespell(me))
endFunction

;;;;;;;;;;;;;;;;;;;;;;; Function finds the right spell for the level and returns it to the update function
Spell Function updatespell(Actor plr)
int lvl = plr.getlevel()
Spell givespell
if (lvl<=10)
Return Givespell as Spell
elseif (lvl>=10)&&(lvl<20)
givespell = lvl1spl
elseif (lvl>=20)&&(lvl<30)
givespell = lvl2spl
elseif (lvl>=30)&&(lvl<40)
givespell = lvl3spl
elseif (lvl>=40)
givespell = lvl4spl
endif
debug.messagebox("I gave you a spell called " + givespell)
Return givespell as Spell
EndFunction

;;;;;;;;;;;;;;;;;;;;;;; Function removes all spells contained in the formlist
Spell Function GetKnownSpell(Actor Subject, FormList SpellFormList) Global
int kspell = 0
while kspell < SpellFormList.GetSize()
if Subject.HasSpell(SpellFormList.GetAt(kspell))
Spell TS = SpellFormList.GetAt(kspell) as Spell
Subject.removespell(TS)
endif
kspell += 1
endwhile
return None
EndFunction

; Update the stage of the quest. Done this way because the script ends with the stage setting.
int Function updatestage(Actor plr)
int lvl = plr.getlevel()
int Stage
if (lvl<=10)
Stage = 5
elseif (lvl>=10)&&(lvl<20)
Stage = 10
elseif (lvl>=20)&&(lvl<30)
Stage = 20
elseif (lvl>=30)&&(lvl<40)
Stage = 30
elseif (lvl>=40)
Stage = 40
endif
debug.messagebox("I am returning a stage of " + stage)
Return stage as int
EndFunction


Player Script attached to the player alias:
Spoiler

Scriptname AAAMagelifeincrease extends ReferenceAlias
; This script merely calls the original quest script to re-run the level checker

AAAMageLife Property up Auto

Event OnStoryIncreaseLevel(int lvl)
debug.messagebox("you leveled up!")
up.updateplz()
EndEvent

Event OnPlayerLoadGame()
debug.messagebox("you've loaded a game and I caught it")
up.updateplz()
EndEvent
User avatar
Nany Smith
 
Posts: 3419
Joined: Sat Mar 17, 2007 5:36 pm

Return to V - Skyrim