Player.RemoveSpell() Not Working

Post » Tue Jun 19, 2012 7:11 am

I have the following code:

Spoiler
Scriptname SIMSChooseConjuration extends activemagiceffectMessage Property MyMessage AutoSpell Property Familiar AutoSpell Property Skeleton AutoSpell Property RaiseDead AutoSpell Property BoundSword AutoSpell Property this AutoActor playerevent OnEffectStart(actor target, actor caster);menu code goes here;something likeplayer = Game.GetPlayer()if caster == playerint res;int choicewhile res != 5 ;im assuming your third button is the one you want to stop onres = MyMessage.show()if res == 0player.addSpell(Familiar)player.unequipSpell(this, 0)player.removeSpell(this)res = 5elseif res == 1player.addSpell(Skeleton)player.unequipSpell(this, 0)player.removeSpell(this)res = 5elseif res == 2player.addSpell(RaiseDead)player.unequipSpell(this, 0)player.removeSpell(this)res = 5elseif res == 3player.addSpell(BoundSword)player.unequipSpell(this, 0)player.removeSpell(this)res = 5elseif res == 4res = 5endifUtility.wait(0.8)endwhileendifendevent

But the spell doesn't get removed from the player's inventory. Everything else works. Any ideas??

If not I'll just change it an object and have the player equip that.

EDIT: No idea why it isn't formatting properly.
User avatar
Cat Haines
 
Posts: 3385
Joined: Fri Oct 27, 2006 9:27 am

Post » Tue Jun 19, 2012 7:21 am

player.removeSpell(this)

It's probably because of the ''this''. Because the script is attached to a magic effect, the ''this'' refers to the magic effect and not the spell. Instead you should try:

player.removeSpell(player.getEquippedSpell(hand))

Now the only problem with that is that you don't know in which hand the player has the spell equipped.. so would probably need to use player.GetEquippedItemType(hand) once for each hand to see whether he has spells equipped or something... and maybe require more checks to see whether he has the correct spell equipped, not sure.
User avatar
Chase McAbee
 
Posts: 3315
Joined: Sat Sep 08, 2007 5:59 am

Post » Mon Jun 18, 2012 11:33 pm

But the spell doesn't get removed from the player's inventory. Everything else works. Any ideas??

If not I'll just change it an object and have the player equip that.

EDIT: No idea why it isn't formatting properly.
You connected the property `this` to whatever spell you are wanting to remove? I don't see anywhere in the code that it is being set so maybe you should verify the value of it with a debug message. Also it looks like you want to break out of the menu no matter what the user picks. You can just comment out the while and endwhile lines to achieve the same effect.
User avatar
Alyna
 
Posts: 3412
Joined: Wed Aug 30, 2006 4:54 am

Post » Mon Jun 18, 2012 9:22 pm

Near the start of the code (line 8)

Spell Property this Auto
And thanks for the tip about the while loop. I had problems with it showing up before without a while loop but I'll give it a go :D.
User avatar
Camden Unglesbee
 
Posts: 3467
Joined: Wed Aug 15, 2007 8:30 am

Post » Tue Jun 19, 2012 2:16 am

Near the start of the code (line 8)

Spell Property this Auto
And thanks for the tip about the while loop. I had problems with it showing up before without a while loop but I'll give it a go :biggrin:.
Yes but this only declares a property for the script. You have to give that property a value by connecting it to the spell you want in the CK. Right now it's basically an allocated empty spell. The tutorial has nice pictures of how to do this: http://www.creationkit.com/Bethesda_Tutorial_Papyrus_Introduction_to_Properties_and_Functions#Properties
User avatar
Brian Newman
 
Posts: 3466
Joined: Tue Oct 16, 2007 3:36 pm

Post » Tue Jun 19, 2012 7:34 am

I have connected that to a spell, but perhaps the problem is the spell I am trying to remove is the one the player is casting? The lines that unequip the spell work, but the spell stays in the inventory.
User avatar
Brad Johnson
 
Posts: 3361
Joined: Thu May 24, 2007 7:19 pm

Post » Tue Jun 19, 2012 3:43 am

Ah never mind my initial reply, was confused with programming languages like Java where ''this'' is a reserved word :P Not sure why it doesn't work then :(
User avatar
Crystal Clarke
 
Posts: 3410
Joined: Mon Dec 11, 2006 5:55 am

Post » Tue Jun 19, 2012 7:57 am

I have connected that to a spell, but perhaps the problem is the spell I am trying to remove is the one the player is casting? The lines that unequip the spell work, but the spell stays in the inventory.
Ah that is a possibility then.. Maybe you could use a scroll? It would destroy itself after casting :)

Try
Event OnEffectEnd()  player.removespell(this)EndEvent
User avatar
Julie Serebrekoff
 
Posts: 3359
Joined: Sun Dec 24, 2006 4:41 am

Post » Mon Jun 18, 2012 9:18 pm

Ah never mind my initial reply, was confused with programming languages like Java where ''this'' is a reserved word :P Not sure why it doesn't work then :(

Yeah I program in java too and I thought it would be the same (until I realised the magiceffect is not the spell that needs to be removed)
User avatar
Solina971
 
Posts: 3421
Joined: Thu Mar 29, 2007 6:40 am

Post » Mon Jun 18, 2012 8:46 pm


Ah that is a possibility then.. Maybe you could use a scroll? It would destroy itself after casting :)

Try
Event OnEffectEnd()  player.removespell(this)EndEvent

Good idea on the scroll front, that should solve it. I also tried the OnEffectEnd but that didn't work. Scroll it is :D.
User avatar
Hella Beast
 
Posts: 3434
Joined: Mon Jul 16, 2007 2:50 am

Post » Mon Jun 18, 2012 5:55 pm

I actually havnt gotten removespell to work either for some reason, I just use duractions for spells that need to be removed.
User avatar
Lexy Dick
 
Posts: 3459
Joined: Mon Feb 12, 2007 12:15 pm

Post » Mon Jun 18, 2012 10:59 pm

I do know that the Papyrus version of AddPerk() simply refuses to work for adding perks to anything other than the player. So I wouldn't be surprised if other functions also fail to work as expected in some cases. Maybe that's the case with RemoveSpell().
User avatar
N Only WhiTe girl
 
Posts: 3353
Joined: Mon Oct 30, 2006 2:30 pm

Post » Tue Jun 19, 2012 2:44 am

What hand do you have the spell equipped to?

You're unequipping from 0. That's only the left hand. If it's possible to equip the spell on either hand, you could also try adding a unequipspell(this, 1) to your code.
User avatar
Bereket Fekadu
 
Posts: 3421
Joined: Thu Jul 12, 2007 10:41 pm

Post » Mon Jun 18, 2012 11:24 pm

The unequip bit worked (as it was equipped in the left hand), it's just trying to remove the spell didn't work.
User avatar
Cool Man Sam
 
Posts: 3392
Joined: Thu May 10, 2007 1:19 pm


Return to V - Skyrim