Dielos Posted August 10, 2012 Share Posted August 10, 2012 Hello, I need to detect player kills and check the killed actor's inventory. I have read quite complicated ways of doing this, and I wanted to know if there is an easy and reliable way. At the moment I'm detecting the death of any NPC succesfully through an empty dialogue topic "Death" under the combat tab with empty conditions (runs on everybody). The script is set to run on "Result Script (Begin)" and fires every single time correctly. But this detects every death, it doesn't matter from what they died. If I try something likeif iskiller Player ;Do something here endifthe code in the "if" doesn't run. So my guess is that the iskiller command only works correctly on the exact moment the NPC dies? I also tried setting iskiller as a condition for the death topic to run, with Target Subject, Function Name iskiller, Function Info PlayerRef, Comp ==, and Value 1. The topic never fires... Any easy way of doing this or a different method or command that can work in the dialogue other than iskiller? Thanks in advance for any help... Link to comment Share on other sites More sharing options...
viennacalling Posted August 10, 2012 Share Posted August 10, 2012 Overall, what are you trying to do with the killed actor's inventory? Maybe there is another way to accomplish what you want. Link to comment Share on other sites More sharing options...
luthienanarion Posted August 10, 2012 Share Posted August 10, 2012 (edited) Try running the IsKiller condition on Combat Target instead of Subject. Edited August 10, 2012 by luthienanarion Link to comment Share on other sites More sharing options...
Dielos Posted August 10, 2012 Author Share Posted August 10, 2012 viennacalling, I'm trying to check for an object in the killed NPC's inventory. If the NPC has the object, and was killed by the player, then the player gets an xp boost or something... luthienanarion, I tried that option, but still didn't work. It seems that iskiller doesn't really do anything in the dialogue conditions. I'm not sure, maybe iskiller gives only a result under the ondeath block and right at the moment of death. If this is the case, then it will probably never fire here, as I assume that the script runs, just after he has been killed. The death topic let's the killed NPC say something while dying, but for the engine, he might be dead already while he says his sentence. I don't know... Link to comment Share on other sites More sharing options...
viennacalling Posted August 10, 2012 Share Posted August 10, 2012 viennacalling, I'm trying to check for an object in the killed NPC's inventory. If the NPC has the object, and was killed by the player, then the player gets an xp boost or something... So the object is functioning as a token. Similar work I've read about is to put the script on the object itself. The script has a gamemode block which checks if the container is dead and if the killer was the player. If so then you can have something happen. Not sure if works as well in practice, but something to consider. Link to comment Share on other sites More sharing options...
Dielos Posted August 10, 2012 Author Share Posted August 10, 2012 It sure is an interesting suggestion and worth a try... I will try that, thanks. And yes, the object is working as a token. The other option I was thinking, but don't know if it would work, is to put all the NPC's I need inside a FormList, instead of giving them tokens, and loop that FormList looking for dead references. Don't know if this is too complicated though... Link to comment Share on other sites More sharing options...
luthienanarion Posted August 11, 2012 Share Posted August 11, 2012 (edited) It sure is an interesting suggestion and worth a try... I will try that, thanks. And yes, the object is working as a token. The other option I was thinking, but don't know if it would work, is to put all the NPC's I need inside a FormList, instead of giving them tokens, and loop that FormList looking for dead references. Don't know if this is too complicated though... If you're willing to require NVSE for your plugin, I could easily whip up a ref-walk script that scanned for dead NPCs against a list. The reason you'd need to use tokens is that you can't otherwise exclude NPCs you've already accounted for in subsequent scans. scn ScanForPlayerKillsOS ; Put this on a token in the player's inventory. ref currentactor begin gamemode set currentactor to getfirstref 42 1 0 ; You would use "getfirst ref 200 1 0" if you wanted to include non-human actors such as creatures. label 10 if(currentactor) if(currentactor.getdead && listgetformindex PlayerKillsList currentactor != -1 && currentactor.getitemcount KillToken == 0 && currentactor.iskiller player) ; Replace 'PlayerKillsList' with the name of your Form List of NPCs you want counted. ; 'KillToken' is an unplayable item of any type used to mark counted NPCs so they are skipped once they are counted. currentactor.additem KillToken 1 1 set KillCountVariable to KillCountVariable + 1 ; Increment a variable, either global or declared locally. endif set currentactor to Pencil01 ; Avoids a potential bug in GetNextRef. set currentactor to getnextref goto 10 endif end ; gamemode Edited August 11, 2012 by luthienanarion Link to comment Share on other sites More sharing options...
Recommended Posts