Papyrus Spell help

Post » Tue Jun 19, 2012 8:13 pm

Okay, I'm trying to make a really cool necklace that, when equipped, gives you a spell. Unequipping removes the spell.

Aaaand that's my problem. I'm tired of searching the CreationKit.com site for the functions, as they are usually the console commands.
Just... answer me this:

Is "Game.GetPlayer().addSpell(chargeSpell)" the Papyrus equivalent for "player.addspell chargeSpell" on the console?

and...

How do you see if a target (ex. the Player) knows a spell, but doesn't neccessarily have to have it equipped?

Thanks,
~L
User avatar
Naazhe Perezz
 
Posts: 3393
Joined: Sat Aug 19, 2006 6:14 am

Post » Tue Jun 19, 2012 10:51 pm

From what I understand (which isn't much btw) you have to treat papyrus commands as a completely different beast than console commands. Some things are similar, but it might cause you trouble in the future.

But as for code

Assuming Player is your actor with type actor
and Spell is your spell with type Spell

Event OnEquipped(Actor akActor)	if !Player.hasSpell(Spell) ;if player doesn't have spell		Player.addSpell(Spell);add the spell	endIfendEventEvent OnUnequipped(Actor akActor)	 Player.removeSpell(Spell)  ;Removes spell on UnequipendEvent

You could add a variable to it, so that if the player knew the spell beforehand, it woudn't remove the spell on unequip.
Also my typing is awful so I may have miss typed something.
User avatar
jadie kell
 
Posts: 3497
Joined: Sat Jul 29, 2006 3:54 pm

Post » Tue Jun 19, 2012 5:01 pm

The best way, I find, of looking for Papyrus' native functions on the Creation Kit Wiki is using the http://www.creationkit.com/Category:Papyrus page.

From what I understand (which isn't much btw) you have to treat papyrus commands as a completely different beast than console commands.
That's completely correct - Papyrus and the console are entirely separate systems that neither share any code nor talk with one another.

You script looks good as well, although if you want to use that you'd need a variable or property called "Player" that's used to store the player as an http://www.creationkit.com/Actor_Script, as you mentioned in that comment. That script also makes the assumption that the spell is only accessible via the necklace. If it's a spell that can be obtained in other ways, then the necklace might remove a spell that the player already hand. It seems a fairly safe bet that that won't be a problem in this case, though.

Cipscis
User avatar
Leah
 
Posts: 3358
Joined: Wed Nov 01, 2006 3:11 pm

Post » Tue Jun 19, 2012 11:26 pm

Yeah for example,

int Property has = 0 autoEvent OnEquipped(Actor akActor)	    if !Player.hasSpell(Spell) ;if player doesn't have spell			    Player.addSpell(Spell);add the spell	    else			    has=1 ; if the player already has the spell	    endIfendEventEvent OnUnequipped(Actor akActor)		 if has == 1 ;if the player already had the spell (this was set in onEquipped)			    Player.removeSpell(Spell)  ;Removes spell on Unequip		 endIfendEvent

this is if you want to have it if the player already had the spell, don't remove it.
User avatar
Patrick Gordon
 
Posts: 3366
Joined: Thu May 31, 2007 5:38 am

Post » Tue Jun 19, 2012 11:52 pm

Because we have a proper "bool" type in Papyrus, it would be a little bit more semantically correct to use that type, but that example would still do the trick. As a worst case scenario, there's still the possibility that the player could learn the spell with the item equipped, but that's a pretty hard problem to solve. If that's a legitimate worry for this case, it'd probably be best just to make a new spell instead of using an existing one.

Cipscis
User avatar
Jeremy Kenney
 
Posts: 3293
Joined: Sun Aug 05, 2007 5:36 pm

Post » Tue Jun 19, 2012 12:18 pm

Yeah for example,

int Property has = 0 autoEvent OnEquipped(Actor akActor)		if !Player.hasSpell(Spell) ;if player doesn't have spell				Player.addSpell(Spell);add the spell		else				has=1 ; if the player already has the spell		endIfendEventEvent OnUnequipped(Actor akActor)		 if has == 1 ;if the player already had the spell (this was set in onEquipped)				Player.removeSpell(Spell)  ;Removes spell on Unequip		 endIfendEvent

this is if you want to have it if the player already had the spell, don't remove it.

Except you better do a RegisterForUpdate or that variable you set on the equip event will be reset by the time the Unequip event comes along...at least that's been my experience in Papyrus. Like

RegisterForUpdate(1000) ; In the equip
UnRegisterForUpdate() ; In the Unequip.
User avatar
Je suis
 
Posts: 3350
Joined: Sat Mar 17, 2007 7:44 pm

Post » Wed Jun 20, 2012 1:08 am

But those scripts add the spell to the player if ANY actor equips the item. This script adds the spell to the actor that equipped the item, which may or may not be the player:

int Property has = 0 autoEvent OnEquipped(Actor akActor)		    if !akActor.hasSpell(Spell) ;if actor doesn't have spell						    akActor.addSpell(Spell) ;add the spell		    else						    has=1 ;if the actor already has the spell		    endIfendEventEvent OnUnequipped(Actor akActor)				 if has == 1 ;if the actor already had the spell (this was set in onEquipped)						    akActor.removeSpell(Spell)  ;Removes spell on Unequip				 endIfendEvent

Man, there are so many other tweaks I want to make to this script, but this change will prevent the player having the spell when they give the item to their companion and the companion equips it.
User avatar
Jessica Nash
 
Posts: 3424
Joined: Tue Dec 19, 2006 10:18 pm

Post » Tue Jun 19, 2012 9:48 pm

Sorry... I haven't done ANY papyrus scripting yet, but from my programming experience, I think there is an error in the OnUnequipped function.

Since we set has=1 when the player already has the spell, we want to make sure we only want to remove the spell when has is not 1. Thus, shouldn't it be as follows?

bool Property alreadyHasSpell = false autoEvent OnEquipped(Actor akActor)   if !akActor.hasSpell(Spell) ;if actor doesn't have spell	  akActor.addSpell(Spell) ;add the spell   else	  alreadyHasSpell=true ;if the actor already has the spell   endIfendEventEvent OnUnequipped(Actor akActor)   if !alreadyHasSpell  ;if the actor didn't already have the spell remove it (this was set in onEquipped)	  akActor.removeSpell(Spell)  ;Removes spell   endIfendEvent

Edited after reading several comments about using bools instead of ints (Like the one from Redwood Elf below). Also changed variable name to make it more human-readable. Hope there are no variable naming limits!

(Edit 2 - Simplified "alreadyHasSpell == false" to "!alreadyHasSpell") Thanks Redwood Elf
User avatar
Bethany Short
 
Posts: 3450
Joined: Fri Jul 14, 2006 11:47 am

Post » Tue Jun 19, 2012 9:35 am

Personally, I'd have used a Bool variable instead of an int (Kids these days and their "I have 4GB of Memory, I don't have to pinch pennies on my variable types"), but I believe you are correct, sir.
User avatar
jeremey wisor
 
Posts: 3458
Joined: Mon Oct 22, 2007 5:30 pm

Post » Tue Jun 19, 2012 5:34 pm

Personally, I'd have used a Bool variable instead of an int (Kids these days and their "I have 4GB of Memory, I don't have to pinch pennies on my variable types"), but I believe you are correct, sir.

Edited the code above to use the proper variable type... I'm sad that I'm probably still wasting at least 7 bits :(
User avatar
Lilit Ager
 
Posts: 3444
Joined: Thu Nov 23, 2006 9:06 pm

Post » Tue Jun 19, 2012 7:57 pm

Edited the code above to use the proper variable type... I'm sad that I'm probably still wasting at least 7 bits :(

Never http://en.wikipedia.org/wiki/Nibble your http://tvtropes.org/pmwiki/pmwiki.php/Main/IncrediblyLamePun

Oh, and you don't need to compare alreadyHasSpell to false, "if !alreadyHasSpell" will work fine.
User avatar
OnlyDumazzapplyhere
 
Posts: 3445
Joined: Wed Jan 24, 2007 12:43 am

Post » Tue Jun 19, 2012 10:30 pm

Never Nibble your Bytes!

Oh, and you don't need to compare alreadyHasSpell to false, "if !alreadyHasSpell" will work fine.

Can't I even do it a little bit?

I'm trying not to assume too much about the syntax of Papyrus... I'm just a C/C++ geek that likes reading code... Thanks for the clean-up help!
User avatar
Dan Wright
 
Posts: 3308
Joined: Mon Jul 16, 2007 8:40 am

Post » Tue Jun 19, 2012 11:17 am

Thanks, guys! This has helped me out a lot!

I guess I should say what it's for...

The script is for a cool necklace that you can charge via a spell. The spell charges the necklace 5 points per second, while damaging your life by the same amount. This is for the neckalces 'special ability', which I call 'Resilience'. It will make it so when your life is below 20%, the necklace is equipped, and if the necklace has some charge, then it will heal you by that amount, and reset the charge to zero. Obviously, this means that overcharging is useless.

Also, when I get THIS working, I'll be doing the same for Magicka and Stamina necklaces as well. (But those necklaces only activate when the respective stat reaches zero, not 20%.)

Anyways, thanks! I've got the rest done, I just need to get started on an updating function that checks your current and max health/magicka/stamina.
User avatar
Emily Shackleton
 
Posts: 3535
Joined: Sun Feb 11, 2007 12:36 am

Post » Tue Jun 19, 2012 10:19 pm

Always happy to help.

That sounds like a pretty cool, but not TOO overpowering item. I like that they are all necklaces, forcing the player to choose!
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Tue Jun 19, 2012 6:41 pm

Exactly. Of course, there is the risk of the script breaking, and that may not be bad unless it's with the spell (infinitely hurting you, and restoring your life once it reaches below 20%. That happened the first time I made the necklace, and thus I've had to restart the project from scratch.).

Also, I was thinking that I'd need somebody to retexturize a necklace to make it fit, and I can just barely draw a square, on the computer and on paper. (Sad part? I'm only exaggerating by a little.)

Oh! I've also made up some names:

Life necklace: Pheonix Amulet (spell is called "Life Charge", special ability is called "Resiliance")
Magicka necklace: Drake Amulet (named after an older name for water dragons) (spell is called "Magicka Charge", special ability is called "Focus")
Stamina necklace: Gryphon Amulet (spell is called "Stamina Charge", special ability is called "Hype")

Phew. Names are a drag.

Thanks, guys!
~L
User avatar
sas
 
Posts: 3435
Joined: Thu Aug 03, 2006 8:40 am


Return to V - Skyrim