Best way to detect a players death?

Post » Mon Jun 18, 2012 7:34 am

I'm trying to prevent and change the death event for the player for a mod I'm making, however I'm having trouble figuring out how to make that work.

The player is an actor, and actors have the "OnDeath" and "OnDying" events available to them. I could simply run a script directly on the player, and then run code off of those events, but I feel like attaching scripts to the player is one of those "nono's" for modding, and that I should use a different method.

The other possibility is to create an OnUpdateGameTime() event within another script, and then use a reference to the player to detect his death. While that is the most logical solution, I'm worried about the delay involved in doing so, especially because it could possibly not be run within the duration of the players death animation.

Anyone have any ideas or suggestions here?
User avatar
Scott
 
Posts: 3385
Joined: Fri Nov 30, 2007 2:59 am

Post » Mon Jun 18, 2012 3:11 am

I'm trying to prevent and change the death event for the player for a mod I'm making, however I'm having trouble figuring out how to make that work.

The player is an actor, and actors have the "OnDeath" and "OnDying" events available to them. I could simply run a script directly on the player, and then run code off of those events, but I feel like attaching scripts to the player is one of those "nono's" for modding, and that I should use a different method.

The other possibility is to create an OnUpdateGameTime() event within another script, and then use a reference to the player to detect his death. While that is the most logical solution, I'm worried about the delay involved in doing so, especially because it could possibly not be run within the duration of the players death animation.

Anyone have any ideas or suggestions here?
perhaps do the latter, but instead of checking for death, check for extremely low hp. Then If you make your mod set the player as immortal, timing shouldn't be an issue.
User avatar
saxon
 
Posts: 3376
Joined: Wed Sep 19, 2007 2:45 am

Post » Sun Jun 17, 2012 6:14 pm

You could use a quest to attach the script to, then set OnUpdate to .1 (Or some other small number) so it updates often enough to check for HP differences. Then just check for HP < 1 or something. I'm doing something similar to this for my berserker mod, so feel free to look at the source code I've got over in my thread if you need ideas on syntax or whatever: http://www.gamesas.com/topic/1343936-need-help-with-scripting-berserker-mod/
User avatar
Dragonz Dancer
 
Posts: 3441
Joined: Sat Jun 24, 2006 11:01 am

Post » Mon Jun 18, 2012 8:29 am

perhaps do the latter, but instead of checking for death, check for extremely low hp. Then If you make your mod set the player as immortal, timing shouldn't be an issue.

A possible idea, but I feel like it has similar issues. OnUpdateGameTime() requires that it be registered before use. Leaving it on all the time doesn't seem like the best idea but if there is no choice I suppose I'll have to do that. The check for extremely low hp would essentially be run at the same time that the death check would occur. It adds a brief moment perhaps, but it's still setting itself up for another death check ran at the same speed as the previous check. It just doesn't seem reliable, as there's still a possibility that the player could die before even this is checked.

Is there a more reliable way of performing the death check besides relying on "OnUpdateGameTime()" ?
User avatar
TWITTER.COM
 
Posts: 3355
Joined: Tue Nov 27, 2007 3:15 pm

Post » Mon Jun 18, 2012 8:56 am

You could use a quest to attach the script to, then set OnUpdate to .1 (Or some other small number) so it updates often enough to check for HP differences. Then just check for HP < 1 or something. I'm doing something similar to this for my berserker mod, so feel free to look at the source code I've got over in my thread if you need ideas on syntax or whatever: http://www.gamesas.com/topic/1343936-need-help-with-scripting-berserker-mod/

This was essentially my plan, but I do worry about possible performance issues when setting the number so low like that. This will especially be the case as more mods begin to use similar checks, all checking in frequent intervals. I suppose we did something similar in oblivion but I guess the unfamiliarity with the new language is making me paranoid.
User avatar
victoria gillis
 
Posts: 3329
Joined: Wed Jan 10, 2007 7:50 pm

Post » Mon Jun 18, 2012 2:29 am

Bump
User avatar
Angela
 
Posts: 3492
Joined: Mon Mar 05, 2007 8:33 am

Post » Mon Jun 18, 2012 7:54 am

You'd be much better off using a script on the player (or, better, making a quest and putting the player in an alias on the quest, and using a ReferenceAlias script), and watching for the OnDeath/OnDying events.

Papyrus is threaded, and so it only gets as much processor time as it gets - if you have update loops faster than they can be processed, you can bog down all scripts in the whole game.

Or, make the player Essential, and then do whatever you want when his HP gets low or watch for the OnEnterBleedout event. (This is how the brawling works - the quest makes the player temporarily essential during the brawl.)
User avatar
Noely Ulloa
 
Posts: 3596
Joined: Tue Jul 04, 2006 1:33 am

Post » Mon Jun 18, 2012 2:32 am

You'd be much better off using a script on the player (or, better, making a quest and putting the player in an alias on the quest, and using a ReferenceAlias script), and watching for the OnDeath/OnDying events.

Papyrus is threaded, and so it only gets as much processor time as it gets - if you have update loops faster than they can be processed, you can bog down all scripts in the whole game.

Or, make the player Essential, and then do whatever you want when his HP gets low or watch for the OnEnterBleedout event. (This is how the brawling works - the quest makes the player temporarily essential during the brawl.)

Interesting tip regarding the onenterbleedout event, that may be what I end up doing. However, I don't think I'm really seeing it as you're describing.

Assuming that I want to make the player essential and then watch "OnEnterBleedOut", wouldn't that code also have to be run on the player, or am I just not understanding events properly?
User avatar
daniel royle
 
Posts: 3439
Joined: Thu May 17, 2007 8:44 am

Post » Mon Jun 18, 2012 6:10 am

You'd be much better off using a script on the player [cut]
How do you assign a script to the player, i can't see it in the ck :(
User avatar
Cameron Wood
 
Posts: 3384
Joined: Wed Oct 31, 2007 3:01 pm

Post » Mon Jun 18, 2012 6:37 am

How do you assign a script to the player, i can't see it in the ck :(

I have been wondering this as well.
User avatar
Averielle Garcia
 
Posts: 3491
Joined: Fri Aug 24, 2007 3:41 pm

Post » Mon Jun 18, 2012 8:40 am

Object Window->Actors->Actor->Player -- that's the player base actor, you can attach a script to that. Or you can create a quest, make a ReferenceAlias and use Force Fill to point directly to the player reference (select any cell and you'll see the Player in the reference list). Then attach a script to that alias.
User avatar
neil slattery
 
Posts: 3358
Joined: Wed May 16, 2007 4:57 am

Post » Mon Jun 18, 2012 6:02 am

Object Window->Actors->Actor->Player -- that's the player base actor, you can attach a script to that. Or you can create a quest, make a ReferenceAlias and use Force Fill to point directly to the player reference (select any cell and you'll see the Player in the reference list). Then attach a script to that alias.
thank you! :)
User avatar
Jade Muggeridge
 
Posts: 3439
Joined: Mon Nov 20, 2006 6:51 pm

Post » Mon Jun 18, 2012 7:10 am

Object Window->Actors->Actor->Player -- that's the player base actor, you can attach a script to that. Or you can create a quest, make a ReferenceAlias and use Force Fill to point directly to the player reference (select any cell and you'll see the Player in the reference list). Then attach a script to that alias.

So if my quest script includes an "OnEnterBleedout" event and there is a referencealias for the Player within the script, will it run properly?

I'm testing this within my mod and I can't seem to get it to work properly.

(I have an alias set up as you instructed within the quest, and I have declared the property within the script.)

This is my code:
Event OnInit()	Player = Player_Alias.GetActorReference()EndEventEvent OnEnterBleedOut()		Debug.Messagebox("This is actually running.")	If Player.GetAV("health") < 1		Debug.Messagebox("You Died.")		Player.Resurrect()		Player.SetAV("Health", 10)		Game.ForceFirstPerson()		Player.Moveto(LichDeathMarker)	Endif  EndEventFunction MakePlayerEssential()	Player.GetActorBase().SetEssential()EndFunctionReferenceAlias Property Player_Alias AutoActor Property Player Auto

I have manually set the Player_Alias property to the Alias I created within the quest too. When using this code, there are no errors, but it does not run properly. It seems as though the Player actor isn't actually pointing to the player, and anything applied to it does absolutely nothing (However if I use Player = Game.GetPlayer() it works just fine)
Additionally, when testing the code and setting Player to Game.GetPlayer() I was able to make the PC Essential, but he never stands up after being "killed" (Is that normal?), and the code for the OnEnterBleedout event never runs.
User avatar
Maya Maya
 
Posts: 3511
Joined: Wed Jul 05, 2006 7:35 pm

Post » Mon Jun 18, 2012 5:56 am

The OnEnterBleedout event needs to be on a script on the player - so in your case, on a script that extends ReferenceAlias and put on your player alias. That script can simply call a function on your quest if you want to keep things mostly centralized, using this sort of syntax:

(GetOwningQuest() as MyQuestScript).MyFunctionToRespondToPlayerEnteringBleedout()
User avatar
Czar Kahchi
 
Posts: 3306
Joined: Mon Jul 30, 2007 11:56 am

Post » Sun Jun 17, 2012 8:32 pm

Yeah I've not had luck with getting scripts to work when I attach them to the player entitiy either. I have a suspicion that this entity is only "called" for at the start of a new game, so as long as you have a new game it'll work but not on existing characters. So I'm going to attempt to instead use the quest method instead to attach the script to the player for the one I'm working on (it adjusts player walk speeds).
User avatar
Sweet Blighty
 
Posts: 3423
Joined: Wed Jun 21, 2006 6:39 am

Post » Mon Jun 18, 2012 5:17 am

The OnEnterBleedout event needs to be on a script on the player - so in your case, on a script that extends ReferenceAlias and put on your player alias. That script can simply call a function on your quest if you want to keep things mostly centralized, using this sort of syntax:

(GetOwningQuest() as MyQuestScript).MyFunctionToRespondToPlayerEnteringBleedout()

Ohhh Ok, I didn't know I could attach scripts to the Quest Aliases, thanks, this should help.
User avatar
krystal sowten
 
Posts: 3367
Joined: Fri Mar 09, 2007 6:25 pm

Post » Mon Jun 18, 2012 6:53 am

You'd be much better off using a script on the player (or, better, making a quest and putting the player in an alias on the quest, and using a ReferenceAlias script), and watching for the OnDeath/OnDying events.
Or, make the player Essential, and then do whatever you want when his HP gets low or watch for the OnEnterBleedout event. (This is how the brawling works - the quest makes the player temporarily essential during the brawl.)
The fact that we can do these things is awesome! Thanks for posting, I'm glad I saw this.

Cipscis
User avatar
herrade
 
Posts: 3469
Joined: Thu Apr 05, 2007 1:09 pm

Post » Mon Jun 18, 2012 12:48 am

Hmm. Could anyone reference one of the brawl quest ID's to me so I could look at the code? It seems I'm still having issues.

In my main quest script, I am making the player essential from the get-go so they can't ever die.

The quest code looks something like this.
Event OnInit()	Player = Game.GetPlayer()EndEventFunction MakingThePlayerEssential()   Player.GetActorBase().SetEssential()EndFunction

And the ReferenceAlias script for the player looks like this:
Event OnEnterBleedout()	Debug.Messagebox("This is actually running.")	(GetOwningQuest() as QuestScript).QuestFunction()	EndEvent

Both scripts compile, but I'm getting some wonky behavior. First off, when the player is "killed" he simply lays there indefinitely, he never actually stands back up. This isn't such a big deal, as I plan to modify his health in the QuestFunction() Function. However, I never see the actual messagebox for OnBeginBleedingOut(), which tells me that the code isn't ever being ran. If anyone knows what's wrong or can direct me towards a quest where the player is made essential, that would be a great help.
User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm

Post » Sun Jun 17, 2012 11:02 pm

Hm, for some reason OnEnterBleedout() does not occur, even though I'm in a downed state as an essential npc.

When switching the code over to the OnDying() event however, the code ran perfectly( OnDeath() worked as well). It seems I'll be using this for now.
User avatar
Manuela Ribeiro Pereira
 
Posts: 3423
Joined: Fri Nov 17, 2006 10:24 pm

Post » Sun Jun 17, 2012 10:49 pm

My testing on OnEnterBleedout :
It will trigger on a base actor if the base actor is set to essential.
It will trigger on a Unique Reference Alias to actor if the base actor is set to essential.
It will trigger on a Forced reference alias to actor only if the "essential" checkbox is checked. Otherwise it will not trigger, even if the base actor is set to essential.
I dont know of any function to set a Reference Alias of actor to essential through a script.
(tests were only on ReferenceAlias to "Player")
User avatar
helliehexx
 
Posts: 3477
Joined: Fri Jun 30, 2006 7:45 pm

Post » Mon Jun 18, 2012 9:21 am

I would:

1. Setup a (hidden) quest to handle the death event(s) ... No Objectives, no Journal Entries
2. Use the "StoryManager" and "Events System" to watch for the death event (with condition of Player)
3. Tie the hidden Quest to the Events

http://www.creationkit.com/Story_Manager

It depends exactly what you want to do, but the SM-Events make it easy to have the trigger(s) and a hidden Quest means you can script what you like on the Alias (PC).
User avatar
Angelina Mayo
 
Posts: 3427
Joined: Wed Jan 24, 2007 4:58 am


Return to V - Skyrim