irfna Posted April 19, 2011 Share Posted April 19, 2011 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 More sharing options...
David Brasher Posted April 19, 2011 Share Posted April 19, 2011 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.AANPCStatNOTAAJabberwocky.AANPCStat Link to comment Share on other sites More sharing options...
irfna Posted April 20, 2011 Author Share Posted April 20, 2011 (edited) 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 April 20, 2011 by irfna Link to comment Share on other sites More sharing options...
Astymma Posted April 20, 2011 Share Posted April 20, 2011 (edited) 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-------------------------ValueBob NPC-------------------StringMapTed NPC-------------------StringMapMary NPC------------------StringMapAlice NPC------------------StringMap An example of an inner StringMap for Bob Index-------------------------ValueNPCName-----------------Bob NPCNPCLevel------------------12NPCHealth----------------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 April 20, 2011 by Astymma Link to comment Share on other sites More sharing options...
Recommended Posts