Effect on Strike - How do I give weapons script abilities on

Post » Mon Jun 18, 2012 3:25 am

I've no experience with modding or scripting anything... ever...

But I managed to create a box which sends the player flying when activated with some help, now I want to add that (or, really, any special effect) to a weapon, so that when striking an enemy (or friend) I can cause that effect.

In this case, I want to knockback (like the chest does) an enemy whenever I use a connecting power attack.

Thanks.


Edit: Also, is there anyway to delay the effect?
User avatar
Pete Schmitzer
 
Posts: 3387
Joined: Fri Sep 14, 2007 8:20 am

Post » Mon Jun 18, 2012 6:31 pm

You should take a look at the dragonpriest ultra mask effect. It has scripts on it that "do something" when the actor wearing it is struck. All you need to do is change the script so that "doesthe thing you want" when your actor hits the enemy :D
User avatar
Chase McAbee
 
Posts: 3315
Joined: Sat Sep 08, 2007 5:59 am

Post » Mon Jun 18, 2012 2:31 am

You can put an OnHit() event on the objects that you want to affect the player when it is hit. akAggressor is the actor who struck the object (in this case the player). Make a script with something like this:

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \bool abBashAttack, bool abHitBlocked)  Actor aggressor = akAggressor.GetBaseObject() as ActorEndEvent

Now you have access to whoever hit the object as the actor "aggressor" and you can mess with them.

You can't really use a weapon effect to give an "on-strike" effect through a weapon script. You could however make the effect a Magic Effect on an Enchantment and apply the Enchantment to the weapon.
User avatar
Emily abigail Villarreal
 
Posts: 3433
Joined: Mon Aug 27, 2007 9:38 am

Post » Mon Jun 18, 2012 7:21 am

You can put an OnHit() event on the objects that you want to affect the player when it is hit. akAggressor is the actor who struck the object (in this case the player). Make a script with something like this:

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \bool abBashAttack, bool abHitBlocked)  Actor aggressor = akAggressor.GetBaseObject() as ActorEndEvent

Now you have access to whoever hit the object as the actor "aggressor" and you can mess with them.

You can't really use a weapon effect to give an "on-strike" effect through a weapon script. You could however make the effect a Magic Effect on an Enchantment and apply the Enchantment to the weapon.

Thanks for the help, but that would require being hit by the enemy in order to hit them back. I was hoping there would be a way to affect targets struck by the player.
User avatar
yermom
 
Posts: 3323
Joined: Mon Oct 15, 2007 12:56 pm

Post » Mon Jun 18, 2012 3:51 pm

Thanks for the help, but that would require being hit by the enemy in order to hit them back. I was hoping there would be a way to affect targets struck by the player.
You can do this by adding an enchantment with a script attatched to it to your weapon, example:

1) Make a new weapon myweapon
2) Make a new enchantment myenchantment
3) Make a new magic-effect myeffect

4) Set the myeffect's settings/variables to:
casting type: fire and forgetdelivery: contactand if you want it to have no cost, base cost: 0

5) Add a papyrus script to your effect modeled after this:
Scriptname myscript extends ActiveMagicEffect{mydescription}Event OnEffectStart(Actor akTarget, Actor akCaster)if akCaster == Game.GetPlayer()  Debug.MessageBox("We hit them")EndIfEndEvent

6) Add myeffect to myenchantment, then myenchantment to myweapon

The current script will just create a little window in-game whenever the player hits someone with the weapon saying "we hit them"

Not sure how to check if it was a power attack though.. but it's a good start
User avatar
sam
 
Posts: 3386
Joined: Sat Jan 27, 2007 2:44 pm

Post » Mon Jun 18, 2012 1:14 pm

You can do this by adding an enchantment with a script attatched to it to your weapon, example:

1) Make a new weapon myweapon
2) Make a new enchantment myenchantment
3) Make a new magic-effect myeffect

4) Set the myeffect's settings/variables to:
casting type: fire and forgetdelivery: contactand if you want it to have no cost, base cost: 0

5) Add a papyrus script to your effect modeled after this:
Scriptname myscript extends ActiveMagicEffect{mydescription}Event OnEffectStart(Actor akTarget, Actor akCaster)if akCaster == Game.GetPlayer()  Debug.MessageBox("We hit them")EndIfEndEvent

6) Add myeffect to myenchantment, then myenchantment to myweapon

The current script will just create a little window in-game whenever the player hits someone with the weapon saying "we hit them"

Not sure how to check if it was a power attack though.. but it's a good start

Thank you. Am going to test it out now.

Edit:

So, I've no idea how to get it to fling the target now.

self.PushActorAway(game.getplayer(), 50)

That was the script the box used, how would I modify it to hit the target? akTarget, Actor akTarget etc. aren't "valid" according to the script


So after messing around and using the wiki, I got a script which 'compiles'... but does nothing in-game.

Scriptname fusrosword extends ObjectReference{fusrosword}Event OnEffectStart(Actor akTarget, Actor akCaster)if akCaster == Game.GetPlayer()    PushActorAway(akTarget, 50)EndIfEndEvent
User avatar
Rozlyn Robinson
 
Posts: 3528
Joined: Wed Jun 21, 2006 1:25 am

Post » Mon Jun 18, 2012 7:39 am

Thank you. Am going to test it out now.

Edit:

So, I've no idea how to get it to fling the target now.

self.PushActorAway(game.getplayer(), 50)

That was the script the box used, how would I modify it to hit the target? akTarget, Actor akTarget etc. aren't "valid" according to the script


So after messing around and using the wiki, I got a script which 'compiles'... but does nothing in-game.

Scriptname fusrosword extends ObjectReference{fusrosword}Event OnEffectStart(Actor akTarget, Actor akCaster)if akCaster == Game.GetPlayer()	PushActorAway(akTarget, 50)EndIfEndEvent
What is PushActorAway a function of? You'll probably want to do something like akCaster.PushActorAway(akTarget, 50) or Game.GetPlayer().PushActorAway(akTarget,50) assuming you can use PushActorAway within an actor

Just calling PushActorAway without another object in front wont push the actor away from anything since it has no idea where it is being pushed from
User avatar
Annick Charron
 
Posts: 3367
Joined: Fri Dec 29, 2006 3:03 pm

Post » Mon Jun 18, 2012 4:37 pm

What is PushActorAway a function of? You'll probably want to do something like akCaster.PushActorAway(akTarget, 50) or Game.GetPlayer().PushActorAway(akTarget,50) assuming you can use PushActorAway within an actor

Just calling PushActorAway without another object in front wont push the actor away from anything since it has no idea where it is being pushed from

Tried:

Scriptname fusrosword extends ObjectReference{fusrosword}Event OnEffectStart(Actor akTarget, Actor akCaster)if akCaster == Game.GetPlayer() self.PushActorAway(akTarget, 50)EndIfEndEvent

and using akcaster instead of self as well. Nothing happened. I also modified my enchant to mimic the red eagle fire enchantment just to make sure that an effect was being applied.

Would I need to define 'aktarget' as well?

I'm also going to get rid of the 'if' as well, see if that works.
User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm

Post » Mon Jun 18, 2012 5:18 pm

Tried:

Scriptname fusrosword extends ObjectReference{fusrosword}Event OnEffectStart(Actor akTarget, Actor akCaster)if akCaster == Game.GetPlayer()self.PushActorAway(akTarget, 50)EndIfEndEvent

and using akcaster instead of self as well. Nothing happened. I also modified my enchant to mimic the red eagle fire enchantment just to make sure that an effect was being applied.

Would I need to define 'aktarget' as well?

I'm also going to get rid of the 'if' as well, see if that works.
I didn't notice this before, but change ObjectReference to ActiveMagicEffect, otherwise the OnEffectStart event never gets called, OnEffectStart is an event that is a part of the ActiveMagicEffect script, so it needs to be extended in order for you to use it

The if statement is only there to check if its the player that hit someone, so feel free to drop it.

akCaster and akTarget are predefined, since they are being sent to the OnEffectStart event. OnEffectStart runs every time the magic effect is supposed to be applied, in this case everytime the weapon hits someone, and it gives you the actor (player or npc) who is casting the effect and the actor being hit by the effect
User avatar
Jaylene Brower
 
Posts: 3347
Joined: Tue Aug 15, 2006 12:24 pm

Post » Mon Jun 18, 2012 12:28 pm

I didn't notice this before, but change ObjectReference to ActiveMagicEffect, otherwise the OnEffectStart event never gets called, OnEffectStart is an event that is a part of the ActiveMagicEffect script, so it needs to be extended in order for you to use it

The if statement is only there to check if its the player that hit someone, so feel free to drop it.

akCaster and akTarget are predefined, since they are being sent to the OnEffectStart event. OnEffectStart runs every time the magic effect is supposed to be applied, in this case everytime the weapon hits someone, and it gives you the actor (player or npc) who is casting the effect and the actor being hit by the effect

Thanks so much. Works like a charm.

Now I just have to learn how to apply that to power attacks only, and then how to create different effects.
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Mon Jun 18, 2012 4:15 pm

Thanks so much. Works like a charm.

Now I just have to learn how to apply that to power attacks only, and then how to create different effects.
Sadly the only way I know of to check for power attacks is in the OnHit method of an actor D:
Unless there's a way to check the animation state of the caster and see if its a power attack animation
User avatar
Davorah Katz
 
Posts: 3468
Joined: Fri Dec 22, 2006 12:57 pm

Post » Mon Jun 18, 2012 1:24 pm

Sadly the only way I know of to check for power attacks is in the OnHit method of an actor D:
Unless there's a way to check the animation state of the caster and see if its a power attack animation

http://www.creationkit.com/OnAnimationEvent_-_Form
User avatar
Jeffrey Lawson
 
Posts: 3485
Joined: Tue Oct 16, 2007 5:36 pm


Return to V - Skyrim