Jump to content

Trying to cast a spell on the player ondying() event


Recommended Posts

Posted

 

I have a reference alias script attached to the player and I am trying to cast a spell when the player dies. The event fires, but the spell apparently does not detect the player as a target. Not sure how to fix?

 

 

event ondying(actor akkiller)
if utility.randomint(1, 100) <= sac_hang_player_ondeath_probability_glob.getvalue() as int 
    debug.trace("sac_ starting to auto hang the player on dying")
    sac_ManooseHangAutohangSPL.cast(game.getplayer(), game.getplayer())
    debug.trace("sac_ auto hanged the player on dying")
endif 
endevent 

 

Trace file:

 

[01/10/2021 - 12:16:48PM] sac_ starting to auto hang the player on dying
[01/10/2021 - 12:16:48PM] Error: Cannot call Cast() on a None object, aborting function call
stack:
    [alias sac_autohang_player_alias on quest sac_autohang_quest (15003884)].sac_autohang_playeralias_script.OnDying() - "sac_autohang_playeralias_script.psc" Line ?
[01/10/2021 - 12:16:48PM] sac_ auto hanged the player on dying

 

 

Otherwise the spell works on the player just fine if it's not cast while the player is in bleedout state.

 

It does not matter if I cast the spell on game.getplayer(), or if I declare a variable and fill it oninit(), I get the same error.

 

Posted
On 1/10/2021 at 11:30 AM, SAC said:

Error: Cannot call Cast() on a None object, aborting function call

That Line suggest that the game.getPlayer() fuction doesn't work anymore after the player has died. try using "self.getRef()" or a variable that has the player-refernce cached.

  • 1 month later...
Posted

While I'm fairly new here, I can guess what you're trying to accomplish. I'm a user of your "Just Hang SSE" mod (good job on achieving the effects, btw!),, and I was curious as to exactly how it was accomplished.  Correct me if I'm wrong, as you wrote the script. What seems to happen, on player death is a clone is created, then hanged. The original player's alpha value is set to zero, making them invisible, and then freecam is enabled, to give the effect that the hanging body is the player. That's a clever way to do it, honestly.

 

Perhaps something could be done similar to how Alternate Actors handles it (I'm currently going through its scripts and documenting what they do to make them easier to read, and to understand scripting), but it seems to fade to its own "loading screen" bring in an actor from an unloaded cell, impose the player's traits onto this actor, transfer the player's inventory to this actor, kill this actor, applies ghost visuals to the player, and then removes its loading screen, leaving the corpse of the player character (sadly, with the dark face bug, unless you have face discoloration fix installed).

 

Again, correct me if I'm wrong, but what you're trying to do is avoid this whole cloning an actor thing, and not use the "OnenterBleedout" event, and figuring out how to attach or use an  "OnDeath" event to the player. I'm actually trying to figure out how to do a similar thing myself, as I'm working on a custom follower mod who is capable of resurrecting the player on their death. I'm not too sure how I'll approach this, hence why I'm analyzing alternate actor's scripts in depth.

 

As far as I can see though, another actor may be needed, as from a programming perspective, the player when alive is an object, and once they are dead, the object is destroyed. Hence why the "Cannot call Cast() on a None Object" error message. It's trying to call a function on an object that no longer exists... It's basically a Null Pointer Exception. This is another thing I'll have to figure out with my follower mod. I'm new to Papyrus scripting, but not to programming.

Posted
On 2/23/2021 at 2:10 AM, FoxinTale said:

While I'm fairly new here, I can guess what you're trying to accomplish. I'm a user of your "Just Hang SSE" mod (good job on achieving the effects, btw!),, and I was curious as to exactly how it was accomplished.  Correct me if I'm wrong, as you wrote the script. What seems to happen, on player death is a clone is created, then hanged. The original player's alpha value is set to zero, making them invisible, and then freecam is enabled, to give the effect that the hanging body is the player. That's a clever way to do it, honestly.

 

Correct on all counts (cleverness included :D )

 

On 2/23/2021 at 2:10 AM, FoxinTale said:

Perhaps something could be done similar to how Alternate Actors handles it (I'm currently going through its scripts and documenting what they do to make them easier to read, and to understand scripting), but it seems to fade to its own "loading screen" bring in an actor from an unloaded cell, impose the player's traits onto this actor, transfer the player's inventory to this actor, kill this actor, applies ghost visuals to the player, and then removes its loading screen, leaving the corpse of the player character (sadly, with the dark face bug, unless you have face discoloration fix installed).

 

Not sure I understand the benefits over the existing solution (besides the fade to black to cover for all the awkward standing around while waiting to be cloned

 

On 2/23/2021 at 2:10 AM, FoxinTale said:

Again, correct me if I'm wrong, but what you're trying to do is avoid this whole cloning an actor thing, and not use the "OnenterBleedout" event, and figuring out how to attach or use an  "OnDeath" event to the player. I'm actually trying to figure out how to do a similar thing myself, as I'm working on a custom follower mod who is capable of resurrecting the player on their death. I'm not too sure how I'll approach this, hence why I'm analyzing alternate actor's scripts in depth.

 

Yes, I wish that worked so I can avoid all the cloning lag. However, onenterbleedout never triggered for me, as far as I can remember

 

On 2/23/2021 at 2:10 AM, FoxinTale said:

As far as I can see though, another actor may be needed, as from a programming perspective, the player when alive is an object, and once they are dead, the object is destroyed. Hence why the "Cannot call Cast() on a None Object" error message. It's trying to call a function on an object that no longer exists... It's basically a Null Pointer Exception. This is another thing I'll have to figure out with my follower mod. I'm new to Papyrus scripting, but not to programming.

 

Looks that way, indeed

 

  • 3 weeks later...
Posted

Stumbled across this mod the other day. It seems to get an event to fire on the "OnDeath". May be of some use to pick apart and see how they did it.

Edit: I looked at it, and it's a "OnDying" event attached to the player, not an "OnDeath". However, they seem to serve similar purposes. 

 

  • 2 months later...
Posted

Update. Figured it out. I've made a mod that resurrects the player via script on death. What I did is create a quest in the CK, create a new quest alias (PlayerRef), and attach whatever script I wanted there. Since I'm pretty bad at explaining things, feel free to tear it apart, as I've included the mod I made here. It's an OnDying event, but it's worked pretty solidly. 

Player revival.zip

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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