Jump to content

Player as target


Recommended Posts

I just realized I had added effects to consumables in the game without making sure they only apply if the player consumes them - now every time an NPC drinks or eats, I get the benefits.

 

I tried to simply put "If Target == Game.GetPlayer()" before my script (and endif at the end), but now I don't know how to declare the variable Target.

 

So how do I define "Target"?

Link to comment
Share on other sites

I'm assuming you have the script attached to the consumables. The vanilla potions which add unique, scripted effects use the OnEffectStart() event, attached to the potion's magic effect. So, whenever the potion is consumed, the game applies the "effect" to whoever consumed it (even if the effect doesn't actually exist). The script would recognize the consumer as the caster (second argument in the event) and you can then use that as your target.

 

For example, Vaermina's Torpor:

Event OnEffectStart(Actor akTarget, Actor akCaster)

	if akTarget == Game.GetPlayer()
		if Game.GetPlayer().GetParentCell() == pNightcaller
			utility.wait(0.1)
			pDA16Quest.SetStage(145)
		else
			pDA16Message.Show()
			Game.GetPlayer().AddItem(pDA16Torpor,1)
		endif
	endif

endEvent

and Esbern's Dragon Infusion:

Event OnEffectStart(Actor akTarget, Actor akCaster)

	If akTarget == Game.GetPlayer()
		Game.GetPlayer().AddPerk(MQBladesDragonResearch)
	EndIf
EndEvent
Edited by GreatSilentOne
Link to comment
Share on other sites

Actually, there is a script applied to the effect that's run as soon as the effect is applied to anyone:

ScriptName ScriptSkooma extends activemagiceffect

Spell Property SpellSkooma01 Auto
Spell Property SpellSkooma02 Auto
Spell Property SpellSkooma03 Auto
MagicEffect Property EffectSkooma01 Auto
MagicEffect Property EffectSkooma02 Auto
MagicEffect Property EffectSkooma03 Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)


If (Game.GetPlayer().HasMagicEffect(EffectSkooma03))
Game.GetPlayer().RemoveSpell(SpellSkooma03)
Game.GetPlayer().AddSpell(SpellSkooma01, false)
ElseIf (Game.GetPlayer().HasMagicEffect(EffectSkooma02))
Game.GetPlayer().RemoveSpell(SpellSkooma02)
Game.GetPlayer().AddSpell(SpellSkooma01, false)
ElseIf (Game.GetPlayer().HasMagicEffect(EffectSkooma01))
Game.GetPlayer().RemoveSpell(SpellSkooma01)
Game.GetPlayer().AddSpell(SpellSkooma01, false)
Else
Game.GetPlayer().AddSpell(SpellSkooma01, false)
Debug.Notification("You relapsed")
Endif

EndEvent

so no matter who the effect is applied to, the player always feels the effects... I thought I could fix this by checking if the player is actually the target of the effect. And there's my initial question again.

Link to comment
Share on other sites

Modified version:

 

 

ScriptName ScriptSkooma extends activemagiceffect

Spell Property SpellSkooma01 Auto
Spell Property SpellSkooma02 Auto
Spell Property SpellSkooma03 Auto
MagicEffect Property EffectSkooma01 Auto
MagicEffect Property EffectSkooma02 Auto
MagicEffect Property EffectSkooma03 Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
    If akTarget == Game.GetPlayer()
        If (akTarget.HasMagicEffect(EffectSkooma03))
            akTarget.RemoveSpell(SpellSkooma03)
            akTarget.AddSpell(SpellSkooma01, false)
        ElseIf (akTarget.HasMagicEffect(EffectSkooma02))
            akTarget.RemoveSpell(SpellSkooma02)
            akTarget.AddSpell(SpellSkooma01, false)
        ElseIf (akTarget.HasMagicEffect(EffectSkooma01))
            akTarget.RemoveSpell(SpellSkooma01)
            akTarget.AddSpell(SpellSkooma01, false)
        Else
            akTarget.AddSpell(SpellSkooma01, false)
            Debug.Notification("You relapsed")
        Endif
    EndIf
EndEvent 

 

 

Changes:

Compares akTarget to Game.GetPlayer(), if equal continues processing

Since akTarget is to equal Game.GetPlayer(), replaced all other instances of Game.GetPlayer() with akTarget. This reduces processing time.

 

akTarget is a variable that is pre-filled with data passed into by the game. You can use it without having to assign any data to it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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