Jump to content

[LE] Moving an item stolen by commanded actor to the player's inventory


moopdog

Recommended Posts

Trying to make a spell that puts the target into the command state. I've managed to do that, and set their Morality to 0 while they're commanded so they'll do whatever you want.

Scriptname ft_CommandScript extends activemagiceffect  

Actor property TargetAct Auto
float property TargetAV Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
	TargetAV == akTarget.GetActorValue("Morality")
	TargetAct == akTarget
	akTarget.SetActorValue("Morality", 0)
	akTarget.SetDoingFavor()
EndEvent

Event OnCommandModeCompleteCommand(int aeCommandType, ObjectReference akTarget)
	TargetAct.SetActorValue("Morality", TargetAV)
EndEvent

Event OnCommandModeExit()
	TargetAct.SetActorValue("Morality", TargetAV)
EndEvent 

The problem I'm having is that when the commanded actor steals an item, they just keep it. I want to make it so the player ends up with the stolen item. I assume this could be accomplished just by using the RemoveItem function, but the issue is what triggers it. I've tried using the OnCommandModeCompleteCommand event, but since stealing an item doesn't count as "completing" the command, it didn't work. Any help would be greatly appreciated.

Link to comment
Share on other sites

maybe OnContainerChanged

I'm new to scripting, so forgive me if this is a dumb question:

 

How do you call for an ObjectReference event in an ActiveMagicEffect script? I tried using OnItemAdded as well, but since it didn't point to any actor, it also didn't work. Do you define what the event points to in the event's parameters?

 

Thank you.

Edited by moopdog
Link to comment
Share on other sites

I've made it so it adds an ability to the target actor that monitors OnItemAdded with this script (ran on commanded actor):

Scriptname ft_CommandMonitorScript extends activemagiceffect  


Actor property MySelf Auto
Actor property PlayerRef Auto
ObjectReference property ItemTaken Auto


Event OnEffectStart(Actor akTarget, Actor akCaster)
Debug.Notification ("Started")
MySelf == akTarget
PlayerRef == Game.GetPlayer()
EndEvent


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
if akSourceContainer == None
ItemTaken == akItemReference
Debug.Notification(ItemTaken)
PlayerRef.AddItem(ItemTaken, 1)
endif
EndEvent


Event OnEffectFinish(Actor akTarget, Actor akCaster)
Debug.Notification ("Ended")
EndEvent

I've tried calling akBaseItem instead of akItemReference, referring to one of those parameters without the ItemTaken property, and just about everything else under the sun, but the second Debug.Notification always returns either "None" or "[Form", and the player never gets the item. The item doesn't have time to be properly targeted before its reference is picked up and therefor rendered invalid for functions. How do I make this work?

 

Link to comment
Share on other sites

I take it you have created a Magic effect and placed it on the dialogue follower alias?

 

Have you gotten the on item added event to fire?

 

Have you gotten the Started notification to appear?

Scriptname ft_CommandMonitorScript extends activemagiceffect  


Actor Myself

Event OnEffectStart(Actor akTarget, Actor akCaster)
Debug.Notification ("Started")
Myself = akTarget
EndEvent


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

Actor PlayerRef = Game.GetPlayer()

Debug.Notification("ItemTaken")
If akSourceContainer != PlayerRef
Myself.RemoveItem(akBaseItem, 1)
PlayerRef.AddItem(akBaseItem, 1)
endif
EndEvent

Edited by Masterofnet
Link to comment
Share on other sites

 

I take it you have created a Magic effect and placed it on the dialogue follower alias?

 

Have you gotten the on item added event to fire?

 

Have you gotten the Started notification to appear?

Scriptname ft_CommandMonitorScript extends activemagiceffect  


Actor Myself

Event OnEffectStart(Actor akTarget, Actor akCaster)
Debug.Notification ("Started")
akTarget = Myself
EndEvent


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

Actor PlayerRef = Game.GetPlayer()

Debug.Notification("ItemTaken")
If akSourceContainer != PlayerRef
Myself.RemoveItem(akBaseItem, 1)
PlayerRef.AddItem(akBaseItem, 1)
endif
EndEvent

Well, i'll be damned.

To answer your question--I had gotten the OnItemAdded event to fire, but it never properly caused any of the functions that follow to trigger (I think because of a lack of valid targets.)

Whatever you changed in my script, it works now. Only issue is that the RemoveItem isn't firing. It looks like you declared the actor properties differently to how I did--are those variables? I wonder if that was the issue.

Also, I have the ft_CommandMonitorScript running on a magic effect on an ability that is temporarily added to the target of the main spell effect via AddSpell, and yes, the Started notification has appeared consistently.

 

Thank you very, very much. Been trying to get this to work for a while.

Edited by moopdog
Link to comment
Share on other sites

I have updated it. Try it now.

 

 

Scriptname ft_CommandMonitorScript extends activemagiceffect



Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

Actor PlayerRef = Game.GetPlayer()

Debug.Notification("ItemTaken")
If akSourceContainer != PlayerRef
GetTargetActor().RemoveItem(akBaseItem, 1)
PlayerRef.AddItem(akBaseItem, 1)
endif
EndEvent

 

Edited by Masterofnet
Link to comment
Share on other sites

I have updated it. Try it now.

 

 

Scriptname ft_CommandMonitorScript extends activemagiceffect

 

 

 

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

 

Actor PlayerRef = Game.GetPlayer()

 

Debug.Notification("ItemTaken")

If akSourceContainer != PlayerRef

GetTargetActor().RemoveItem(akBaseItem, 1)

PlayerRef.AddItem(akBaseItem, 1)

endif

EndEvent

 

Yep, this script works flawlessly. I've found another problem now, though...

 

Scriptname ft_CommandScript extends activemagiceffect  


float TargetAV
Spell property MonitorAbility Auto


Event OnEffectStart(Actor akTarget, Actor akCaster)
TargetAV == akTarget.GetActorValue("Morality")
Debug.Notification("TargetAV is now " + TargetAV)
Debug.Notification("Morality was " + akTarget.GetActorValue("Morality"))
akTarget.AddSpell(MonitorAbility)
akTarget.SetActorValue("Morality", 0)
Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
akTarget.SetDoingFavor()
EndEvent


Event OnEffectFinish(Actor akTarget, Actor akCaster)
akTarget.SetActorValue("Morality", TargetAV)
Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
akTarget.SetDoingFavor(false)
akTarget.RemoveSpell(MonitorAbility)
EndEvent

This is the script I'm using for the effect of the spell itself. The MonitorAbility property points to the ability with the magic effect with the OnItemAdded monitor script. It compiles fine, but the TargetAV variable is never set to anything other than 0, even when the "Morality was" notification returns something that isn't 0 (3, in the case of the NPC i'm testing on). This results in the affected NPC never having their morality set back to normal--which is a problem. What the notifications tell me now:

 

TargetAV is now 0.[repeating zeroes] <- This is what's causing the issue. Should report 3.

Morality was 3.[repeating zeroes] <- Nothing wrong here.

Morality is now 0.[repeating zeroes] <- Sets morality to 0 so the actor will do whatever command you want. Nothing wrong here.

Morality is now 0.[repeating zeroes] <- Should also report 3, but doesn't because TargetAV reports 0 instead of 3.

 

Everything else in the script works exactly as intended.

Edited by moopdog
Link to comment
Share on other sites

Was a lot simpler than I expected it to be.

Scriptname ft_CommandScript extends activemagiceffect  

Spell property MonitorAbility Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
	;Debug.Notification("Morality was " + akTarget.GetActorValue("Morality"))
	akTarget.AddSpell(MonitorAbility)
if akTarget.GetActorValue("Morality") == 0
	akTarget.SetDoingFavor()
	akTarget.SetActorValue("Morality", 0)
	;Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
	Utility.Wait(25)
	akTarget.SetActorValue("Morality", 0)
endif
if akTarget.GetActorValue("Morality") == 1
	akTarget.SetDoingFavor()
	akTarget.SetActorValue("Morality", 0)
	;Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
	Utility.Wait(25)
	akTarget.SetActorValue("Morality", 1)
endif
if akTarget.GetActorValue("Morality") == 2
	akTarget.SetDoingFavor()
	akTarget.SetActorValue("Morality", 0)
	;Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
	Utility.Wait(25)
	akTarget.SetActorValue("Morality", 2)
endif
if akTarget.GetActorValue("Morality") == 3
	akTarget.SetDoingFavor()
	akTarget.SetActorValue("Morality", 0)
	;Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
	Utility.Wait(25)
	akTarget.SetActorValue("Morality", 3)
endif
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	;Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
	akTarget.RemoveSpell(MonitorAbility)
	akTarget.SetDoingFavor(false)
EndEvent

Since Morality only has four values (0 - 3) duplicating the code and having an if clause for each value works perfectly fine. (Note: the magic effect lasts 25 seconds, which is why thats how long it waits for.) Not the cleanest code, but in terms of gameplay it works flawlessly, so I can't complain. Thank you for all the help, @Masterofnet.

Link to comment
Share on other sites

I ain't done yet. You showed some initiative here.

Scriptname ft_CommandScript extends activemagiceffect  

Spell property MonitorAbility Auto

Int MoralityValue 

Event OnEffectStart(Actor akTarget, Actor akCaster)

       MoralityValue = akTarget.GetActorValue("Morality")

       akTarget.AddSpell(MonitorAbility)
       akTarget.SetDoingFavor()
       akTarget.SetActorValue("Morality", 0)

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	;Debug.Notification("Morality is now " + akTarget.GetActorValue("Morality"))
	akTarget.RemoveSpell(MonitorAbility)
        akTarget.SetActorValue("Morality", MoralityValue)
	akTarget.SetDoingFavor(false)
EndEvent
Edited by Masterofnet
Link to comment
Share on other sites

  • Recently Browsing   0 members

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