Intercept Player OnDeath Event... Help

Post » Sat Nov 17, 2012 4:30 am

I'm a noob with Papyrus, but I do programming for a living, so I'm already familiar with the logic and terms. However, I'm totally lost as far as where to begin with my mod... I want to execute some code when the player dies, basically preventing the death entirely, but still play the death animation. To be specific, I'd like the screen to fade to black upon player death and then have the player transfered to another location. Is that even possible? I've tried attaching a script to the Player entity (in Actors > Actor), but no dice. Nothing fires. I read on here that I may need to setup a hidden quest and execute the code on an actor alias?? No idea how to do that. I got as far as being able to create a Quest "object" in CK and being able to attach a script to it, but again, I've no idea what I'm doing really. Can someone help me? Thanks.
User avatar
Jennifer Rose
 
Posts: 3432
Joined: Wed Jan 17, 2007 2:54 pm

Post » Fri Nov 16, 2012 11:52 pm

Make a new quest and edit it, when you edit it there should be a tab that says Alias. Go to that tab and create a new Alias, make the Alias a specific actor and then click the select forced actor button and then a box should pop up. For cell choose "any" and then in the reference box choose player Ref. After that you've got the player as a Alias and can now attach a script to him. When the game loads the script will be on the player unless the quest is stopped, make sure that you have "start game" enabled on the first tab. This means that when you run the game the quest will start up automatically. Hope that helps. :biggrin:
User avatar
Ross Zombie
 
Posts: 3328
Joined: Wed Jul 11, 2007 5:40 pm

Post » Fri Nov 16, 2012 9:10 pm

I know how to do the alias bit, but I'm not too sure about the script you'll need. Reason being, when the player dies, the game usually automatically reloads the last save. You might have to teleport the player when he's nearly dead instead, unfortunately something I'm not too clued in on.

Anyway, here's how to set up the alias:

1. Make a new quest, give it a name and tick "start game enabled" (or something along those lines). Then click ok, exiting the window, so that the ck generates the rest of the quest window
2. Go back into your quest, navigate to the quest alias tab. Right-click and create a new reference alias.
3. Give it a name. Fill it with the player reference (Cell= (any), Actor= Player). This is where you'll be placing your teleport script. If you cannot see the "ok" button, just click on the name box with your mouse, hold shift and press tab twice, then hit enter

You'll need somebody more fluent in papyrus to help you with the actual scripting part. At least your half way there

- Hypno

EDIT: I got ninja'd
User avatar
Queen
 
Posts: 3480
Joined: Fri Dec 29, 2006 1:00 pm

Post » Sat Nov 17, 2012 6:41 am

You might have to teleport the player when he's nearly dead instead, unfortunately something I'm not too clued in on.

Setting the player alias to essential and then using the OnEnterBleedout event works. Then you could use an ImageSpaceModifier ot two to make the player seem to black out before teleporting them elsewhere.
User avatar
Vahpie
 
Posts: 3447
Joined: Sat Aug 26, 2006 5:07 pm

Post » Fri Nov 16, 2012 10:07 pm

EDIT: Nevermind :) Changed ObjectReference to ReferenceAlias, duh.

Thanks everybody! Truly appreciate the help. However, I've attached this script to the Reference Alias, but it never seems to fire -- I don't get a message.

Scriptname LeftForDeadScript extends ObjectReference

Actor Property playerRef auto

Event OnEnterBleedout()
Debug.MessageBox("I'm dying!")
EndEvent

Not sure what I'm doing wrong now. Was the script supposed to be attached to the Quest instead?
User avatar
Chica Cheve
 
Posts: 3411
Joined: Sun Aug 27, 2006 10:42 pm

Post » Sat Nov 17, 2012 2:36 am

It's fine on the alias, but actually I think I was wrong about making the alias essential - I think that makes the 'taking a knee' animation kick in when you don't want it. I did stuff in an alias script to make the player die in stages, as it were, and then teleport them - the vital bit looked like this:


Event OnEnterBleedout()	   GotoState("Dying")endEvent;================================================State Dying;================================================Event OnBeginState()			 Player.SetGhost(True)			 Player.ForceActorValue("Health", 2.0)			 Game.ShakeCamera(Player, 5, 0.1)			 Utility.Wait(3)			 BlackOutImod.ApplyCrossFade(15.0)			 GetReference().MoveTo(DungeonMarker)			 Utility.Wait(8)			 ImageSpaceModifier.RemoveCrossFade(6.0)			 Player.SetGhost(False)endEventEvent OnEnterBleedout()endEventendState
User avatar
Josh Dagreat
 
Posts: 3438
Joined: Fri Oct 19, 2007 3:07 am

Post » Sat Nov 17, 2012 6:20 am

You weren't wrong about making the alias essential, I made the player essential and then used an OnDying script. OnDying looks for when the players health gets to a certain amount, unfortunately that amount is incredibly low so the enemy almost always finishes him off instead. That is why making them essential was needed, but the script you posted above seems to work as well.
User avatar
daniel royle
 
Posts: 3439
Joined: Thu May 17, 2007 8:44 am

Post » Sat Nov 17, 2012 6:38 am

@Ingenue: Thanks for your help, but when I uncheck the Essential flag, I am unable to prevent the game from reloading the last save... Only if Essential is on, will it not do so, but then I of course get the kneeling animation... Any ideas?
User avatar
Kate Norris
 
Posts: 3373
Joined: Mon Nov 27, 2006 6:12 pm

Post » Fri Nov 16, 2012 6:44 pm

So when I did this, I made the player teleport somewhere when they were killed. To do this I used a OnDying script and made the player essential. I made them essential because the OnDying health count is so low that the player would die before the script goes off causing the last save to be loaded. So I made them essential and used a script like this:
Event OnDying(Actor akKiller)Game.GetPlayer().RestoreActorValue("health", 100)Game.GetPlayer().MoveTo(Marker01)Debug.MessageBox("You've been killed!")EndEvent

What this does is restore 100 health points to the player when they die/ kneel down. This is because if I don't then the player will be teleported in bleed out mode and will never get up. By restoring some health the player is no longer in bleed out mode once they are teleported, and are greeted with a message box informing them that they have been killed. You of course still need to attach this to a quest using the player as an Alias for this to work otherwise the script won't fire when the player dies and will be stuck in bleed out mode forever unless they take a healing potion.
User avatar
Tyler F
 
Posts: 3420
Joined: Mon Aug 27, 2007 8:07 pm

Post » Sat Nov 17, 2012 3:20 am

Thanks SteezMyster, but I don't understand the MoveTo function. I don't get where Marker01 comes from. I'm guessing it should be a variable/property, but I don't really get why I can't do "Game.GetPlayer().MoveTo(Riverwood)" like when I do "COC Riverwood" in console... Although I would prefer moving to a random exterior location, maybe within a certain radius of where you were killed, if that's possible. Or even the nearest inn would be good, too. Maybe that is easier.

This code does NOT work. It just keeps reloading the last save. I DO get the message, so it's firing, but again, the last save just gets reloaded. And if I set the actor as essential (by checking checkbox on alias), then OnDying doesn't fire.

Scriptname LeftForDeadScript extends ReferenceAlias  ObjectReference Property WhiterunBanneredMare AutoEvent OnEnterBleedout()	EndEventEvent OnDying(Actor akKiller)	Game.GetPlayer().GetActorBase().SetEssential(True)	Game.GetPlayer().RestoreActorValue("health", 100)	Game.GetPlayer().MoveTo(WhiterunBanneredMare)	Debug.MessageBox("You've been killed!")EndEvent

EDIT:

This code works, except the MoveTo function. Nothing happens.

Scriptname LeftForDeadScript extends ReferenceAlias  ObjectReference Property WhiterunBanneredMare AutoEvent OnEnterBleedout()    Game.GetPlayer().RestoreActorValue("health", 100)    Game.GetPlayer().MoveTo(WhiterunBanneredMare)EndEventEvent OnDying(Actor akKiller)    EndEvent
User avatar
jessica Villacis
 
Posts: 3385
Joined: Tue Jan 23, 2007 2:03 pm

Post » Sat Nov 17, 2012 5:43 am

Did you select the property for the WhiterunBanneredMare property? The Marker01 was a Xmarker heading that I placed somewhere in Skyrim, for the Marker01 Property I selected that Xmarker so when the player died he was teleported to the xmarker. The MoveTo function isn't like COC, you have to actually put in a property for it meaning that the whiterunbanneredmare property would have to point an object that you are teleporting to.
User avatar
BRAD MONTGOMERY
 
Posts: 3354
Joined: Mon Nov 19, 2007 10:43 pm

Post » Sat Nov 17, 2012 1:18 am

Did you select the property for the WhiterunBanneredMare property? The Marker01 was a Xmarker heading that I placed somewhere in Skyrim, for the Marker01 Property I selected that Xmarker so when the player died he was teleported to the xmarker. The MoveTo function isn't like COC, you have to actually put in a property for it meaning that the whiterunbanneredmare property would have to point an object that you are teleporting to.

Yes, I selected the cell WhiterunBanneredMare from the cell list for the property, and the "XMarkerHeading 0010C076" object and I've tried all the other XMarkers in there... Still nothing happens. Is it because someone is trying to attack the player?

EDIT: Okay, should the property type be ObjectReference or something else??
User avatar
gemma
 
Posts: 3441
Joined: Tue Jul 25, 2006 7:10 am

Post » Sat Nov 17, 2012 8:21 am

It should be an object reference, try making a new Xmarker and see if that works.
User avatar
Joie Perez
 
Posts: 3410
Joined: Fri Sep 15, 2006 3:25 pm

Post » Fri Nov 16, 2012 7:17 pm

Stupid me, forgot to enable script logging. Here is the error. Any further ideas? I'm not sure what to do now... Thanks. That's with only the MoveTo function enabled (anything else has been commented out). Not sure why the game is saying the player is dead, when they are set to essential, and this error pops up on while the character is kneeling...

error: Cannot move the player because they are deadstack:    [ (00000014)].Actor.MoveTo() - "" Line ?    [alias LeftForDeadQuestAlias on quest LeftForDeadQuest (30000D62)].LeftForDeadScript.OnEnterBleedout() - "LeftForDeadScript.psc" Line 7

EDIT: ... And the magic ingredient to getting it to work.... Utility.Wait(3)! Grr...
User avatar
adame
 
Posts: 3454
Joined: Wed Aug 29, 2007 2:57 am

Post » Fri Nov 16, 2012 10:55 pm

I got the MoveTo working, but how would I do a MoveTo on a bed and have the player visibly sleep in the bed and upon fading in to game, have the player get out of bed... Additionally, I'd like to have several hours pass in-game...
User avatar
JUan Martinez
 
Posts: 3552
Joined: Tue Oct 16, 2007 7:12 am

Post » Fri Nov 16, 2012 8:54 pm

So I'm going through Madmole's discussions on here, and apparently, I can just do a MoveTo on the bed and the player will be in bed... Now I just need to know how to play the get-out-of-bed animation...

EDIT: Actually, the getting-out-of-bed animation I don't really need, I think. It's good enough just to see the player sleep in bed. Pressing the Activate key or probably any key, makes the player play the get-out-of-bed animation. That was easy :)
User avatar
vicki kitterman
 
Posts: 3494
Joined: Mon Aug 07, 2006 11:58 am

Post » Sat Nov 17, 2012 7:29 am

Just have the object reference activate the player to get the player out of bed:

self.activate(game.getplayer(), true)

So now I have a question, how do you get OnEnterBleedout to fire for the player? I want to call a function when the player is bleeding out but I can't seem to get it to work.

Edit: Hmmm it seems it won't work on a quest script even though it compiles, it has to be on a reference alias script.
User avatar
Lucy
 
Posts: 3362
Joined: Sun Sep 10, 2006 4:55 am

Post » Fri Nov 16, 2012 8:58 pm

Thanks for the info. Will try that :)

OnEnterBleedout is weird. It only fires if player is essential, at least as far as I've been able to tell. I'm using a quest with a reference alias for the player and then I put the script on the reference alias.
User avatar
Natasha Biss
 
Posts: 3491
Joined: Mon Jul 10, 2006 8:47 am

Post » Fri Nov 16, 2012 5:53 pm

If you think about it, it kind of makes sense.

The only time I've seen an actor enter bleed out (drop to one knee) is when they are an essential follower.

I think it's hard-coded that only essential actors receive this event, hence the need to have the player set as essential.

- Hypno
User avatar
Ashley Campos
 
Posts: 3415
Joined: Fri Sep 22, 2006 9:03 pm


Return to V - Skyrim