YourUnequal Posted June 9, 2013 Share Posted June 9, 2013 Okay, it should be one of the easiest things to do and I've done this plenty of times before, so why it's not working this time around is starting to bug me (no pun intended...okay, it was, really). All the attached script needs to do is add a spell to the player's spellbook whilst it is equipped; once the item in question (this time it's a ring) is removed, the player 'forgets' the spell. As I said, I've done this same thing for other pieces of jewellery and it's worked fine (hence the generic name I game to the script). The code I'm using is as follows: Scriptname ApplySpellOnEquipScript extends ObjectReference Spell Property SpellToApply auto Event OnEquipped(Actor akActor) if akActor == Game.GetPlayer() Game.GetPlayer().AddSpell(SpellToApply, abVerbose = true) endif EndEvent Event OnUnEquipped(Actor akActor) if akActor == Game.GetPlayer() Game.GetPlayer().RemoveSpell(SpellToApply) endif EndEvent SpellToApply has been assigned a spell and I have tested the spell itself by inserting it into the game via a tome; the spell itself works fine and it appears in the spellbook under the right category (Conjuration); interestingly enough, if I learn the spell from the tome with the ring equipped, then unequip the ring, the spell stays there, which suggests the script is not being called on at all for some reason. I have tried multiple variations of the .AddSpell() and .RemoveSpell() functions, including omitting the 'if' statements and replacing Game.GetPlayer() with akActor so as to make it apply to any character which equips the object, but to no avail. If I've missed something obvious please do not hesitate to be cynical, as I'm not used to such few lines of code not playing ball :ermm: . Thanks in advance,Your Unequal Link to comment Share on other sites More sharing options...
IsharaMeradin Posted June 9, 2013 Share Posted June 9, 2013 Just gonna throw out some things that you could try. No idea if they'll help or not.The default value for abVerbose for the AddSpell function is true. Try dropping it.Use a property for the PlayerRef instead of using Game.GetPlayer(). It is quicker in the processing. Your script with the changes Scriptname ApplySpellOnEquipScript extends ObjectReference Spell Property SpellToApply auto Actor Property PlayerRef Auto Event OnEquipped(Actor akActor) if akActor == PlayerRef akActor.AddSpell(SpellToApply) endif EndEvent Event OnUnEquipped(Actor akActor) if akActor == PlayerRef akActor.RemoveSpell(SpellToApply) endif EndEvent I always found it pointless to grab a variable in the event, compare it to something else and then use that something else instead of the variable when the point of the check is to ensure that the variable matched the something else. Hence I placed akActor instead of using PlayerRef or Game.GetPlayer() directly. Link to comment Share on other sites More sharing options...
YourUnequal Posted June 9, 2013 Author Share Posted June 9, 2013 I've had a look at the website but I can't seem to find part of a tutorial which helps for this particular problem; I did find some useful things about skin tones on bespoke NPCs though for some other stuff I'm working on :happy:. Link to comment Share on other sites More sharing options...
YourUnequal Posted June 10, 2013 Author Share Posted June 10, 2013 Alright, I'll give that a go; thanks. Link to comment Share on other sites More sharing options...
Recommended Posts