Quote: "1. Entity leaves behind a corpse until the player comes within a certain distance."
Does the player kill the entity or does it die from another source somehow?
Quote: "2. When the player comes within touching distance, the entity activates the key that I place somewhere in the level "
This is the difficult part because once the entity is dead I believe that the entity's script no longer functions. However, if one sets "always active?" to yes the AI main script still might be active. At least I am assuming that would work. I have not tested that as yet.
EDIT #1:
I just tested it. I cannot get it to work with "keep active." There is another fpi that I am going to look at.
End Edit
EDIT #2:
Yes, this can work. You take out the "suspend" command. Here is the code.
;Artificial Intelligence Script
;Header
desc = Leave corpse
;Triggers
:state=0:state=1,coloff,state=1
:state=1,plrdistwithin=50:settargetname=key,settarget,state=2
:state=2:activatetarget=1,none
;End of Script
When the player gets close to the corpse the key is spawned.
The following is when the key is spawned immediately upon the npc's death.
End Edit
Let's start with a simple way to do this. The corpse could either disappear or remain. I am using the leavecorpse.fpi for this example.
Place a key wherever you want the key to show up and set "spawn at start?" to no. Use whatever name you want but it will need to be used in the script. I kept the name of the key as "key". Character entities do not have an ifused parameter, therefore you have to do something that most people don't know about. Since it is not a simple parameter this could be considered the work around. Here is the script that will spawn the key.
;Artificial Intelligence Script
;Header
desc = Leave corpse
;Triggers
:state=0:state=1,suspend,coloff,state=1
:state=1:settargetname=key,settarget,state=2
:state=2:activatetarget=1,none
;End of Script