Jump to content

Storing NPC-specific info


irfna

Recommended Posts

What's the most efficient way to store variables specific to a NPC? Is adding items to the NPC's inventory honestly the best way to do it? Does OBSE provide anything to aid this, if vanilla oblivion does not?
Link to comment
Share on other sites

You can use quest variables in a custom quest you make. Oblivion scripting language is rather cumbersome in this respect. It is not like a lot of scripting languages. It is as if they thought nobody would ever have scripts that needed to look at the values of variables in other scripts.

 

So the syntax is a bit counterintuitive and hard to get used to. So here is an example:

 

Quest: AAVariableHolderQUEST

 

Quest Script Attached to AAVariableHolderQUEST:

SCN AAJabberwocky

Short AANPCStat

 

Script that refers to the variable:

 

SCN AAChestOfDoom

Begin OnActivate

    If AAVariableHolderQUEST.AANPCStat > 15
         Set AAVariableHolderQUEST.AANPCStat to AAVariableHolderQUEST.AANPCStat + 1
         Activate
    EndIf 

End

 

The important thing to note is that you refer to the name of the quest that the script with your variable is attached to. You do not refer to the name of the script containing your variable. so it is:

AAVariableHolderQUEST.AANPCStat

NOT

AAJabberwocky.AANPCStat

Link to comment
Share on other sites

So this would have a different variable for any NPC I called it on? I thought this would only have one variable, assigned to the quest itself, acting more like a global variable. I want what you might consider a field for an object in OO programming, the "object" being any NPC(s) I end up putting a scripted item on. Or the item itself, I suppose.

 

edit: I'd also need to be able to access the info from other scripts, knowing just the NPC. I have seen scripts that just repeatedly add a token item to the NPC as a counter, so a make-shift integer-ish variable on the NPC. Surely there's a better way.

Edited by irfna
Link to comment
Share on other sites

So this would have a different variable for any NPC I called it on? I thought this would only have one variable, assigned to the quest itself, acting more like a global variable. I want what you might consider a field for an object in OO programming, the "object" being any NPC(s) I end up putting a scripted item on. Or the item itself, I suppose.

 

edit: I'd also need to be able to access the info from other scripts, knowing just the NPC. I have seen scripts that just repeatedly add a token item to the NPC as a counter, so a make-shift integer-ish variable on the NPC. Surely there's a better way.

 

Well, I think the best method would likely be a multi-level StringMap using OBSE. A StringMap is an array with the indexes being a text value instead of an integer. The Outer StringMap would use the NPC names as the indexes and the elements would be further StringMaps with name value pairs as the indexes. For example:

 

 

Outer StringMap

 

Index-------------------------Value

Bob NPC-------------------StringMap

Ted NPC-------------------StringMap

Mary NPC------------------StringMap

Alice NPC------------------StringMap

 

An example of an inner StringMap for Bob

 

Index-------------------------Value

NPCName-----------------Bob NPC

NPCLevel------------------12

NPCHealth----------------100

 

 

 

This would then be a global value or a quest variable (I'd go with a quest variable). If you quest was named MyNPCValues and your outer StringMap named MyNPCs you'd access the StringMap for your NPC with something like MyNPCValues.MyNPCs["Bob NPC"] which would return the inner StringMap for Bob.

Edited by Astymma
Link to comment
Share on other sites

  • Recently Browsing   0 members

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