RmD291 Posted November 16, 2017 Share Posted November 16, 2017 Hello, I have been trying to get a script to modify the properties of another one. This has been working, save for one case in particular.This failure is simply the values I am attempting to save in an array are not being properly written, or rather, they seem to reset to the ones I had placed in it initially. The following are the scripts I have made. I have each one placed in different quests. 1st: Script whose property is not working as expected(Failing Property is called NextQuestsIds) Scriptname SRTBaseQuestScript extends Quest SRTChainControlCenterScript Property ChainQuestCenter Auto Int Property CombatAttribute Auto Int Property DefendAttribute Auto Int Property SupportAttribute Auto Int Property TravelAttribute Auto Int Property GatherAttribute Auto Int Property CaptureAttribute Auto Bool Property IsInUse Auto Int Property SelfQuestChainId Auto Int Property ParentQuestId Auto Int[] Property NextQuestsIds Auto Function InitProperties() CleanNextQuests(); EndFunction Function CleanNextQuests() NextQuestsIds = new Int[4]; int idInit = 0; while(idInit < 4) NextQuestsIds[idInit] = -1; idInit += 1; endWhile EndFunction Function ProgressQuest() SRTChainQuestScript pQst = ChainQuestCenter.GetChainQuest(ParentQuestId) as SRTChainQuestScript; pQst.ProgressQuest(self); EndFunction Function CleanUp() SelfQuestChainId = -1; ParentQuestId = -1; NextQuestsIds = None; IsInUse = false; EndFunction 2nd: Script that was supposed to change the values of the 1st script properties(The changes should be applied in the function SetupNextQuests. Function responsible for the whole is MainSetup) Scriptname SRTChainQuestScript extends Quest SRTChainControlCenterScript Property ControlCenter Auto Int Property ChainQuestId Auto String[] Property BaseQuestTypes Auto Quest[] Property BaseQuests Auto SRTBaseQuestScript[] Property ChainQuestGraph Auto Int NumberStages; Int MaxNumberStages = 4; Int MaxNumberQstsPerStage = 4; Int MaxNumberBranches = 4; Int QuestIndex = 0; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Int[] Function GenerateChainQuestLimits() Int[] result = new Int[4]; NumberStages = Utility.RandomInt(2, MaxNumberStages); int generationStepCounter = 0; while(generationStepCounter < NumberStages) if(generationStepCounter == 0) result[generationStepCounter] = Utility.RandomInt(1, (MaxNumberQstsPerStage / 2)); else result[generationStepCounter] = Utility.RandomInt(1, MaxNumberQstsPerStage); endIf generationStepCounter += 1; endWhile while(generationStepCounter < MaxNumberStages) result[generationStepCounter] = -1; generationStepCounter += 1; endWhile return result; EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function SetupBaseQuest(int newQstId, string focus = "", SRTBaseQuestScript[] pQsts = None) SRTBaseQuestScript newQst = ControlCenter.SelectBaseQuestType(focus, pQsts); While(newQst == None) newQst = ControlCenter.SelectBaseQuestType(focus, pQsts); EndWhile newQst.Start(); newQst.InitProperties(); newQst.isInUse = true; newQst.SelfQuestChainId = newQstId; newQst.ParentQuestId = ChainQuestId; ChainQuestGraph[newQstId] = newQst; EndFunction SRTBaseQuestScript[] Function SetupNextQuests(SRTBaseQuestScript[] pQsts, SRTBaseQuestScript[] nxtQsts, int numPQsts) int qstCounter = 0; while(qstCounter < numPQsts) int nxtQCounter = 0; while(nxtQCounter < MaxNumberQstsPerStage) if(nxtQsts[nxtQCounter] != None) pQsts[qstCounter].NextQuestsIds[nxtQCounter] = (nxtQsts[nxtQCounter] as SRTBaseQuestScript).SelfQuestChainId; else pQsts[qstCounter].NextQuestsIds[nxtQCounter] = -1; endIf nxtQCounter += 1; endWhile qstCounter += 1; endWhile return pQsts; EndFunction Function SetupChainQuest(int minNumStages = 2, string focus = "") if(minNumStages < 2) minNumStages = 2; elseIf(minNumStages > MaxNumberStages) minNumStages = MaxNumberStages; endIf ChainQuestGraph = new SRTBaseQuestScript[16]; int[] chainLimits = GenerateChainQuestLimits(); int stage = 0; int qstIndex = 0; SRTBaseQuestScript[] pQsts = None; while(stage < NumberStages) int stageQstCounter = 0; SRTBaseQuestScript[] nxtQsts = new SRTBaseQuestScript[4]; while(stageQstCounter < chainLimits[stage]) SetupBaseQuest(qstIndex, focus, pQsts); nxtQsts[stageQstCounter] = ChainQuestGraph[qstIndex]; qstIndex += 1; stageQstCounter += 1; endWhile if(stage > 0) pQsts = SetupNextQuests(pQsts, nxtQsts, 4); endIf int tmpIntQ = 0; While(tmpIntQ < 4) SRTBaseQuestScript tmpPQst = pQsts[tmpIntQ ]; ChainQuestGraph[tmpPQst.SelfQuestChainId] = tmpPQst; tmpIntQ += 1; EndWhile pQsts = nxtQsts; stage += 1; endWhile EndFunction Function MainSetup(int minNumStages = 2, string focus = "") if(minNumStages < 2) minNumStages = 2; elseIf(minNumStages > MaxNumberStages) minNumStages = MaxNumberStages; endIf ChainQuestGraph = new SRTBaseQuestScript[16]; int[] chainLimits = GenerateChainQuestLimits(); int stage = 0; QuestIndex = 0; SRTBaseQuestScript[] pQsts = None; while(stage < NumberStages) StageSetup(stage, focus, pQsts, chainLimits[stage]); stage += 1; endWhile EndFunction Function StageSetup(int stage, string focus, SRTBaseQuestScript[] pQsts, int stageLimit) int stageQstCounter = 0; SRTBaseQuestScript[] nxtQsts = new SRTBaseQuestScript[4]; while(stageQstCounter < stageLimit) SetupBaseQuest(QuestIndex, focus, pQsts); nxtQsts[stageQstCounter] = ChainQuestGraph[QuestIndex]; QuestIndex += 1; stageQstCounter += 1; endWhile if(stage > 0) pQsts = SetupNextQuests(pQsts, nxtQsts, 4); endIf ;-----------------Debug---------------------; int tmpIntQ = 0; While(tmpIntQ < 4) Debug.MessageBox("ID B: " + pQsts[tmpIntQ ].SelfQuestChainId); ChainQuestGraph[pQsts[tmpIntQ].SelfQuestChainId] = pQsts[tmpIntQ]; Debug.MessageBox("ID C: " + ChainQuestGraph[pQsts[tmpIntQ].SelfQuestChainId].SelfQuestChainId); tmpIntQ += 1; EndWhile ;--------------------------------------; pQsts = nxtQsts; EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function ProgressQuest(Quest completedQst) Int[] nxtQstsIds = (completedQst as SRTBaseQuestScript).NextQuestsIds; int nxtQstCounter = 0; While(nxtQstCounter < MaxNumberBranches) int nxtQstId = nxtQstsIds[nxtQstCounter]; if(nxtQstId >= 0) ChainQuestGraph[nxtQstId].SetStage(10); endIf nxtQstCounter += 1; EndWhile EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function TerminateChainQuest() int qstId = 0; Quest currentQst = ChainQuestGraph[qstId]; while(currentQst != None) (currentQst as SRTBaseQuestScript).CleanUp(); ChainQuestGraph[qstId] = None; qstId += 1; currentQst = ChainQuestGraph[qstId]; endWhile ChainQuestGraph = None; QuestIndex = 0; EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3rd: Additional script that stores and does somethings to help the 2nd Scriptname SRTChainControlCenterScript extends Quest String[] Property BaseQuestTypes Auto Quest[] Property ChainQuests Auto SRTBaseQuestScript[] Property GatherQuests Auto; SRTBaseQuestScript[] Property GatherIngQuests Auto; SRTBaseQuestScript[] Property GatherIngFQuests Auto; SRTBaseQuestScript[] Property HuntQuests Auto; SRTBaseQuestScript[] Property HuntIngQuests Auto; SRTBaseQuestScript[] Property HuntIngFQuests Auto; SRTBaseQuestScript[] Property KillQuests Auto; SRTBaseQuestScript[] Property TalkQuests Auto; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function InitArrays() BaseQuestTypes = new String[8]; BaseQuestTypes[0] = "SRTBaseGatherQuest"; BaseQuestTypes[1] = "SRTBaseGatherIngQuest"; BaseQuestTypes[2] = "SRTBaseGatherIngFQuest"; BaseQuestTypes[3] = "SRTBaseHuntQuest"; BaseQuestTypes[4] = "SRTBaseHuntIngQuest"; BaseQuestTypes[5] = "SRTBaseHuntIngFQuest"; BaseQuestTypes[6] = "SRTBaseKillQuest"; BaseQuestTypes[7] = "SRTBaseTalkQuest"; ; BaseQuestTypes[0] = "SRTBaseAssassinateQuest"; ; BaseQuestTypes[1] = "SRTBaseCaptureQuest"; ; BaseQuestTypes[2] = "SRTBaseClearQuest"; ; BaseQuestTypes[3] = "SRTBaseConquerQuest"; ; BaseQuestTypes[4] = "SRTBaseDamageQuest"; ; BaseQuestTypes[5] = "SRTBaseDefendQuest"; ; BaseQuestTypes[6] = "SRTBaseDeliveryQuest"; ; BaseQuestTypes[7] = "SRTBaseEscortQuest"; ; BaseQuestTypes[8] = "SRTBaseExchangeQuest"; ; BaseQuestTypes[9] = "SRTBaseExperimentQuest"; ; BaseQuestTypes[10] = "SRTBaseExploreQuest"; ; BaseQuestTypes[11] = "SRTBaseFetchQuest"; ; BaseQuestTypes[13] = "SRTBaseGatherQuest"; ; BaseQuestTypes[14] = "SRTBaseGatherIngQuest"; ; BaseQuestTypes[15] = "SRTBaseGatherIngFQuest"; ; BaseQuestTypes[16] = "SRTBaseGiveQuest"; ; BaseQuestTypes[17] = "SRTBaseHuntQuest"; ; BaseQuestTypes[18] = "SRTBaseHuntIngQuest"; ; BaseQuestTypes[19] = "SRTBaseHuntIngFQuest"; ; BaseQuestTypes[20] = "SRTBaseKillQuest"; ; BaseQuestTypes[21] = "SRTBaseListenQuest"; ; BaseQuestTypes[22] = "SRTBaseReadQuest"; ; BaseQuestTypes[23] = "SRTBaseRepairQuest"; ; BaseQuestTypes[25] = "SRTBaseReportQuest"; ; BaseQuestTypes[26] = "SRTBaseSpyQuest"; ; BaseQuestTypes[28] = "SRTBaseStealthQuest"; ; BaseQuestTypes[29] = "SRTBaseTakeQuest"; ; BaseQuestTypes[30] = "SRTBaseTalkQuest"; ; BaseQuestTypes[31] = "SRTBaseTravelQuest"; ; BaseQuestTypes[32] = "SRTBaseUseQuest"; EndFunction SRTBaseQuestScript Function SearchQuest(String qstName, bool forEval = false) SRTBaseQuestScript[] baseQsts; if(qstName == "SRTBaseGatherQuest") baseQsts = GatherQuests; elseIf(qstName == "SRTBaseGatherIngQuest") baseQsts = GatherIngQuests; elseIf(qstName == "SRTBaseGatherIngFQuest") baseQsts = GatherIngFQuests; elseIf(qstName == "SRTBaseHuntQuest") baseQsts = HuntQuests; elseIf(qstName == "SRTBaseHuntIngQuest") baseQsts = HuntIngQuests; elseIf(qstName == "SRTBaseHuntIngFQuest") baseQsts = HuntIngFQuests; elseIf(qstName == "SRTBaseKillQuest") baseQsts = KillQuests; else baseQsts = TalkQuests; endIf if(forEval) return baseQsts[0]; else return GetBaseQuestType(baseQsts); endIf EndFunction ;; GetBaseQuestType (String baseQuestName) ;; Returns a free (not being used) quest with the name <baseQuestName> + ## ;; Necessary due to not being able to create new instances of quests SRTBaseQuestScript Function GetBaseQuestType(SRTBaseQuestScript[] questTypeList) SRTBaseQuestScript selectingQuest; int qstNum = 1; while (qstNum < 5) selectingQuest = questTypeList[qstNum]; if (selectingQuest != None) if ((selectingQuest as SRTBaseQuestScript).IsInUse == false) (selectingQuest as SRTBaseQuestScript).IsInUse = true; return selectingQuest; endif endif qstNum += 1; endwhile return None; EndFunction SRTBaseQuestScript Function SelectBaseQuestType(string focus, SRTBaseQuestScript[] pQsts) SRTBaseQuestScript selectedQuest; if(focus == "initial") selectedQuest = SearchQuest("SRTBaseTalkQuest"); else selectedQuest = SelectHelpVillageQuest(pQsts); endIf return selectedQuest; EndFunction Int[] Function CalculateQstScore(SRTBaseQuestScript[] qsts) int qstN = 0; int combatScore = 0; int captureScore = 0; int defendScore = 0; int gatherScore = 0; int supportScore = 0; int travelScore = 0; while (qstN < 4) SRTBaseQuestScript auxQst = (qsts[qstN] as SRTBaseQuestScript); if(auxQst != None) combatScore += auxQst.CombatAttribute; captureScore += auxQst.CaptureAttribute; defendScore += auxQst.DefendAttribute; gatherScore += auxQst.GatherAttribute; supportScore += auxQst.SupportAttribute; travelScore += auxQst.TravelAttribute; endIf qstN += 1; endWhile int[] scoreResult = new int[6]; scoreResult[0] = combatScore; scoreResult[1] = captureScore; scoreResult[2] = defendScore; scoreResult[3] = gatherScore; scoreResult[4] = supportScore; scoreResult[5] = travelScore; return scoreResult; EndFunction SRTBaseQuestScript Function SelectHelpVillageQuest(SRTBaseQuestScript[] previousQsts) SRTBaseQuestScript qstCandidate = GatherQuests[0] as SRTBaseQuestScript; SRTBaseQuestScript newCandidate; string selectQstName = BaseQuestTypes[0]; int j = 1; if(previousQsts == None) while (j < BaseQuestTypes.length) newCandidate = SearchQuest(BaseQuestTypes[j], true) as SRTBaseQuestScript; if (newCandidate.GatherAttribute > 0) if(newCandidate.GatherAttribute > qstCandidate.GatherAttribute) qstCandidate = newCandidate; selectQstName = BaseQuestTypes[j]; elseIf(newCandidate.GatherAttribute == qstCandidate.GatherAttribute && newCandidate.CombatAttribute <= qstCandidate.CombatAttribute) if(Utility.RandomInt(0,4) < 1) qstCandidate = newCandidate; selectQstName = BaseQuestTypes[j]; endIf endIf endIf j += 1; endWhile else int[] score = CalculateQstScore(previousQsts); ;; If there are more hunting quests than gather quests if(score[3] > 0) if(score[0] > score[3]) ;; Check possible quests for best match while (j < BaseQuestTypes.length) newCandidate = SearchQuest(BaseQuestTypes[j], true) as SRTBaseQuestScript; if (newCandidate.GatherAttribute > 0) if(newCandidate.GatherAttribute > qstCandidate.GatherAttribute) qstCandidate = newCandidate; selectQstName = BaseQuestTypes[j]; elseIf(newCandidate.GatherAttribute == qstCandidate.GatherAttribute && newCandidate.CombatAttribute <= qstCandidate.CombatAttribute) if(Utility.RandomInt(0,4) < 1) qstCandidate = newCandidate; selectQstName = BaseQuestTypes[j]; endIf endIf endIf j += 1; endWhile else while (j < BaseQuestTypes.length) newCandidate = SearchQuest(BaseQuestTypes[j], true) as SRTBaseQuestScript; if (newCandidate.GatherAttribute > 0 || newCandidate.CombatAttribute <= 10) If(Utility.RandomInt(0,4) < 1) qstCandidate = newCandidate; selectQstName = BaseQuestTypes[j]; endIf endIf j += 1; endWhile endIf else ;; Check possible quests for best match while (j < BaseQuestTypes.length) newCandidate = SearchQuest(BaseQuestTypes[j], true) as SRTBaseQuestScript; if (newCandidate.GatherAttribute > 0) if(newCandidate.GatherAttribute > qstCandidate.GatherAttribute) qstCandidate = newCandidate; selectQstName = BaseQuestTypes[j]; elseIf(newCandidate.GatherAttribute == qstCandidate.GatherAttribute) if(Utility.RandomInt(0,4) < 1) qstCandidate = newCandidate; selectQstName = BaseQuestTypes[j]; endIf endIf endIf j += 1; endWhile endIf endIf return SearchQuest(selectQstName); EndFunction Quest Function GetChainQuest(int chainQstId) return ChainQuests[chainQstId]; EndFunction ReferenceAlias Property QuestAgent Auto Function Placement() Actor PlayerRef = Game.GetPlayer(); QuestAgent.GetReference().MoveTo(PlayerRef, -120.0 * Math.Sin(PlayerRef.GetAngleZ()), -120.0 * Math.Cos(PlayerRef.GetAngleZ()), PlayerRef.GetHeight()); EndFunction I've been this issue for a while, however have been unable to detect/determine what might be failing or incorrect. Thanks for any help you can provide. (Anything that you think might be important that I am not mentioning just say it) Link to comment Share on other sites More sharing options...
ReDragon2013 Posted November 16, 2017 Share Posted November 16, 2017 Maybe you didn't noticed. https://www.creationkit.com/index.php?title=Arrays_(Papyrus) Important to know: How do we clean up the whole array? You took this way, that is not really working: SRTBaseQuestScript[] pQsts = None;You should use that, which is doing the job: Int[] b ; create empty array of same type inside the function as variable NextQuestsIds = b ; clear the whole array "NextQuestsIds" now SRTBaseQuestScript[] c ChainQuestGraph = c ; clear the whole array "ChainQuestGraph"Hint: every quest has a unique ID, which you receive by int i = q.GetFormID() Link to comment Share on other sites More sharing options...
ReDragon2013 Posted November 17, 2017 Share Posted November 17, 2017 Your approach to handle quest IDs is very complicated. I think this could be written much easier, but I do not have the time for that.Maybe next script adjustements push you in the right way. SRTBaseQuestScript Scriptname SRTBaseQuestScript extends Quest {rewritten by ReDragon 2017} ;SRTChainControlCenterScript PROPERTY ChainQuestCenter auto Quest PROPERTY myControlQuest auto ; Better than the script variant from above! Int PROPERTY CombatAttribute auto Int PROPERTY DefendAttribute auto Int PROPERTY SupportAttribute auto Int PROPERTY TravelAttribute auto Int PROPERTY GatherAttribute auto Int PROPERTY CaptureAttribute auto Int[] PROPERTY NextQuestsIds auto Hidden Int PROPERTY ParentQuestId auto Int PROPERTY SelfQuestChainId auto ;Bool PROPERTY IsInUse auto ; UnUSED by now ; -- FUNCTIONs -- 3 ;----------------------------- FUNCTION Init(Int ID, Int pID) ; external called by "SRTChainQuestScript.psc", see SetupBaseQuest() ;----------------------------- SelfQuestChainId = ID ParentQuestId = pID NextQuestsIds = new Int[4] int i = 0 WHILE (i < 4) NextQuestsIds[i] = -1 ; fill each entry of array with -1 i = i + 1 ENDWHILE ENDFUNCTION ;------------------- FUNCTION Terminate() ; external called by "SRTChainQuestScript.psc", see TerminateChainQuest() ;------------------- SelfQuestChainId = -1 ; use this value, instead of "IsInUse" ParentQuestId = -1 Int[] b NextQuestsIds = b ; clear the whole array "NextQuestsIds" ENDFUNCTION ;------------------ FUNCTION Progress() ; external called by whom ?? ;------------------ ;;; SRTChainQuestScript ps = ChainQuestCenter.GetChainQuest(ParentQuestId) as SRTChainQuestScript ; ps = pQst SRTChainQuestScript ps = (myControlQuest as SRTChainControlCenterScript).GetChainQuest(ParentQuestId) as SRTChainQuestScript int iMax = ps.MaxNumberBranches int i = 0 ; i = nxtQstCounter WHILE (i < iMax) int n = NextQuestsIds[i] ; n = nxtQstId IF (n >= 0) quest q = ps.ChainQuestGraph[n] as Quest q.setStage(10) ; go on for every chained quest ENDIF i = i + 1 ENDWHILE ENDFUNCTION SRTChainQuestScript Scriptname SRTChainQuestScript extends Quest {rewritten by ReDragon 2017} SRTChainControlCenterScript PROPERTY ControlCenter auto Int PROPERTY ChainQuestId auto ;String[] PROPERTY BaseQuestTypes auto ; !? ;Quest[] PROPERTY BaseQuests auto ; !? SRTBaseQuestScript[] PROPERTY ChainQuestGraph auto Int PROPERTY MaxNumberBranches = 4 auto Int MaxNumberQstsPerStage = 4 Int MaxNumberStages = 4 Int NumberStages Int QuestIndex ; -- FUNCTIONs -- ;;----------------------------------------- ;FUNCTION ProgressQuest(Quest completedQst) ; "SRTBaseQuestScript.psc", see Progress() ;;----------------------------------------- ;ENDFUNCTION ;--------------------------------------------------------------------- FUNCTION SetupBaseQuest(Int ID, String s = "", SRTBaseQuestScript[] a) ;--------------------------------------------------------------------- SRTBaseQuestScript ps ; ps = newQst WHILE (!ps) ps = ControlCenter.SelectBaseQuestType(s, a) ; s = focus, a = pQsts ENDWHILE (ps as Quest).Start() ; native funcion ps.Init(ID, ChainQuestId) ; newQst.InitProperties() ChainQuestGraph[ID] = ps ENDFUNCTION ;------------------------------------------------------------------------------------- FUNCTION SetupNextQuests(SRTBaseQuestScript[] a, SRTBaseQuestScript[] aNext, Int iMax) ; internal helper ;------------------------------------------------------------------------------------- int i = 0 ; i = qstCounter WHILE (i < iMax) ; iMax = numPQsts int j = 0 ; j = nxtQCounter WHILE (j < MaxNumberQstsPerStage) SRTBaseQuestScript ps = aNext[j] ; aNext = nxtQsts IF ( ps ) a[i].NextQuestsIds[j] = ps.SelfQuestChainId ELSE a[i].NextQuestsIds[j] = -1 ENDIF j = j + 1 ENDWHILE i = i + 1 ENDWHILE ;;; RETURN a ; *** NOT NEEDED, array has been already modified !!! *** a = pQsts ENDFUNCTION ;---------------------------------------- Int[] FUNCTION GenerateChainQuestLimits() ; internal helper ;---------------------------------------- Int[] a = new Int[4] ; a = result NumberStages = Utility.RandomInt(2, MaxNumberStages) ; 2,3,4 int i = 0 ; i = generationStepCounter WHILE (i < NumberStages) int m = MaxNumberQstsPerStage IF (i == 0) m = m / 2 ENDIF m = Utility.RandomInt(1, m) a[i] = m i = i + 1 ENDWHILE WHILE (i < MaxNumberStages) a[i] = -1 i = i + 1 ENDWHILE RETURN a ENDFUNCTION ;------------------------------------------------------------ FUNCTION SetupChainQuest(Int minNumStages = 2, String s = "") ; external called by whom ?? ;------------------------------------------------------------ IF (minNumStages < 2) minNumStages = 2 ELSEIF (minNumStages > MaxNumberStages) minNumStages = MaxNumberStages ENDIF ChainQuestGraph = new SRTBaseQuestScript[16] ; 16 int[] chainLimits = GenerateChainQuestLimits() SRTBaseQuestScript[] a ; a = pQsts int n = 0 ; n = qstIndex int i = 0 ; i = stage WHILE (i < NumberStages) SRTBaseQuestScript[] aNext = new SRTBaseQuestScript[4] ; aNext = nxtQsts int j = 0 ; j = stageQstCounter WHILE (j < chainLimits[i]) SetupBaseQuest(n, s, a) ; s = focus aNext[j] = ChainQuestGraph[n] n = n + 1 j = j + 1 ENDWHILE IF (i > 0) SetupNextQuests(a, aNext, 4) ENDIF j = 0 ; j = tmpIntQ WHILE (j < 4) SRTBaseQuestScript ps = a[j] ; ps = tmpPQst int T = ps.SelfQuestChainId ChainQuestGraph[T] = ps a[j] = aNext[j] ; *** TAKE THIS here to update the full array *** j = j + 1 ENDWHILE ;;; a = aNext ; *** DO NOT DO THAT !!! *** i = i + 1 ENDWHILE ENDFUNCTION ;----------------------------------------------------------------------------------- Function StageSetup(Int stage, String focus, SRTBaseQuestScript[] a, Int stageLimit) ;----------------------------------------------------------------------------------- SRTBaseQuestScript[] aNext = new SRTBaseQuestScript[4] ; aNext = nxtQsts int i = 0 ; i = stageQstCounter WHILE (i < stageLimit) SetupBaseQuest(QuestIndex, focus, a) ; a = pQsts aNext[i] = ChainQuestGraph[QuestIndex] QuestIndex += 1 i = i + 1 ENDWHILE IF (stage > 0) SetupNextQuests(a, aNext, 4) ENDIF ;-----------------Debug---------------------; i = 0 ; i = tmpIntQ WHILE (i < 4) int ID = a[i].SelfQuestChainId Debug.MessageBox("ID B: " +ID) ChainQuestGraph[ID] = a[i] Debug.MessageBox("ID C: " +ChainQuestGraph[ID].SelfQuestChainId) i = i + 1 ENDWHILE ;--------------------------------------; ;;; a = aNext ;;; pQsts = nxtQsts ; *** DO NOT DO THAT, array is already updated !!! *** ENDFUNCTION ;------------------------------------------------------ FUNCTION MainSetup(Int minNumStages = 2, String s = "") ;------------------------------------------------------ IF (minNumStages < 2) minNumStages = 2 ELSEIF (minNumStages > MaxNumberStages) minNumStages = MaxNumberStages ENDIF ChainQuestGraph = new SRTBaseQuestScript[16] int[] chainLimits = GenerateChainQuestLimits() SRTBaseQuestScript[] ps ; ps = pQsts QuestIndex = 0 int i = 0 ; i = stage WHILE (i < NumberStages) StageSetup(i, s, ps, chainLimits[i]) ; s = focus i = i + 1 ENDWHILE ENDFUNCTION ;----------------------------- FUNCTION TerminateChainQuest() ;----------------------------- SRTBaseQuestScript ps = ChainQuestGraph[0] ; ps = currentQst int i = 0 ; i = qstId WHILE ( ps ) ps.Terminate() (ps as Quest).Stop() ; Do we should use that here also? (ReDragon) ChainQuestGraph[i] = None i = i + 1 ps = ChainQuestGraph[i] ; get the next script in quest chain ENDWHILE SRTBaseQuestScript[] b ChainQuestGraph = b ; clear the whole array QuestIndex = 0 ENDFUNCTION SRTChainControlCenterScript Scriptname SRTChainControlCenterScript extends Quest {rewritten by ReDragon 2017} ReferenceAlias PROPERTY QuestAgent auto Quest[] PROPERTY ChainQuests auto String[] PROPERTY BaseQuestTypes auto Hidden SRTBaseQuestScript[] PROPERTY GatherQuests auto SRTBaseQuestScript[] PROPERTY GatherIngQuests auto SRTBaseQuestScript[] PROPERTY GatherIngFQuests auto SRTBaseQuestScript[] PROPERTY HuntQuests auto SRTBaseQuestScript[] PROPERTY HuntIngQuests auto SRTBaseQuestScript[] PROPERTY HuntIngFQuests auto SRTBaseQuestScript[] PROPERTY KillQuests auto SRTBaseQuestScript[] PROPERTY TalkQuests auto ; -- FUNCTIONs -- ;---------------------------------- Quest FUNCTION GetChainQuest(Int i) ;---------------------------------- RETURN ChainQuests[i] ; i = chainQstId ENDFUNCTION ;------------------- FUNCTION Placement() ;------------------- actor player = Game.GetPlayer() float f = player.GetAngleZ() float fz = player.GetHeight() float fx = Math.Sin(f) * -120.0 float fy = Math.Cos(f) * -120.0 QuestAgent.GetReference().MoveTo(player, fx,fy,fz) ENDFUNCTION ;-------------------- FUNCTION InitArrays() ;-------------------- BaseQuestTypes = new String[8] BaseQuestTypes[0] = "SRTBaseGatherQuest" BaseQuestTypes[1] = "SRTBaseGatherIngQuest" BaseQuestTypes[2] = "SRTBaseGatherIngFQuest" BaseQuestTypes[3] = "SRTBaseHuntQuest" BaseQuestTypes[4] = "SRTBaseHuntIngQuest" BaseQuestTypes[5] = "SRTBaseHuntIngFQuest" BaseQuestTypes[6] = "SRTBaseKillQuest" BaseQuestTypes[7] = "SRTBaseTalkQuest" ENDFUNCTION ;------------------------------------------------------------------- SRTBaseQuestScript FUNCTION GetBaseQuestType(SRTBaseQuestScript[] a) ; internal helper // a = questTypeList ;------------------------------------------------------------------- ;; GetBaseQuestType (String baseQuestName) ;; Returns a free (not being used) quest with the name <baseQuestName> + ## ;; Necessary due to not being able to create new instances of quests SRTBaseQuestScript ps ; ps = selectingQuest int i = 1 ; i = qstNum WHILE (i < 5) ps = a[i] IF (ps) && (ps.SelfQuestChainId < 0) ps.SelfQuestChainId = 0 RETURN ps ; /1 ENDIF i = i + 1 ENDWHILE RETURN None ; /2 ENDFUNCTION ;-------------------------------------------------------------------- SRTBaseQuestScript FUNCTION SearchQuest(String s, Bool forEval=False) ;-------------------------------------------------------------------- SRTBaseQuestScript[] a ; a = baseQsts IF (s == "SRTBaseGatherQuest") ; s = qstName a = GatherQuests ELSEIF (s == "SRTBaseGatherIngQuest") a = GatherIngQuests ELSEIF (s == "SRTBaseGatherIngFQuest") a = GatherIngFQuests ELSEIF (s == "SRTBaseHuntQuest") a = HuntQuests ELSEIF (s == "SRTBaseHuntIngQuest") a = HuntIngQuests ELSEIF (s == "SRTBaseHuntIngFQuest") a = HuntIngFQuests ELSEIF (s == "SRTBaseKillQuest") a = KillQuests ELSE a = TalkQuests ENDIF IF ( forEval ) RETURN a[0] ENDIF ;--------- RETURN GetBaseQuestType(a) ENDFUNCTION ;-------------------------------------------------------------------------------- SRTBaseQuestScript FUNCTION SelectBaseQuestType(String s, SRTBaseQuestScript[] a) ;-------------------------------------------------------------------------------- SRTBaseQuestScript ps ; ps = selectedQuest IF (s == "initial") ; s = focus ps = SearchQuest("SRTBaseTalkQuest") ELSE ps = SelectHelpVillageQuest(a) ; a = pQsts ENDIF RETURN ps ENDFUNCTION ;------------------------------------------ String FUNCTION myF_Candidate(Bool bCombat) ; internal helper ;------------------------------------------ SRTBaseQuestScript ps = GatherQuests[0] as SRTBaseQuestScript ; ps = qstCandidate SRTBaseQuestScript newCandidate string s int i = 1 WHILE (i < BaseQuestTypes.Length) newCandidate = SearchQuest(BaseQuestTypes[i], TRUE) as SRTBaseQuestScript IF ( newCandidate ) int T = newCandidate.GatherAttribute IF (T > 0) IF (T > ps.GatherAttribute) ps = newCandidate s = BaseQuestTypes[i] ELSEIF (T == ps.GatherAttribute) && (Utility.RandomInt(0,4) == 0) IF (!bCombat) || (newCandidate.CombatAttribute <= ps.CombatAttribute) ps = newCandidate s = BaseQuestTypes[i] ENDIF ENDIF ENDIF ENDIF i = i + 1 ENDWHILE RETURN s ENDFUNCTION ;------------------------------- String FUNCTION myF_Candidate2() ; internal helper ;------------------------------- SRTBaseQuestScript ps = GatherQuests[0] as SRTBaseQuestScript ; ps = qstCandidate SRTBaseQuestScript newCandidate string s int i = 1 WHILE (i < BaseQuestTypes.Length) newCandidate = SearchQuest(BaseQuestTypes[i], TRUE) as SRTBaseQuestScript IF ( newCandidate ) IF (newCandidate.GatherAttribute > 0) || (newCandidate.CombatAttribute <= 10) IF (Utility.RandomInt(0,4) == 0) ps = newCandidate s = BaseQuestTypes[i] ENDIF ENDIF ENDIF i = i + 1 ENDWHILE RETURN s ENDFUNCTION ;------------------------------------------------------------------------- SRTBaseQuestScript FUNCTION SelectHelpVillageQuest(SRTBaseQuestScript[] a) ;------------------------------------------------------------------------- string s = BaseQuestTypes[0] ; s = selectQstName IF ( a ) ; a = previousQsts ELSE s = myF_Candidate(TRUE) RETURN SearchQuest(s) ; /1 ENDIF ;--------- int[] b = new Int[6] ; b = scoreResult CalculateQstScore(a, b) ; b = score int i = b[3] IF (i <= 0) s = myF_Candidate(False) ; Check possible quests for best match RETURN SearchQuest(s) ; /2 ENDIF ;--------- If there are more hunting quests than gather quests IF (b[0] > i) s = myF_Candidate(TRUE) ; Check possible quests for best match RETURN SearchQuest(s) ; /3 ENDIF ;--------- s = myF_Candidate2() RETURN SearchQuest(s) ; /4 ENDFUNCTION ;---------------------------------------------------------- FUNCTION CalculateQstScore(SRTBaseQuestScript[] a, Int[] b) ; internal helper, see function above ;---------------------------------------------------------- int m int i = 0 ; i = qstN WHILE (i < 4) SRTBaseQuestScript ps = (a[i] as SRTBaseQuestScript) ; a = qsts, ps = auxQst IF ( ps ) m = b[0] + ps.CombatAttribute ; COMBAT b[0] = m m = b[1] + ps.CaptureAttribute b[1] = m m = b[2] + ps.DefendAttribute b[2] = m m = b[3] + ps.GatherAttribute ; GATHER b[3] = m m = b[4] + ps.SupportAttribute b[4] = m m = b[5] + ps.TravelAttribute b[5] = m ENDIF i = i + 1 ENDWHILE ENDFUNCTION Link to comment Share on other sites More sharing options...
foamyesque Posted November 18, 2017 Share Posted November 18, 2017 Properties get reinitialized to their originally defined values when a quest triggers an OnInit event. This always occurs when the quest is started, and may also occur the first time the quest loads into the game, depending on how its flags are set. I suspect this may be the root cause of your problem; if you alter the values, and then start the quest, they will get reset on you. Link to comment Share on other sites More sharing options...
Recommended Posts