Script to fire spell when player kills NPC.

Post » Mon Jun 18, 2012 11:39 pm

I need some help, I want to detect when the player kills and NPC but I cant seem to figure it out. There is no function to detect combat targets death, if you dont give a specific NPC ID!!!

Does anyone know how to do this?
User avatar
Beth Belcher
 
Posts: 3393
Joined: Tue Jun 13, 2006 1:39 pm

Post » Mon Jun 18, 2012 10:19 am

If I remember correctly, one of the things a perk can do it "add levelled item on death" (I hope it's still in Skyrim - can't check and don't have the CK on this computer). You could add a perk like that to the player to add a scripted token (unplayable, and therefore invisible armour) that runs your script.

Cipscis
User avatar
Chloe Botham
 
Posts: 3537
Joined: Wed Aug 30, 2006 12:11 am

Post » Mon Jun 18, 2012 9:46 pm

That sounds a little confusing, the unvisible token can detect when I kill someone? The add leveled item on death thing sounds like its specific to certain NPCs, I need it to be for anyone. I tried messing with GetPCMiscStat "People Killed" but it doesnt seem to work, im not sure i know how to use it :x
User avatar
Sxc-Mary
 
Posts: 3536
Joined: Wed Aug 23, 2006 12:53 pm

Post » Mon Jun 18, 2012 10:42 pm

Add leveled item on death is a type of perk entry. If the perk is on the player, you can run conditions on enemies to determine when items will be added.

For example, in Fallout 3, there was a perk that allowed you to collect ears from all (I think - it was condition based anyway) non-creature actors that you killed.

If the item that gets added is a scripted token, then the script could detect when it is added to an inventory and make the reasonable assumption that the player has just killed the actor whose inventory it's just been added to.

Cipscis
User avatar
Ally Chimienti
 
Posts: 3409
Joined: Fri Jan 19, 2007 6:53 am

Post » Mon Jun 18, 2012 7:04 pm

I only see Add Leved List on Death, and It doesnt seem automatically add an item to my inventory :x Uhg, maybe i should give this up.
User avatar
jess hughes
 
Posts: 3382
Joined: Tue Oct 24, 2006 8:10 pm

Post » Mon Jun 18, 2012 10:25 pm

That sounds right - just use a levelled list that only contains a single item.

I'm not sure, but there might be another perk using this entry in Skyrim.esm that you could look at for an example. I'm not particularly familiar with Skyrim's content, though.

Cipscis
User avatar
Noely Ulloa
 
Posts: 3596
Joined: Tue Jul 04, 2006 1:33 am

Post » Mon Jun 18, 2012 5:15 pm

Hmm OK so i got the item to be added to the NPC upon death, but how do i get the script on the item to run? Its too late to run OnDeath, OnDying, and OnItemAdded.
Also, when casting the spell, im not sure how to go about this. I know to use



Function Cast(ObjectReference akSource, ObjectReference akTarget = None) native
But can I make the player cast a healing spell for example on himself this way?

User avatar
Krystina Proietti
 
Posts: 3388
Joined: Sat Dec 23, 2006 9:02 pm

Post » Mon Jun 18, 2012 12:20 pm

Just use http://www.creationkit.com/OnInit, as the item you're adding will be created when the actor dies, so its OnInit event should run then.

I haven't played around with the http://www.creationkit.com/Cast_-_Spell function, but I'd try something like this:
MySpell.Cast(Game.GetPlayer(), Game.GetPlayer())

Cipscis
User avatar
Jeffrey Lawson
 
Posts: 3485
Joined: Tue Oct 16, 2007 5:36 pm

Post » Mon Jun 18, 2012 10:35 pm

Just use http://www.creationkit.com/OnInit, as the item you're adding will be created when the actor dies, so its OnInit event should run then.

I haven't played around with the http://www.creationkit.com/Cast_-_Spell function, but I'd try something like this:
MySpell.Cast(Game.GetPlayer(), Game.GetPlayer())

Cipscis
Hm, OnInit seems to run only once. The script runs when I take the perk, I get a message box telling me, but when I kill an NPC the item appears on them, but no script runs :/

I can get it to continuously update but I dont know how to check if the actor runing the script is dead or not... I have something like this, Im missing where to and how to define the spell and the isdead part.

    EVENT onInit()					   ; This event will run once, when the script is initialized        registerForUpdate(2)        gotoState ("polling")    endEVENT  STATE polling        EVENT onUpdate()               	 if IsDead() == 1 ;No idea how to refer to the actor running the script.            Debug.MessageBox("Script Triggered!")       	 MySpell.Cast(Game.GetPlayer(), Game.GetPlayer())        endif    endEVENTendSTATE
User avatar
Julie Serebrekoff
 
Posts: 3359
Joined: Sun Dec 24, 2006 4:41 am


Return to V - Skyrim