Jump to content

Equip item on add + cast on equip


h3Xh3X

Recommended Posts

I'm trying to make an item equip when added to an actor's inventory. When equipped, the item should turn the actor into a hagraven.

I have the spell effect and spell set up.

 

Effect:

Scriptname PolymorphHostileEffectScript extends ActiveMagicEffect  
{Turns target into a hostile polymorph}

Race Property PolymorphRace auto
Faction Property PlayerWerewolfFaction auto

Event OnEffectStart(Actor Target, Actor Caster)
if (Target.GetActorBase().GetRace() != PolymorphRace)
	Target.SetRace(PolymorphRace)
	Target.UnequipAll()
	Target.SetAttackActorOnSight(true)
	Target.AddToFaction(PlayerWerewolfFaction)
endif
EndEvent

Event OnEffectFinish(Actor Target, Actor Caster)
; change back
Target.SetRace(None) 
Target.SetAttackActorOnSight(false)
Target.RemoveFromFaction(PlayerWerewolfFaction)
endEvent

 

EquipOnAddNotPlayer:

Scriptname EquipOnAddNotPlayer extends ObjectReference  
{Equips item when added to inventory,
unless actor is player.}

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
   if akNewContainer != Game.GetPlayer()
       if akNewContainer
           Debug.Trace("Item contained by " + akNewContainer)
;            (akNewContainer as Actor).Equip(this) ; <- I'm not sure what to do here
       endIf
   endIf
endEvent

 

CastOnEquip:

Scriptname CastOnEquip extends ObjectReference 
{Object casts spell when equipped }
Spell Property SpellToCast auto

Event OnEquipped(Actor AkActor)
AkActor.AddSpell(SpellToCast)
SpellToCast.Cast(Self, Self)
EndEvent


Event OnUnequipped(Actor AkActor)
AkActor.RemoveSpell(SpellToCast)
EndEvent

 

In the CastOnEquip script, I'm not sure if AddSpell() and RemoveSpell() are needed. Please enlighten me!

In the EquipOnAddNotPlayer script, see the commented line. I'm wondering how to cast akNewContainer to an Actor object so I can call EquipItem on it (or how to achieve this by other means). I also wouldn't know what to pass as akItem to EquipItem() in this case.

Link to comment
Share on other sites

EquipOnAddNotPlayer:

 

- you also need to test that the container is an actor, (EquipItem will give an error on non-actors).

- it's EquipItem, not Equip

- use "self"

 

Scriptname EquipOnAddNotPlayer extends ObjectReference  
{Equips item when added to inventory, unless actor is player.}

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
if (akNewContainer as Actor) != none && akNewContainer != Game.GetPlayer()
	Debug.Trace("[EquipOnAddNotPlayer] Item contained by " + akNewContainer)
	(akNewContainer as Actor).EquipItem(self)
else
	Debug.Trace("[EquipOnAddNotPlayer] Container is not a non-player actor " + akNewContainer)
endIf
endEvent

 

CastOnEquip:

 

- AddSpell and RemoveSpell are not necessary.

 

Scriptname CastOnEquip extends ObjectReference 
{Object casts spell when equipped }

Spell Property SpellToCast auto

Event OnEquipped(Actor AkActor)
SpellToCast.Cast(Self, Self)
EndEvent

 

PS. I don't have the CK handy, so I couldn't test if the scripts work or not.

Edited by steve40
Link to comment
Share on other sites

Btw, I'm not sure if setting race to "none" will work (or it might default to Nord race!). You need to store the initial race in a property, then set it back afterwards:

 

Scriptname PolymorphHostileEffectScript extends ActiveMagicEffect  
{Turns target into a hostile polymorph}

Race Property PolymorphRace auto
Faction Property PlayerWerewolfFaction auto
Race Property InitialRace auto hidden

Event OnEffectStart(Actor Target, Actor Caster)

InitialRace = Target.GetActorBase().GetRace()

       if (InitialRace != PolymorphRace)
               Target.SetRace(PolymorphRace)
               Target.UnequipAll()
               Target.SetAttackActorOnSight(true)
               Target.AddToFaction(PlayerWerewolfFaction)
       endif
EndEvent

Event OnEffectFinish(Actor Target, Actor Caster)
       ; change back
       Target.SetRace(InitialRace) 
       Target.SetAttackActorOnSight(false)
       Target.RemoveFromFaction(PlayerWerewolfFaction)
endEvent

Edited by steve40
Link to comment
Share on other sites

Btw, I'm not sure if setting race to "none" will work (or it might default to Nord race!). You need to store the initial race in a property, the set it back afterwards:

 

This was what the "polymorph skeever" test script in the ck did, so I just blindly copied that (adding hostile effects). Thanks for the pointer, I'll keep it in mind when I test. :)

Now I'm gonna go around reverse pickpocketing polymorph rings to guards! :D

Edited by h3Xh3X
Link to comment
Share on other sites

The Debug.Trace messages will print into the papyrus log, but will only work if you have enabled trace logging in your Skyrim.ini file.

 

As gast89 says, you can change "Debug.Trace" to "Debug.Notification" and the messages will show on your monitor.

Link to comment
Share on other sites

Okay, getting the messages now. Still no transformation.

One question; how can I invoke a script from within another script instead of triggering it on an event?

 

The message says it is contained by TGAssaultScript <reference> instead of Actor or ObjectReference <reference>. This may be because I'm testing it on people in thieves guild (TG) and they are supposed to react as if assaulted?

Maybe I can put it in their inventory without pickpocketing for now. Not sure if Actor.OpenInventory() is implemented in console.

Edited by h3Xh3X
Link to comment
Share on other sites

Hmmm. Maybe that means that you got busted pickpocketing? Could you try it on some ordinary guards please.

 

Also try this putting this script on the ring, I've added a debug message.

 

Scriptname CastOnEquip extends ObjectReference 
{Object casts spell when equipped }

Spell Property SpellToCast auto

Event OnEquipped(Actor AkActor)
Debug.Notification("[CastOnEquip]Item was equipped by: " + AkActor)
       SpellToCast.Cast(Self, Self)
EndEvent

 

Edit: also try this modified script:

 

Scriptname EquipOnAddNotPlayer extends ObjectReference  
{Equips item when added to inventory, unless actor is player.}

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
       if (akNewContainer as Actor) != none && akNewContainer != Game.GetPlayer()
               Debug.Trace("[EquipOnAddNotPlayer] Item contained by " + akNewContainer)
               (akNewContainer as Actor).EquipItem((self as Armor).GetBaseObject(), True, True)
       else
               Debug.Trace("[EquipOnAddNotPlayer] Container is not a non-player actor " + akNewContainer)
       endIf
endEvent

Edited by steve40
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...