FrederickI Posted December 26, 2011 Share Posted December 26, 2011 I'm working on a mod to automatically add certain items every adventurer should have - like lockpicks, repair hammers, or arrows - to the player's inventory as needed, at a cost in magicka. At present, the main scripting for this is as a spell effect; in a ScriptEffectUpdate block, it checks whether the player has enough of each item and, if not, adds one and subtracts some magicka; the code for this is mostly the same as for the bound arrows in Supreme Magicka (found somewhere in the middle of zzSMAreaTokenSystemScript). In testing, this has worked well, but requires that my mod require whatever mod(s) these items come from. This is not a problem so long as every item comes from Oblivion.esm. However, my goal is to have the items customizable in an ini file, and for the player to be able to put into the ini file items from any mod he or she might have. My spell script loads the ini file with OBSE's RunBatchScript command. The ini file so far contains one line: "set itemRef to a", which I expect to set the variable itemRef (a ref variable declared in my script) to refer to the lockpick (whose FormID is 0000000a). In the script, the following appears:Begin ScriptEffectUpdate set itemCount to player.getItemCount itemRef If itemCount < 5 player.addItem itemRef 1 EndIf Endin addition to a ScriptEffectStart block with the RunBatchScript call. The only variables in the script so far are "short itemCount" and "ref itemRef". This gets me no results - if I drop all my lockpicks, nothing gets added to my inventory when the script effect is running. I get a similar non-result if the ini file reads "set itemRef to lockpick" (the EditorID for a lockpick is also lockpick). Is what I'm trying doable? Will I have to implement this as a quest instead? I can post the full text of the script or even the .esp this is in if you need more information. Though this isn't my first Oblivion mod, this my first project that takes any scripting, so any help is appreciated. I'm also trying to think of a good way to determine the magicka cost of an item. Some items duplicate existing magic (so a potion should cost at least as much as its effect would as a spell, for example), but others are more tenuous (what magnitude of Open spell does a lockpick match?) and many items, such as repair hammers, have no magickal equivalent at all. Let's ignore for the moment that the items this produces could be sold (exchanging temporary magicka for permanent gold). tl;dr: How to I specify an item (by FormID or by EditorID) from an ini file? Link to comment Share on other sites More sharing options...
Septfox Posted December 26, 2011 Share Posted December 26, 2011 The problem, I think, is that declared references are local only, just like declared variables. So running a batch script won't do anything, since the script commands are run through the console where you can't declare anything. What you could do is attach the script to a quest that runs for a single script pass when the spell is used. The batch script can modify variables/references in that (the format for setting quest variables/references/strings/etc being questname.variablename). I don't think there's any way to modify variables or references remotely for object or magic scripts; only quests. So to recap, you'd have:The magic effect script, which runs once when it's cast and has nothing but the startquest command in itThe quest that houses the main scriptThe main script, which runs runbatchscript at the very start to set all the references, followed by the list of references to add to the player's inventory, ended with the script calling stopquest The only problem I can really see is that you'd have to declare as many references as you expect the player to set. The good thing though, is if they don't use ALL the entries available to them, the game should simply ignore the lines for those references (since they're empty initially). Also, you can use the editorID to add items via a script. It's only the console that forces you to use formIDs. Link to comment Share on other sites More sharing options...
FrederickI Posted December 26, 2011 Author Share Posted December 26, 2011 (edited) Thanks. I implemented it with a quest, and now it works. The spell the player casts is a toggle (with either a startquest or a stopquest depending on whether the quest is running already) and the quest loads from the ini file the first time it runs and then periodically checks if the player needs a new item. Currently, the quest script uses a ref and some shorts to keep track of each item, but I might use OBSE arrays instead to be more flexible. Edit: This only seems to work for items whose formid starts with a letter. Lockpick (formid "a") and pewter mug ("fda4") work, but cloth ("87a") and welkynd stone ("191") don't. When I ask the game to print the ref variables to the console, unused variables and those with letters in them (lockpicks, cloth, etc.) show as "0.0000" but the welkynd stone shows as "191.0000" - as though the game had read it as a short or float, not a ref. Edited December 26, 2011 by Frederick_I Link to comment Share on other sites More sharing options...
Septfox Posted December 26, 2011 Share Posted December 26, 2011 That's a bit odd. You could try entering the whole thing, I suppose (0000087a rather than 87a), but chances are it's going to screw up anyway...hrm. Just use, and encourage use of, editorIDs instead of formIDs. Not only are they easier to keep track of, what with generally having meaningful names instead of random numbers, potential users don't have to worry about determining their item's position in the load order or constantly update the ini as they load order changes. FormIDs for non-base items will always require all eight digits, with the first two being the load order offset. Link to comment Share on other sites More sharing options...
FrederickI Posted December 27, 2011 Author Share Posted December 27, 2011 I tested the leading zeros, but as you suspected that didn't work. EditorIDs don't work, because RunBatchScript is the same as putting the file through the console manually. I though I might be able to force the game to treat the value as a ref instead of a number, but I don't see anything that could do that on the Construction Set wiki's list of functions. Link to comment Share on other sites More sharing options...
nosisab Posted December 27, 2011 Share Posted December 27, 2011 (edited) Well, the additem command works only for base objects (BaseID) and not for references (RefID), this makes sense since you are using the Base ID as template to create the amount of objects being added to the game and each one receives a proper RefID from the engine on time. The same for the removeitem which removes the provided amount of items from the container (in this case, the player), so you can't specify which item from the lot is removed. On the other hand, to deal with actually placed items in game you should use the enable/disable commands which acts on the RefID, I mean over "that specific copy" of certain item in game. PS: an extra problem occurs if the item is defined on a mod, since in this case it is prefixed (the two first hexadecimal digits) second the mod's position at the load order. For example, if the item comes from a mod that is placed 5th counting Oblivion.esm (which is always 00) the mod, and then the item, is prefixed as 04 (hex) so if the baseID shown in CS is f452 (for example) the item should be referenced in game as 0400f452 or 400f452. Just to make sure the hex part, if the mod is the 11th it is prefixed as 0A, that prefix is shown directly on OBMM if you use it. Anyway the actual prefix is one less than the mod position because the count begins at 0 instead 1. Observation, from the above becomes clear that any item from mod input into the ini becomes invalidated whenever the mod position at the load order is changed. I believe OBSE has functions to retrieve the mod prefix but I never used it and can't tell from memory just now. Still, for your mod to be independent of another mod position, the ini must provide the information so the actual mod the item comes from can be verified on the fly before mounting the string to be used at the additem command. Edited December 27, 2011 by nosisab Link to comment Share on other sites More sharing options...
Septfox Posted December 27, 2011 Share Posted December 27, 2011 ...eh? AddItem has no problems working with refIDs, if it did then a good quarter of the mods on the Nexus wouldn't work.This:ref item1ref set item1ref to lockpick player.additem item1ref 1Works perfectly fine.Though it might be that I'm misunderstanding and/or mixing up terms. Haven't been to bed yet, just got done with an 8-hour streak of Borderlands. Anyway, the problem is that you can't affect refIDs from the console (though other variables types do work). So...don't use the console. "Wot," you say, "I should just give it up then?". No, of course not, that would be silly. Oblivion WILL bend to your will, whether it bloody well likes it or not.*clears throat*Pluggy was apparently made, at least partially, to provide modders with the ability to make proper inis. I'm not sure how functional it is for your purpose, though, and I'm too sleepy to try writing up a script using it. Maybe in the morning. Link to comment Share on other sites More sharing options...
Recommended Posts