DixiePig Posted March 1, 2016 Share Posted March 1, 2016 How can I attach a variable to an NPC and then have a spell script get or modify it? My main goal here is to understand how scripts interact with each other and the game. Here's a simple example of how I might use it: A firebolt spell that, every time it hits an actor, increments an int timesHit. It then checks if timesHit >= 3, and if true it creates an explosion, and sets timesHit = 0. Questions:Does timesHit have to be declared somewhere independently from the magic effect script? How it is accessed by the magic effect script?How to make it go away when no longer needed (timesHit = 0, actor dies, combat ends)? What to be aware of to prevent savegame bloat?Any help, advice, or tips would be greatly appreciated. Link to comment Share on other sites More sharing options...
Revylrie Posted March 1, 2016 Share Posted March 1, 2016 The easiest way to accomplish this would be to use a dummied actor value to "store" the timesHit variable. (Of course, this may result in incompatibility with mods that edit the same value.) For the sake of demonstration, let's say that this AV is Fame, which, fortunately, is set to 0 by default in vanilla Skyrim. You'd then want your script to look something like this: Scriptname SuperSpecialAwesomeFireboltExplosionModThingy extends ActiveMagicEffect Event OnEffectStart(Actor Target, Actor Caster) If Target.IsDead() == 0If Target.GetAV("Fame") < 3Target.ModAV("Fame", 1)EndIf If Target.GetAV("Fame") >= 3Target.AddSpell (Kablooie)Target.SetAV("Fame", 0)EndIfEndIfEndEvent With "SuperSpecialAwesomeFireboltExplosionModThingy" being whatever you want to call your script and "Kablooie" being an explosion magic effect centered on the target. (Although I'm not sure magic effects work like that. I'm just giving a proof-of-concept example.) Does that help? Link to comment Share on other sites More sharing options...
DixiePig Posted March 1, 2016 Author Share Posted March 1, 2016 It does help. Thank you for the reply.This works for my example, which uses an int. Floats, bools, or strings might be found in actor values (don't know what's available) but if I want to do something more complex (like something that requires more than a few variables) then this won't work.Want I specifically want to understand is how scripts can interact, like accessing the variable values of other script instances. Your solution addresses the example but not the question, unless of course the answer to the question is "you can't.", in which case that's the exact answer I need.Thanks again for the info, I appreciate it very much. Any further info would also be very welcome. Link to comment Share on other sites More sharing options...
Revylrie Posted March 1, 2016 Share Posted March 1, 2016 (edited) I wouldn't go so far as to say "you can't" - in the words of Farengar Secret-Fire, "one sure mark of a fool is to dismiss anything that falls outside his experience as being impossible" - but you're right that you wouldn't be able to call and update integer timesHit within the same script in the example you gave because the script is only supposed to run once every time the custom firebolt spell is cast. I know for a fact that you can use actor values to store integer values (more accurately, floats - actor values have decimal places) and call the information you're looking for, but what I don't know is whether you could use additional scripts to accomplish the same. (I would assume not.) Edited March 1, 2016 by Revylrie Link to comment Share on other sites More sharing options...
DixiePig Posted March 1, 2016 Author Share Posted March 1, 2016 (edited) I wouldn't go so far as to say "you can't" - in the words of Farengar Secret-Fire, "one sure mark of a fool is to dismiss anything that falls outside his experience as being impossible" - but you're right that you wouldn't be able to call and update integer timesHit within the same script in the example you gave because the script is only supposed to run once every time the custom firebolt spell is cast. I know for a fact that you can use actor values to store integer values (more accurately, floats - actor values have decimal places) and call the information you're looking for, but what I don't know is whether you could use additional scripts to accomplish the same. (I would assume not.) Do scripts have public variables / functions? Say the newFireBolt spell script had a public "int getTimesHit()" function. Upon the spell hitting an actor, could the script scan through the active magic effects on that actor for any instances of itself, call getTimesHit(), copy the result + 1 to its own timesHit value, and then dispel that previous instance? I've just been looking through the papyrus APl and there are only 17 obsolete actor value floats I can use. I would prefer not to have a 1/17 chance of breaking someone's game per float per scripted mod they have installed. Edit: Also, thanks for the input. Edited March 1, 2016 by DixiePig Link to comment Share on other sites More sharing options...
Revylrie Posted March 1, 2016 Share Posted March 1, 2016 (edited) Let me put it this way: If it were/is possible to do what you describe, then mod authors wouldn't need to use the obsolete actor values, and that would be good news indeed for me and my own custom spells mod. Edited March 1, 2016 by Revylrie Link to comment Share on other sites More sharing options...
Terra Nova Posted March 1, 2016 Share Posted March 1, 2016 Not possible because ActiveMagicEffects are removed too quickly to track them. Link to comment Share on other sites More sharing options...
DixiePig Posted March 1, 2016 Author Share Posted March 1, 2016 Right. I'll see what I can accomplish with just the Actor variable floats.Thank you both for your help.Any tips in the interest of minimizing conflicts? Link to comment Share on other sites More sharing options...
Terra Nova Posted March 1, 2016 Share Posted March 1, 2016 This would require testing, but you could get all of their return values and if any of them isn't default, then a mod has edited it? Link to comment Share on other sites More sharing options...
sLoPpYdOtBiGhOlE Posted March 2, 2016 Share Posted March 2, 2016 You could use a Faction rank. eg: When the effect starts, check if the target is in your HitCount faction, if not then add them Use set and get faction rank as a count. Not as neat as using unused AV's, but you won't end up in conflict with other mods that may be editing those same actor values. Link to comment Share on other sites More sharing options...
Recommended Posts