Papyrus: checking if player killed actor then do something

Post » Thu Jun 21, 2012 10:07 am

Hi,

I'm new to Papyrus and I am creating a script that checks if the player killed the actor.
If so, it will do something. If not, it will resurrect my actor.
But, I don't know how to properly do this. At least, it is not working.

Here is my code:
Scriptname A_LodronsBOSSLich_Death extends ObjectReference  {handles the WHOLE BOSS!}Actor Property Player AutoInt Property BossKiller Auto Conditional ; 0 = unset, 1 = player, -1 not the playerInt Property AResurrected == 1 Auto ConditionalSpell Property REVIVESPELL AutoEvent OnDeath(Actor akKiller)BossKiller == 0BossKillerWho()if BossKiller == -1	  if AResurrected == 1	   ;do nothing here	  else			REVIVESPELL.Cast(Self, Self)			AResurrected == 1	  endif	  else   	  Debug.Trace("Not killed by player, can't revive boss.")endIfEndEVENTFunction BossKillerWho(); check if the player killed the boss or something elseif Player == Game.GetPlayer()		 BossKiller == 1		 Debug.Trace("Player killed the boss.")	  else		 BossKiller == -1		 Debug.Trace("Something else killed the boss.")endIfEndFunction

I'd appreciate if you could help me.
I guess the Player Property isn't working as intended.

Thanks in advance.
User avatar
Marnesia Steele
 
Posts: 3398
Joined: Thu Aug 09, 2007 10:11 pm

Post » Thu Jun 21, 2012 11:23 pm

Function BossKillerWho(); check if the player killed the boss or something elseif Player == Game.GetPlayer()				 BossKiller == 1				 Debug.Trace("Player killed the boss.")		  else				 BossKiller == -1				 Debug.Trace("Something else killed the boss.")endIfEndFunction

The Player property is always going to equal the Player unless you tell the script to change it (which you are not), so only the first portion of your If statement will ever execute.

Here's what I think you are trying to do:

Spell property ReviveSpell AutoActor property MyBoss AutoBool ResurrectedEvent OnDeath(Actor akKiller)   If Resurrected	  ;do nothing.   Else	  If akKiller != game.getPlayer()		 ReviveSpell.Cast(MyBoss, MyBoss)		 Resurrected = True	  EndIf   EndIfEndEvent
User avatar
Patrick Gordon
 
Posts: 3366
Joined: Thu May 31, 2007 5:38 am

Post » Thu Jun 21, 2012 11:01 pm

The Player property will point to whatever you fill it with in the Creation Kit. If you fill it with the PlayerRef, then if Player == Game.GetPlayer() will always be true. What you actually want to find out, assuming this script is running on your possible victim, is whether the akKiller actor is the same as Player.

Event OnDeath(Actor akKiller)   if akKiller == Player      etc

But OnDeath is an event of an Actor, not an ObjectReference.
User avatar
Rhi Edwards
 
Posts: 3453
Joined: Fri Jul 28, 2006 1:42 am

Post » Thu Jun 21, 2012 6:48 pm

ScriptName A_LodronsBOSSLich_Death extends Actor Bool bResurrected = TrueActor Property PlayerREF AutoSpell Property ReviveSpell AutoEvent OnDeath(Actor akKiller)	If akKiller == PlayerREF		If !bResurrected			bResurrected = True			ReviveSpell.Cast(Self)		EndIf	EndIfEndEvent
  • 'PlayerREF' is the Player's EditorID. Player won't auto-fill 'cause it doesn't exactly match a form with an EDID.
  • The OnDeath Event has all you need to determine if the player killed the lich. You won't need a custom function
  • 'Player == Game.GetPlayer()', had that property been working, would have always returned True as they're one and the same
  • Extend Actor rather than ObjectReference. Actor can use all ObjectReference can and more.
  • If using Cast for a 'Self' archetype spell, you shouldn't need to include the second argument.
  • No need for the 'Conditional' unless checking the values with a message box or whatever.
  • For determining if resurrected, a bool seems to make more sense
User avatar
katsomaya Sanchez
 
Posts: 3368
Joined: Tue Jun 13, 2006 5:03 am

Post » Thu Jun 21, 2012 11:55 am

I didn't go through your script to see what you're doing but I thought I would show you a simple script that adds a key to the NPC after the player kills him/her:

Scriptname AddItemKeyOnDeathScript extends Actor  {ONLY ADD A KEY TO ACTOR!}Key property _KeyToAdd Autoauto STATE WaitingToBeActivatedEvent OnDeath(Actor killer)    Self.AddItem(_KeyToAdd)EndEventEndStateSTATE done    ;done doing stuffendSTATE

As I said...very small and simple and may give you an idea....or not :)
User avatar
Robert Jackson
 
Posts: 3385
Joined: Tue Nov 20, 2007 12:39 am


Return to V - Skyrim