Jump to content

Adding a potion effect to the player when the player kills an Actor


Recommended Posts

Hello. This is some of my first attempts at trying to do papyrus scripting. I am trying to create a magic effect, for an enchantment, that activates when the player kills an enemy. So, when a player kills an enemy, I want to apply either a spell or potion effect that gives them 10 secs of stealth field.

Scriptname StealthKillScript extends activemagiceffect

Potion Property StealthBoy auto const

Event OnDeath(Actor akKiller)
  if (akKiller == Game.GetPlayer())
	Function ApplyPotionToActor()
	Game.GetPlayer().EquipItem(StealthBoy)
	endfunction
   endif
endevent
 
 

 

Currently, I have this, which should, if I am doing this right, apply a stealth boy to the player when they kill an actor. The problem is, the compiler is giving me lip. I have two errors: "mismatched input 'Function' expecting ENDIF" and "mismatched input 'endfunction' expecting ENDEVENT". Does Papyrus just not let you place functions inside of events, or is there something else going on? Is what I am trying to do even possible?

 

Link to comment
Share on other sites

Yes, functions must be declared outside of events, then you use the function in an event, or another function. For this case I don't think you need the function at all. Just do:

 

Scriptname StealthKillScript extends activemagiceffect

Potion Property StealthBoy auto const

Event OnDeath(Actor akKiller)
if (akKiller == Game.GetPlayer())
    Game.GetPlayer().AddItem(StealthBoy, 1, 1) ;adds 1 stealthboy silently to player
    Game.GetPlayer().EquipItem(StealthBoy)
endif
endevent

I'm not sure the OnDeath event will work on the enchantment magic effect, but it's worth a try. If it doesn't work, have the enchantment magic effect add an ability to the target with the OnEffectStart event, then put the OnDeath event on the ability's magic effect.

Edited by dylbill
Link to comment
Share on other sites

I have tried many times to use .EquipItem as a quick way to apply effect potions like Stimpak and Stealthboy to the player and other actors.

 

Has never worked for me.

 

Have always ended up packaging the MGEF Magic effect as a Spell or Perk to apply in script .AddSpell or .Addperk which works fine.

Link to comment
Share on other sites

Okay, so I tried that new version of the additem script. It did not work. I have already tried using the AddSpell command, but I may not have used it correctly.

Scriptname StealthKillScript extends activemagiceffect

Spell Property StealthKill auto const

Event OnDeath(actor Killer)
  if (Killer == Game.GetPlayer())
      Game.GetPlayer().AddSpell(StealthKill)
	
   endif
endevent


This is what I had wrote. StealthKill is just a spell that applies the ChamelonEffectStealthBoy for 10 seconds. I also attached this magic effect to an enchantment I have applied to a weapon OMOD. If you don't mind, could you elaborate on what you mean adding it as an ability using OnEffectStart?

Edited by FlamingLlama926
Link to comment
Share on other sites

I mean, I don't think enchantments on weapons have a duration. So, you hit someone with a weapon, the enchantment applies to that actor and the magic effect immediatly ends, which means the OnDeath event isn't firing because the magic effect is no longer active on the enemy. So what you do, is make a new ability with a new magic effect and put the script with the OnDeath Event on that. Actually a better way would be to use a spell with a duration of let's say 30 seconds, and cast it on the target.

 

Oh also for spells you want to use Cast instead of AddSpell. You can use AddSpell for abilities though.

 

Like this

Scriptname StealthKillScriptA extends ActiveMagicEffect 

;This script goes on the enchantment magic effect

Spell Property OnDeathSpell auto ;spell with 30 second duration 

Event OnEffectStart(Actor akTarget, Actor akCaster)
    OnDeathSpell.Cast(akCaster, akTarget)
EndEvent
Scriptname StealthKillScript extends activemagiceffect
;This script goes on the spell's magic effect from above.
;If target dies within 30 seconds, stealth is applied to player
;Otherwise nothing happens.

Spell Property StealthKill auto const

Event OnDeath(actor Killer)
  if (Killer == Game.GetPlayer())
      StealthKill.Cast(Game.GetPlayer(), Game.GetPlayer())
   endif
endevent

Oh, and you should put some Debug.Notification("Some Text") in to make sure the script is firing.

Edited by dylbill
Link to comment
Share on other sites

Okay, so, that did not seem to work. It is highly likely I messed something up. I did add debug notifications into the code, and none popped up when I killed someone with the enchanted weapon. So, let me try to get this straight: The first script goes into a new magic effect, which is the one that I want to link to my spell. That magic effect casts a new spell that does something. Then, the second script goes into the magic effect I have linked to my enchantment, and casts the spell with the caster being the player, and the target also being the player. If I have this written out right, this is what I did. I am sorry, I feel like I am not connecting the dots on something I should be understanding.

Edited by FlamingLlama926
Link to comment
Share on other sites

  • Recently Browsing   0 members

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