Jump to content

Referencing a quest within its quest script


StealthDick

Recommended Posts

I'm working on a mod that generates radiant quests.

 

To do this, I have a bunch of "blank" quests.

 

Each quest is nameless and scriptless, they are start game !(enabled) and have repeatable objectives/stages. All of the quests are held within a formlist.

 

I have a UDF that is to be called on an NPC (rGiver). When the UDF runs, it finds the first quest in the form list that isn't visible in the pip-boy. (rQuest)

 

Once a quest that meets this condition is found, it then sets the type of quest it is by getting the range of another formlist that holds quest types. This questtype formlist is full of [quest] scripts. The chosen script is then called (rQuestScript).

 

rQuestScript then becomes the script for rQuest

 

Each quest script has different variables, but they all share 3 of the same ones (iStage, rQuest, rGiver).

 

I've been scratching my head at this for the last 2 days. I cannot (for the life of me) get the UDF to set these variables up in rQuest's new script (rQuestScript).

 

Here's the udf:

scn sdGenRQ

begin function {}

short bQuestStarted
ref rGiver = this
ref rQuest

; Goes through each key in the formlist
ForEach rQuest <- sdRadiantQuests
        ;Is the NOT quest visible in the pip-boy?? 
	if (GetQuestFlag rQuest 5) == 0

		;Reset the quest before applying changes
                ResetQuest rQuest

                ;Select Quest type
		array_var aType = GetListForms sdTypeOfQuest
		int iKey = GetRandomInRange (Ar_First aType) (Ar_Last aType)
		ref rQuestScript = aType[iKey]
		SetScript rQuestScript rQuest

                ;Sets up variables for the quest
		rQuest.SetVariable "iStage", 1
		rQuest.setRefVariable "rQuest", rQuest
		rQuest.setRefVariable "rGiver", rGiver

                ;Start the quest
		StartQuest rQuest
		bQuestStarted = 1

		break
	endif		
loop

; ForEach went through the whole list and all of the quests were visible. !bQuestStarted 
if bQuestStarted == 0
	MessageEX "You cannot exceed the radiant quest limit! Max %g quests." (ListGetCount sdRadiantQuests)
endif


end

SetVariable/SetRefVariable aren't working in this case. Setting up AuxillaryVariables don't work either.

Link to comment
Share on other sites

I think you mixed up with refs and forms on these lines.

;Sets up variables for the quest
rQuest.SetVariable "iStage", 1
rQuest.setRefVariable "rQuest", rQuest
rQuest.setRefVariable "rGiver", rGiver

According to GECK wiki, the syntax for setRefVariable is this:

ref.SetRefVariable VarName:string NewValue:form Parent:Object

So if these ref variables hold base forms, which they do in this case since rQuest is a quest, you need to write them like this:

;Sets up variables for the quest
SetVariable "iStage", 1, rQuest
setRefVariable "rQuest", rQuest, rQuest
setRefVariable "rGiver", rGiver, rQuest
Edited by ebizoe
Link to comment
Share on other sites

No, it doesn't work in my test either. I think we should try alternatives.
How about letting the quest script to retrieve the new values (iStage, rQuest, rGiver) by itself.
I tested following scripts and they worked.
I set up a quest called "MainQuest" just for holding values for these variables.
This is the attached script for "MainQuest":

scn MainQuestScript
int iStage
ref rQuest
ref rGiver

This is my test script pretending to be one of the radiant quest scripts:

scn sdRadiantQuestScript1
int iStage
ref rQuest
ref rGiver
int bInit
begin GameMode {}
    if bInit != 1
        bInit = 1
        iStage = MainQuest.iStage
        rQuest = MainQuest.rQuest
        rGiver = MainQuest.rGiver
printc "QuestScript1:iStage=%.0f, rQuest=%i, rGiver=%n" iStage rQuest rGiver
    endif
end

And then, the main user function script:

scn sdGenRQ
begin function {}
    ref rGiver = BobbyPin
    array_var sdRadiantQuests = ar_List sdRadiantQuestScript1, sdRadiantQuestScript2, sdRadiantQuestScript3
    array_var aQuests = ar_List sdQuest1 sdQuest2 sdQuest3
    ForEach array_var aIter <- aQuests
        ref rQuest = *aIter
        if (GetQuestFlag rQuest 5) == 0
            ResetQuest rQuest
            int iKey = GetRandomInRange 0 (ar_Size sdRadiantQuests) ;The return value is inclusive. min <= x < max.
            ref rQuestScript = sdRadiantQuests[iKey]
            MainQuest.iStage = 1
            MainQuest.rQuest = rQuest
            MainQuest.rGiver = rGiver
            SetScript rQuestScript, rQuest
            StartQuest rQuest
            break
        endif
    loop
end

Note that since "MainQuest" is just for holding variables, it doesn't need to run.

Link to comment
Share on other sites

@ebizoe


I was able to figure it out last night. Decided to remake the whole plugin.


setRefVariable/setVariable does work, it just doesn't work on quests/objects that have their scripts changed.


I ended up basically doing what you did. I would show off my new quest script, but it looks fresh out of an Italian restaurant. It does work, however.

Link to comment
Share on other sites

It's good to know the problem is solved anyway.

>I ended up basically doing what you did. I would show off my new quest script, but it looks fresh out of an Italian restaurant. It does work, however.

I guarantee that in a month or so, you'll curse your own code being too cryptic.
Well, good luck on your mod development. We all love to play new quests!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...