Trouble casting a spell from an wearable item to player

Post » Wed Jun 20, 2012 10:10 pm

Hello everyone!

I have been trying to make this to work for about 4 hours now, but the wiki nor this forums made it work. So i guess i'm just going to ask it here. I am aware that this might seem simple for some of you, but i have never scripted with papyrus before, so please do understand.

(I'm not Englisch, so i'm sorry for grammer/spelling mistakes :biggrin:)

So my problem is... As soon as i equip something, i want a spell to be cast on the player. I tried using all the functions i'm aware of, but they didn't do the trick(or i used wrong parameters). This is all i have:

Item:
-Script
Scriptname TripAuraScriptBase extends ObjectReference{OnEquip shows message, play sound & shake camera}Sound property AmbRumbleShake autoSpell property TripAuraBasePlayerAbility autoEvent OnEquipped(Actor akActor)  if akActor == Game.GetPlayer()  Debug.MessageBox("You equipped the Aura. It's effects will help you untill you unequip it.")  Game.ShakeCamera()  TripAuraBasePlayerAbility.Cast(Self, Game.GetPlayer())  Game.GetPlayer().AddSpell(TripAuraBasePlayerAbility)  ;AmbRumbleShake.play(self)  endIfEndEventEvent OnUnequipped(Actor akActor)  if akActor == Game.GetPlayer()  Debug.MessageBox("You unequipped the Aura. It's effects will leave your body.")  Game.ShakeCamera()  Game.GetPlayer().DispelSpell(TripAuraBasePlayerAbility)  ;AmbRumbleShake.play(self)  endIfEndEvent

-Item:
[img]http://i552.photobucket.com/albums/jj335/fire3lf/Item.jpg[/img]

Magic effect:
Scriptname TripAuraBasePlayerEffectScript extends activemagiceffect{Placed on player};Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)  ;Debug.Messagebox("We were hit by " + akAggressor)  ;Debug.Trace("We were hit by " + akAggressor);EndEventEvent OnEquipped(Actor akActor)	If (akActor == Game.GetPlayer())		Debug.Messagebox("ok")	EndIfEndEvent
<====== Temp to see if it was working

[img]http://i552.photobucket.com/albums/jj335/fire3lf/effect.jpg[/img]

Spell:
[img]http://i552.photobucket.com/albums/jj335/fire3lf/spell.jpg[/img]

I have done lots of different types, but i couldn't make it to work...

If anyone has an idea, please tell me!

Thanks,

Triplus


For those who can make the sound work too, it would be much appreiciated, i don't hear the doun playing (without the ; in the script ofc)
User avatar
IsAiah AkA figgy
 
Posts: 3398
Joined: Tue Oct 09, 2007 7:43 am

Post » Thu Jun 21, 2012 2:02 am

.
User avatar
David John Hunter
 
Posts: 3376
Joined: Sun May 13, 2007 8:24 am

Post » Wed Jun 20, 2012 8:59 pm

An ability doesn't need to be cast - Addspell does all you need.

But if you want the "ok" messagebox to show when the magic effect starts, you should use an OnEffectStart event, not OnEquipped.

Event OnEffectStart(Actor akTarget, Actor akCaster)  Debug.Notification("Magic effect was started on " + akTarget)endEvent
User avatar
Vivien
 
Posts: 3530
Joined: Fri Apr 13, 2007 2:47 pm

Post » Thu Jun 21, 2012 8:21 am

An ability doesn't need to be cast - Addspell does all you need.

But if you want the "ok" messagebox to show when the magic effect starts, you should use an OnEffectStart event, not OnEquipped.

Event OnEffectStart(Actor akTarget, Actor akCaster)  Debug.Notification("Magic effect was started on " + akTarget)endEvent
i'll try that, thanks :smile:

EDIT: it still isn't working... MY screen is shaking, and i get the messagebox from the first script, but i do not get the effect messagebox...
I really can't figure out what i'm doing wrong... from what i remeber form de oblivion CS this is about what i did there...
User avatar
Bitter End
 
Posts: 3418
Joined: Fri Sep 08, 2006 11:40 am

Post » Wed Jun 20, 2012 10:22 pm

I have made it to work... but now i wonder how i can add a spell to the "ak agressor".

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)  Debug.Messagebox("Aggressor, source" + akAggressor + akSource)  TripAuraBaseEnemyAbility.Cast(akAggressor, akAggressor)EndEvent

I get the messagebox, but i don't htink the aggressor gets the spell...

akAggressor.addspell(spell)
does not work either..., not able to compile that...

any sugestions.
User avatar
LuBiE LoU
 
Posts: 3391
Joined: Sun Jun 18, 2006 4:43 pm

Post » Thu Jun 21, 2012 8:44 am

akAggressor is an ObjectReference, so you need to cast it to be an actor (akAggressor as Actor) before you can use AddSpell().
User avatar
Victoria Vasileva
 
Posts: 3340
Joined: Sat Jul 29, 2006 5:42 pm

Post » Thu Jun 21, 2012 7:08 am

I don't get what i'm doing wrong...

Scriptname TripAuraBasePlayerEffectScript extends activemagiceffect {Placed on player}Spell Property TripAuraBaseEnemyAbility AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)  Debug.Messagebox("Cloak effect was started on " + akTarget + akCaster)EndEventEvent OnHit(Objectreference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)  Debug.Messagebox("Aggressor, source" + akAggressor + akSource)  ((akAggressor) as Actor).AddSpell(TripAuraBaseEnemyAbility)EndEvent

This should apply this script (I do get the messagebox :))

Scriptname TripAuraBaseEnemyEffectScript extends activemagiceffect {Placed on Enemy}Event OnDeath(Actor akKiller)if (akKiller == Game.GetPlayer())  Debug.Messagebox("We were killed by the player!")endIfEndEvent

I tried oneffectstart event, with a messagebox, but it wouldn't work...

I got a feeling papyrus is much harder then scritping with the oblivion CS...

Thanks for taking your time to help me out! :)
User avatar
Amiee Kent
 
Posts: 3447
Joined: Thu Jun 15, 2006 2:25 pm

Post » Thu Jun 21, 2012 12:02 pm

OnDeath occurs after death, so the script is not running unless you specify 'No death dispel' for the TripAuraBaseEnemyEffect. But you could use OnDying instead.
User avatar
Sarah Unwin
 
Posts: 3413
Joined: Tue Aug 01, 2006 10:31 pm

Post » Thu Jun 21, 2012 10:27 am

AddSpell actually teaches the spell to the Actor.
User avatar
Leonie Connor
 
Posts: 3434
Joined: Mon Mar 12, 2007 4:18 pm

Post » Thu Jun 21, 2012 12:12 pm

AddSpell actually teaches the spell to the Actor.

so what would you sugest then?

OnDeath occurs after death, so the script is not running unless you specify 'No death dispel' for the TripAuraBaseEnemyEffect. But you could use OnDying instead.
I'll try it tomorrow, thanks anyway :)
User avatar
Flash
 
Posts: 3541
Joined: Fri Oct 13, 2006 3:24 pm

Post » Thu Jun 21, 2012 2:53 am

Well items can cast spells on targets...so the item should be able to cast a spell on the player on the OnEquipped event. Make the spell effect a scripted type, and have it register for updates, checking whether the item is still equipped, and if it isn't stop registering for updates and disable itself.
User avatar
Robert Jr
 
Posts: 3447
Joined: Fri Nov 23, 2007 7:49 pm

Post » Thu Jun 21, 2012 12:44 pm

It aint working yet... i really don't know what i'm doing worng :(

I have tried staying as close to this as possible: http://www.creationkit.com/Dynamically_Attaching_Scripts
What i've done so far:
I got gloves placed on slot 61 with a script just doing some textboxes, shaking screen ect, ect:

Spoiler
Scriptname TripAuraScriptBase extends ObjectReference{OnEquip shows message, play sound & shake camera}Event OnEquipped(Actor akActor)  if akActor == Game.GetPlayer()  Debug.MessageBox("You equipped the Aura. It's effects will help you untill you unequip it.")  Game.ShakeCamera()  endIfEndEventEvent OnUnequipped(Actor akActor)  if akActor == Game.GetPlayer()  Debug.MessageBox("You unequipped the Aura. It's effects will leave your body.")  Game.ShakeCamera()  endIfEndEvent

These gloves also have an enchantment with cloak and 192 magnitude. First i had this

Spoiler
Scriptname TripAuraBasePlayerEffectScript extends activemagiceffect  {Placed on player}Spell Property TripAuraBaseApplySpell AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)Debug.Messagebox("Cloak effect was started on " + akTarget)EndEventEvent OnHit(Objectreference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)Debug.Notification("Aggressor, source" + akAggressor + akSource)((akAggressor) as Actor).AddSpell(TripAuraBaseApplySpell)TripAuraBaseApplySpell.Cast(akAggressor, akAggressor)EndEvent
Script running on the cloak, but i removed it cuz they might interfere (i tought) This script isn't necessary so leave this :smile:

Then i have copied the script from the page mentionned above:
Spoiler
Scriptname TripAuraBaseEnemyEffectScript extends activemagiceffect  {Placed on Enemy}Actor MySelfFloat HealthEvent OnEffectStart(Actor akTarget, Actor akCaster)MySelf = akTargetHealth = MySelf.GetActorValue("Health")RegisterForSingleUpdate(0.25)EndEventEvent OnUpdate()Health = MySelf.GetActorValue("Health")RegisterForSingleUpdate(0.25)EndEventEvent OnEffectFinish(Actor akTarget, Actor akCaster)UnregisterForUpdate()EndEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, \  bool abSneakAttack, bool abBashAttack, bool abHitBlocked)Float Damage = Health - MySelf.GetActorValue("Health")Health = MySelf.GetActorValue("Health")if (akAggressor == Game.GetPlayer())Debug.Notification("You did " + Damage as Int + " points of damage.")endifEndEvent
But the damge isn't showing up in the top left corner...

I also have this script
Scriptname TripEnemyBaseApplyingScript extends activemagiceffectSpell Property TripAuraBaseEnemyAbility AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)akTarget.AddSpell(TripAuraBaseEnemyAbility)EndEvent

As far as i'm aware, all that is defferent to the page mentionned above is that i apply the cloak by an enchantment, and not by adding it with a quest...
I can upload my esp, if anyone wants to check if i havn't messed up... and i'm pretty sure i did :s

I really appriciate you guys keep taking the time to help me out! :smile:
User avatar
Austin Suggs
 
Posts: 3358
Joined: Sun Oct 07, 2007 5:35 pm

Post » Thu Jun 21, 2012 8:30 am

First, is a cloak really what you want? A cloak applies the spell which you set as the Assoc. Item 1 of the magic effect to everyone within the radius set by the magnitude (modified by the conditions you put on it, of course). In your scripts you seem to want to apply it only to NPCs who've hit the player. Which should it be?
User avatar
Luis Reyma
 
Posts: 3361
Joined: Fri Nov 02, 2007 11:10 am

Post » Thu Jun 21, 2012 3:45 am

hmm... the reason i'm making this is not to attatch the scripts currently on it... but i want to add 10% of the enemys hp to the player, when the enemy dies. So it should be everyone the player kills. I think both should work, but wich one is the most efficient? :)
User avatar
Daddy Cool!
 
Posts: 3381
Joined: Tue Aug 21, 2007 5:34 pm

Post » Thu Jun 21, 2012 6:28 am

I don't think either will work. The OnHit method has the drawback that the enemy would have to land a blow, which they often don't. The Cloak method would be better, but has the drawback that you'd need to specify a large range, to get everyone within shooting distance, and it can take a while to attach the effect to everyone in an area. Both of them have the problem that actors in levelled lists can't have scripts attached.

Unfortunately, according to the Wiki, the OnCombatStateChanged doesn't work when applied to the player, or you could use that. What about using OnStoryKillActor instead?
User avatar
brenden casey
 
Posts: 3400
Joined: Mon Sep 17, 2007 9:58 pm

Post » Thu Jun 21, 2012 9:02 am

I woud have the onStoryKillActor on the player(instead of the cloak). Then i can detect the 'ak victims'

health. That would be it i think. I'll let you know. First i'm going to finish somthing in minecraft :tongue:


Thanks! :smile:

User avatar
helen buchan
 
Posts: 3464
Joined: Wed Sep 13, 2006 7:17 am

Post » Thu Jun 21, 2012 9:19 am

NB OnStoryKillActor is a Quest's event, not the player's. Have fun :)
User avatar
Latino HeaT
 
Posts: 3402
Joined: Thu Nov 08, 2007 6:21 pm

Post » Thu Jun 21, 2012 12:01 pm

so i would have to make a quest to do this?

EDIT; 1 sec i think i'm headding in the right direction... :) i'll let you know, found a topic where it is +- explained
User avatar
Baby K(:
 
Posts: 3395
Joined: Thu Nov 09, 2006 9:07 pm

Post » Thu Jun 21, 2012 4:16 am

1 quick question. would i have to put this

Event OnStoryKillActor(ObjectReference akVictim, ObjectReference akKiller, Location akLocation, int aiCrimeStatus, int aiRelationshipRank)  Victimshealth = ((akVictim) as Actor).GetBaseActorValue("health")   Debug.Messagebox(akKiller + " killed " + akVictim + "Who had " + Victimshealth as Int + "Hitpoints")   Game.GetPlayer().RestoreActorValue("health", 50)EndEvent

as the questscript?
User avatar
Kyra
 
Posts: 3365
Joined: Mon Jan 29, 2007 8:24 am

Post » Thu Jun 21, 2012 9:10 am

No. You can pop the body of that in the Papyrus script tab of your quest's one and only stage. Have to rush now but I'll come back and give more details in an hour, if you need them. :)
User avatar
Penny Flame
 
Posts: 3336
Joined: Sat Aug 12, 2006 1:53 am

Post » Thu Jun 21, 2012 7:51 am

hmmm.... i have been trying all sorts of things, inserting the whole script gives me an error, inserting this
ObjectReference akVictimObjectReference akKillerLocation akLocationint aiCrimeStatusint aiRelationshipRankVictimshealth = ((akVictim) as Actor).GetBaseActorValue("health")Debug.Messagebox(akKiller + " killed " + akVictim + "Who had " + Victimshealth as Int + "Hitpoints")Game.GetPlayer().RestoreActorValue("health", 50)
compiles, but i didn't say when it should do something(no event).

I'm putting this in the Papyrus Fragment bit of the quest Stages tab, is that correct?
User avatar
SHAWNNA-KAY
 
Posts: 3444
Joined: Mon Dec 18, 2006 1:22 pm

Post » Thu Jun 21, 2012 5:34 am

Here are what I think are complete instructions for the whole process - you've obviously done some of this but there are one or two gotchas so I'll just go through it all.

Create a new quest. On the Quest Data tab, give it an ID but not a name, so the player doesn't get notifications about the quest starting and finishing, and set the Event to Kill Actor Event.

On the Quest aliases Tab, create two aliases: KillerAlias and VictimAlias, and set their Fill type to Find matching reference: From Event. You'll have to click ok and then reopen each alias before you can set the event type to Kill Actor Event, and the Event Data to Killer or Victim, respectively.

On the Quest Stages tab, create one stage, 0. Do not give it a log entry, but check the Start up and Shut down stage check boxes, and enter the following in the Papyrus Script tab:
if alias_KillerAlias.GetReference() == Game.GetPlayer()  float VictimHealth =  alias_VictimAlias.GetActorReference().GetBaseActorValue("health")  Debug.Notification("Adding " + VictimHealth + " HP")  Game.GetPlayer().RestoreActorValue("health", VictimHealth)endIfstop() 

Note that you refer to quest aliases with "alias_" before their names. The Stop() is needed to get the Story Manager to repeat this quest. Click Compile, and save the quest.

Now in the Object window go to Character\SM Event node, open up the Kill Actor node, right click on the top node and add a new Quest node. Drag it up to the top of the quest node list, and make sure Shares Event is clicked. Right click on it and add your quest.

That's it, I think. :)
User avatar
Cheryl Rice
 
Posts: 3412
Joined: Sat Aug 11, 2007 7:44 am

Post » Thu Jun 21, 2012 3:50 am

Thank you for the detaille explanation, but everytime i clikc ok and reopen, the checkbox next to fin matchin ref goes away and goes back to specific ref...
User avatar
{Richies Mommy}
 
Posts: 3398
Joined: Wed Jun 21, 2006 2:40 pm

Post » Thu Jun 21, 2012 12:38 am

You have to set the Event to Kill Actor Event on the Quest Data tab first.
User avatar
meg knight
 
Posts: 3463
Joined: Wed Nov 29, 2006 4:20 am

Post » Wed Jun 20, 2012 9:58 pm

perfect that did it. going to test it tomorrow. You are my hero! :) thank you again! i'll let you know for sure!
User avatar
Jose ordaz
 
Posts: 3552
Joined: Mon Aug 27, 2007 10:14 pm

Next

Return to V - Skyrim