Papyrus - OnEquipped Example - I think

Post » Sun Jun 17, 2012 1:39 pm

Just incase anyone wants a head start on how to write a simple Papyrus onEquipped script.


Go into your Item (an Amulet for instance)

Down in the right corner, there is a scripts window
Click Add
Double Click on [New Script]
Now you get a window, which allows you to name the script.
Dont worry about the Extends ObjectReference bit yet - I think this basically tells you what sort of object you will be working with or something?

Name your script, and click ok.


It probably just closed the Script window, and your like?
What???

It has created the script file, now you need to create the Input arguments that will be used within the script.

You do this via double clicking on the script in the same script window,
then Add Property
A window will appear where you can select the 'type' of property.
Which pretty much means, any of the data types available in Skyrim.
Int values, string values ,as well as spells, items, weather etc....

If for example, you want to add a spell to a player when they equip the item, you would set the Property to be 'Spell'
Name it something like MyLittleSpell
(this is just the name of the variable, not the name of the spell itself)
Dont worry about the initial value, as it tends to stay as a text box for the time being.
Close the window, after having made your spell property.
Now, if you select the property you just made, you will be able to select 'Edit Property' or 'Set Value'

When you do that, a Context sensitive dropdown can appear, which lists all of the spells in the Game (in your mod).
You can then select the spell, and click ok.

So...
That is the 'PRE' script work done.

You have told the script what spell to use..
Now you need to tell it how to use it...

This is the bit im not too sure on...
Correct me if needed.

* Right Click on the script in the window, and select Edit Source
* Compile it once you are finished with your script

Scriptname BaaleosOnEquip extends ObjectReference
Spell Property EyesProperty auto <----- This is your property that you made. it appears in your script like this. Yours would be named MyLittleSpell
 
Event OnEquipped(Actor AkActor)
Game.GetPlayer().AddSpell(EyesProperty) <------ You can see, that we are feeding in EyesProperty (the spell) into the AddSpell function.
EndEvent
 
 
Event OnUnequipped(Actor AkActor)
Game.GetPlayer().RemoveSpell(EyesProperty) <------- The same with the RemoveSpell function
EndEvent




Anyway..
Compile your script, close the item, save your mod, and load up skyrim, and equip your item, and hopfully, your OnEquip script will fire.


Pro's and Con's with the new Scripting system

Alot of advanced scripters like being able to dive in and get their hands dirty with textual editing of the script, while that is still there via 'Right Click and Edit Source', the method of adding arguments and such, seems a little complicated.
Infact, I dont know how to reference a Spell in the script, without adding it as a propert first?
I liked it when you could simply type in the editor ref..... I dont know if you can do that anymore?


Anyhow... Hope this example helps people.
User avatar
maya papps
 
Posts: 3468
Joined: Mon Aug 07, 2006 3:44 pm

Post » Sun Jun 17, 2012 11:49 am

Haven't worked with or seen any Papyrus, but I'd bet "extends" means your (in object-oriented terms) subclassing an existing type (more likely including a protocol). In this case, a reference to an object. How general an "Object" is I have no idea.
User avatar
Emily Jones
 
Posts: 3425
Joined: Mon Jul 17, 2006 3:33 pm

Post » Sun Jun 17, 2012 10:23 pm

Yeah, it essentially defines what the object type we are working with, and thus what events and methods are available to use within that object.

eg - OnEquipped and OnActivate seem to exist for items?
User avatar
Mrs Pooh
 
Posts: 3340
Joined: Wed Oct 24, 2007 7:30 pm

Post » Mon Jun 18, 2012 12:44 am

Nice!

Any idea how to get something working that has the same functionality as weapon scripts from past games?

They're entirely useless now. (not just saying that, Bethesda doesn't have a single weapon base form with a script attached to it)

In past games, having a script on a weapon would generally mean that script would run on the target actor when hit, and I see absolutely no way of doing this anymore short of putting a script on every actor that detects when it has been hit by the weapon you wanted to have that script effect.
User avatar
Oyuki Manson Lavey
 
Posts: 3438
Joined: Mon Aug 28, 2006 2:47 am

Post » Sun Jun 17, 2012 6:24 pm

It's probably better to think of it as extending, really. Each type of form (for example, Actor) has a script that already exists (for example, the "Actor" script), and the game ensures that these scripts are always attached to each of those forms, although you won't see it in the scripts tab in their dialogue window in the editor.

For the most part, these scripts define the events and other functions, mostly native, available to forms of the appropriate type.

Also, you should edit your examples to use "AkActor" instead of Game.GetPlayer(), otherwise having non-player actors equipping or unequipping the scripted item would cause the player to be affected.

Cipscis
User avatar
MISS KEEP UR
 
Posts: 3384
Joined: Sat Aug 26, 2006 6:26 am

Post » Sun Jun 17, 2012 12:20 pm

To create a scripted weapon effect you'll probably want to create an enchantment that applies an http://www.creationkit.com/ActiveMagicEffect_Scriptto the target.
User avatar
asako
 
Posts: 3296
Joined: Wed Oct 04, 2006 7:16 am

Post » Mon Jun 18, 2012 2:48 am

http://www.creationkit.com/OnHit_-_ObjectReference

OnHit event would be what you need.
User avatar
kevin ball
 
Posts: 3399
Joined: Fri Jun 08, 2007 10:02 pm

Post » Sun Jun 17, 2012 12:38 pm

http://www.creationkit.com/OnHit_-_ObjectReference events are called when the scripted reference is hit. If you put it on a weapon and hit something with the weapon, the OnHit event won't be called.

If you use an enchantment like JoelBurgess suggested, that will be activated when you use the weapon to hit something else.

Cipscis
User avatar
lauraa
 
Posts: 3362
Joined: Tue Aug 22, 2006 2:20 pm

Post » Mon Jun 18, 2012 1:37 am

In past games though, you could attach a script to an object, as well as an enchantment, and the script would run on hit by default (I think?), or there was a way to specify it to run when it hit someone and run the code on them (using getSelf() if I'm not mistaken).

Is there no way to do this anymore without enchantments?

I ask because I was looking to add functionality to weapons without overriding existing enchantments, and giving every actor a script that checks the weapon hitting them for a Keyword seems like overkill for something that was so simple before.
User avatar
Isaac Saetern
 
Posts: 3432
Joined: Mon Jun 25, 2007 6:46 pm

Post » Sun Jun 17, 2012 5:35 pm

Attaching scripts with an onHit() to every actor would, indeed, be overkill. Enchantments are the way to go. You'll create one script that lives there and passes an ActiveMagicEffect onto an actor hit by the weapon.
User avatar
Justin
 
Posts: 3409
Joined: Sun Sep 23, 2007 12:32 am

Post » Sun Jun 17, 2012 6:06 pm

Here's the complete list of native events:
http://www.creationkit.com/Category:Events

If I remember correctly, though, and OnHit block on a weapon has never worked. How did you do this in previous games?

Cipscis
User avatar
Laura Cartwright
 
Posts: 3483
Joined: Mon Sep 25, 2006 6:12 pm

Post » Mon Jun 18, 2012 3:15 am

Try looking at the enchantment on Mehrunes' Razor as a place to get started. - DA07MehrunesRazorMagicEffect
User avatar
Marta Wolko
 
Posts: 3383
Joined: Mon Aug 28, 2006 6:51 am

Post » Sun Jun 17, 2012 2:14 pm

Try looking at the enchantment on Mehrunes' Razor as a place to get started. - DA07MehrunesRazorMagicEffect

While your here.

Could you give me a tip on how to get a Passive/Constant Detect life effect?

I think the problem is that Constant Effects, apply the effect to the wearer of the amulet (item), and Detect Life spells need to be area wide in order to hit other targets.

Every thing I try, gets the detect life shader to affect me, and only me, everyone else remains normal, and I get glowy.

Closest I got, was applying it via enchantment, which is what got me glowing... but so far, cant make it affect others.
User avatar
Paul Rice
 
Posts: 3430
Joined: Thu Jun 14, 2007 11:51 am

Post » Sun Jun 17, 2012 8:33 pm

While your here.

Could you give me a tip on how to get a Passive/Constant Detect life effect?

I think the problem is that Constant Effects, apply the effect to the wearer of the amulet (item), and Detect Life spells need to be area wide in order to hit other targets.

Every thing I try, gets the detect life shader to affect me, and only me, everyone else remains normal, and I get glowy.

Closest I got, was applying it via enchantment, which is what got me glowing... but so far, cant make it affect others.

Why not make it so the amulet gives you a special power (Either to be hotkeyed or to be used with "Z" like Shouts) and then make that power (Toggle-able) the Night Eye.
User avatar
Prue
 
Posts: 3425
Joined: Sun Feb 11, 2007 4:27 am

Post » Mon Jun 18, 2012 3:38 am

Night Eye is easy to do - I have that already - Its detect life I would like.
But I dont think it is do-able via enchantments.

The effect needs to be applied to people in the vicinity of me.
Enchantments on the otherhand, only apply to the wearer.

Closest way to do this, is to do some sort of pseudo HB that triggers a Detect Life on HB Via Script.

Enchantments only target other npc's when used like staves, or when they are hit by them.
Thats the only way I can think of to get Detect Life working as a wearable amulet.
User avatar
Samantha Mitchell
 
Posts: 3459
Joined: Mon Nov 13, 2006 8:33 pm

Post » Sun Jun 17, 2012 11:32 am

If I remember correctly, though, and OnHit block on a weapon has never worked. How did you do this in previous games?

I can't recall what block type I was using, but I can't imagine it was anything other than GameMode, with the script selected in the Script Effect field. I'd check, except that the hard drive with Oblivion and FO3 on it is gathering dust somewhere in my closet. The Script Effect field doesn't even seem to exist anymore, there's only Crit Effect and Enchantment, as if they replaced Script Effect with the Papyrus Scripts array, even though they have totally different functionality now (read: the new one is, as far as I can tell, extremely limited in use).
User avatar
Smokey
 
Posts: 3378
Joined: Mon May 07, 2007 11:35 pm

Post » Sun Jun 17, 2012 10:48 pm

As with the Mehrunes spell mentioned above, I want a spell to go off when the sword hits, but the Mehrunes example leaves a critical thing out: I don't need akCaster.kill, I need "akCaster.castSpell(spellname)" in psuedo-code.

Edit: Figured it out. Here's the script I was looking for:

ScriptName AkaviriEffect extends ActiveMagicEffectSpell property spellToCast autoEvent OnEffectStart(Actor akTarget, Actor akCaster)debug.trace(self + " hitting " + akTarget + "with Ghostblade")spellToCast.Cast(akCaster, None)EndEVENT
User avatar
Phillip Hamilton
 
Posts: 3457
Joined: Wed Oct 10, 2007 3:07 pm


Return to V - Skyrim