Jump to content

Having trouble scripting global variable change (among other problems)


Recommended Posts

While laying this out here, I'm positive there's a better way to do this, so I'm open to any suggestions.

What I'm trying to do is have a player need to discover 3 (randomly selected) locations for dialogue to open up with an npc.

In the first quest stage fragment I set 3 global variables to integers each of which refers (via index) to objects in a Formlist (locations).

So in the first quest stage fragment I have: 

csbMagLocHunt01.SetValueInt(place01)                    ; where place01 = random 0..6
csbMagLocHunt02.SetValueInt(place02)
csbMagLocHunt03.SetValueInt(place03)

In the 'end' fragment for npc dialogue I have (ie. every time you talk to them):

---------------------------------

if csbmaglochunt01 != 69                                    ; ie if player hasn't found that location
   if IsLocationDiscovered(csb_ScoutLocLoc.getat(csbmaglochunt01.getvalue()))                                               csb_scoutlocloc is a formlist with locations
      csbMagLocHunt01.SetValueInt(69)            ;to denote player has found the location
   endif
endif

if csbmaglochunt02 != 69
   if IsLocationDiscovered(csb_ScoutLocLoc.getat(csbmaglochunt02.getvalue())) 
      csbMagLocHunt02.SetValueInt(69)
   endif
endif

if csbmaglochunt03 != 69
   if IsLocationDiscovered(csb_ScoutLocLoc.getat(csbmaglochunt03.getvalue())) 
       csbMagLocHunt03.SetValueInt(69)
   endif
endif

------------------------------------

Attached to the quest is the following borrowed script--ie. not mine.


Bool Function isLocationDiscovered(ObjectReference akMapMarker)
    if akMapMarker.IsMapMarkerVisible() == True
        if akMapMarker.CanFastTravelToMarker() == True
            return true
        endif
    endif
  
    return false
EndFunction

-------------------------------------------------------

 

First problem I have is that it doesn't like csbMagLocHunt02.SetValueInt(69), saying the property is 'already defined'.

Any ideas ?

 

 

Edited by csbx
Link to comment
Share on other sites

Um - yes. Yes I did. Thanks for weeding through the mire and noticing that !

I think now the problem is that I don't know how to reference the function that's in the script attached to the quest. I'm trying to call it here in the dialogue script.

I'm trying to call: isLocationDiscovered(ObjectReference akMapMarker)

Link to comment
Share on other sites

If you attach  the .psc files of the script attached to the quest, and the TIF fragment file in the TopicInfo here, I might give better help.

In general, you want to keep your fragments as concise as possible.    I would suggest that you move that entire function into the quest script.

For TopicInfo to call a function in the script of the quest it belongs to:

Assuming the script  attached to your quest is called 'MyQuestScript', and the function is 'CheckLocations()' then in TopicInfo:

(GetOwningQuest() as MyQuestScript).CheckLocations()

 

Link to comment
Share on other sites

Script attached to quest:

Scriptname MyQuestScript extends Quest

GlobalVariable Property  csbMagLocHunt01 Auto
GlobalVariable Property  csbMagLocHunt02 Auto
GlobalVariable Property  csbMagLocHunt03 Auto
FormList       Property  csbScoutLocLoc  Auto

Function CheckLocations()
    If csbMagLocHunt01.GetValueInt() != 69                                    
        If IsLocationDiscovered(csbScoutLocLoc.GetAt(csbMagLocHunt01.GetValueInt()) as ObjectReference)                                             
            csbMagLocHunt01.SetValueInt(69) 
        EndIf
    EndIf

    If csbMagLocHunt02.GetValueInt() != 69                                    
        If IsLocationDiscovered(csbScoutLocLoc.GetAt(csbMagLocHunt02.GetValueInt()) as ObjectReference)                                             
            csbMagLocHunt02.SetValueInt(69) 
        EndIf
    EndIf

    If csbMagLocHunt03.GetValueInt() != 69                                    
        If IsLocationDiscovered(csbScoutLocLoc.GetAt(csbMagLocHunt03.GetValueInt()) as ObjectReference)                                             
            csbMagLocHunt03.SetValueInt(69) 
        EndIf
    EndIf
EndFunction

Bool Function IsLocationDiscovered(ObjectReference akMapMarker)
    Return (akMapMarker.IsMapMarkerVisible() && akMapMarker.CanFastTravelToMarker())
EndFunction

Then, in TopicfInfo fragment:

(GetOwningQuest() as MyQuestScript).CheckLocations()

 

Link to comment
Share on other sites

My general thought would be:

Assuming you have a FormList of all potential locations you need to discover, and you need to select a random 3 from those.

FormList Property AllPossibleLocations Auto
FormList Property LocationsToDiscover Auto

While LocationsToDiscover.GetSize() < 3
    Int idx = Utility.RandomInt(0, AllPossibleLocations.GetSize() - 1)
    If !LocationsToDiscover.HasForm(AllPossibleLocations.GetAt(idx))
        LocationsToDiscover.AddForm(AllPossibleLocations.GetAt(idx))
    EndIf
EndWhile
                                      

Then, your CheckLocations() can be:
 

GlobalVariable Property LocationsFound Auto ;; set initially to 0

Function CheckLocations()
    Int idx = 0
    While idx < LocationsToDiscover.GetSize()
        ObjectReference mapMarker = LocationsToDiscover.GetAt(idx) as ObjectReference
        If (mapMarker && mapMarker.IsMapMarkerVisible() && mapMarker.CanFastTravelToMarker())
           LocationsToDiscover.RemoveAddedForm(mapMarker)
           LocationsFound.SetValueInt(LocationsFound.GetValueInt() + 1)
        Else
           idx += 1
        EndIf
    EndWhile
EndFunction

And the condition for NPC dialogue to open up would be for 'LocationsFound' to be 3.

Link to comment
Share on other sites

Scorrp10 - I haven't checked the last bit of code re: checking locations, but everything else is running well. I'm also now able to call functions (in general) like a big boy because of your writeup.

THANK YOU !

Link to comment
Share on other sites

  • Recently Browsing   0 members

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