ripvanwinkle111 Posted March 4, 2012 Share Posted March 4, 2012 So, I have an NPC and I want to check if he is dead, and if he is dead, prevent other functions or loops from running.However, the NPC state never becomes true. (npc is dead) I'm not using an integer variable in the OnDeath event because I expect people like to use console commands to resurrect NPCs.I just want some of my other functions to stop working unless the NPC is alive. self.getbaseobject() returns the correct base ID.And the compiler doesn't throw any errors. Any suggestions? event oninit() registerforupdate(5)endevent event onupdate() debug.messagebox("NPC IsDead? = "+(self.getbaseobject() as Actor).isdead()) endevent Link to comment Share on other sites More sharing options...
gsmanners Posted March 4, 2012 Share Posted March 4, 2012 I think you're confusing GetDeadCount and IsDead. One uses the base ID, the other uses the reference ID. Link to comment Share on other sites More sharing options...
ripvanwinkle111 Posted March 4, 2012 Author Share Posted March 4, 2012 I think you're confusing GetDeadCount and IsDead. One uses the base ID, the other uses the reference ID. GetDeadCount returns how many of that base type is dead. So if you have killed 25 rabbits, GetDeadCount will return the integer 25. And I have tried using objectreference and Actorbase but both of those throw a compile error saying that IsDead() is not a valid function for that type. I'm just trying to find out if a specific npc is alive or dead. According to the wiki, it should work like this. ; Is Sally currently dead?bool sallyIsDead = Sally.IsDead() http://www.creationk.../IsDead_-_Actor Link to comment Share on other sites More sharing options...
eltucu Posted March 4, 2012 Share Posted March 4, 2012 (edited) Umm... Eh, i *think* you can make it work in two ways: If the script is running off the NPC, that is, the script is attached to the NPC, by just running an IsDead() without any further stuff should work. debug.messagebox("NPC IsDead? = "+(IsDead()) The game just assumes that since you're running the script on top of the NPC, you're talking about that NPC when you call the IsDead() function. If not, you need to make a property that points to the NPC. This one im not sure how to do it, it may be an object reference property or an actor property, whichever one lets you select the NPC from the render window. Eitheractor property tehproperty autoorobjectReference property tehproperty auto Then you'd call the IsDead like this: debug.messagebox("NPC IsDead? = "+(tehproperty.IsDead()) Now, im not sure how Papyrus works like this but for all i know (not much actually) of both Ada and C++, the compiler would crap at you for trying to output a boolean as a string. So you may need to make a conditional if Papyrus doesnt makes the conversion automatically. That means, creating a string variable, assigning to it "false" or "true" depending on what IsDead() tells you with an IF, then displaying a message with the string. something like if IsDead == truemystring = "true"elsemystring = "false"EndIf debug.messagebox("NPC IsDead? = "+(mystring)) I dunno exactly how stings are handled in Papyrus. Probably its done automatically, but its worth mentioning. Edited March 4, 2012 by eltucu Link to comment Share on other sites More sharing options...
ripvanwinkle111 Posted March 4, 2012 Author Share Posted March 4, 2012 Umm... Eh, i *think* you can make it work in two ways: If the script is running off the NPC, that is, the script is attached to the NPC, by just running an IsDead() without any further stuff should work. debug.messagebox("NPC IsDead? = "+(IsDead()) If not, you need to make a property that points to the NPC. This one im not sure how to do it, it may be an object reference property or an actor property, whichever one lets you select the NPC from the render window. Then you'd call the IsDead like this: debug.messagebox("NPC IsDead? = "+(tehproperty.IsDead()) Now, im not sure how Papyrus works like this but for all i know (not much actually) of both Ada and C++, the compiler would crap at you for trying to output a boolean as a string. So you may need to make a conditional if Papyrus doesnt makes the conversion automatically. That means, creating a string variable, assigning to it "false" or "true" depending on what IsDead() tells you with an IF, then displaying a message with the string. something like if IsDead == truemystring = "true"elsemystring = "false"EndIf debug.messagebox("NPC IsDead? = "+(mystring)) Or something like that. Probably its done automatically, but its worth mentioning. Well, I have tried passing the objectreference but it doesn't have the IsDead() function on it.As for strings, well, Papyrus doesn't have strings really. The only strings it uses is for date and gamesettings.With the GECK, it didn't check this kind of thing when you wrote the script, because nothing was compiled...it ran or it broke. Edit: I just tried : debug.messagebox("NPC IsDead? = "+IsDead()) and it said its not a valid function. Link to comment Share on other sites More sharing options...
eltucu Posted March 4, 2012 Share Posted March 4, 2012 (edited) An actor property doesnt works? Papyrus has string type, check the wiki. Anyway, you're not looking for the baseID of the actor, you're looking for the referenceID. Give it one in the render window, checking the properties of the actor in that cell, then point from the property to the actor. Where are you running the script? from a quest? actor? activator? what? Edited March 4, 2012 by eltucu Link to comment Share on other sites More sharing options...
ripvanwinkle111 Posted March 4, 2012 Author Share Posted March 4, 2012 An actor property doesnt works? Papyrus has string type, check the wiki. Anyway, you're not looking for the baseID of the actor, you're looking for the referenceID. Give it one in the render window, checking the properties of the actor in that cell, then point from the property to the actor. Where are you running the script? from a quest? actor? activator? what? Passing a bool into a string isn't the problem, the problem is that the return value is always false. Yep, already tried giving it the referenceid, it doesn't work.The script is attached to the NPC itself. Self.isdead() also does not work.Self as Actor fails.Self as Actorbase fails. It's very frustrating is all, trying to find the right " cast as" phrase that doesn't bomb out. Link to comment Share on other sites More sharing options...
eltucu Posted March 4, 2012 Share Posted March 4, 2012 Try with an OnLoad event instead of OnInit. It seems that the onupdate event never happens so its stuck on false. Then add UnregisterForUpdate() once you checked what you wanted to check. Link to comment Share on other sites More sharing options...
ripvanwinkle111 Posted March 5, 2012 Author Share Posted March 5, 2012 Try with an OnLoad event instead of OnInit. It seems that the onupdate event never happens so its stuck on false. Then add UnregisterForUpdate() once you checked what you wanted to check. OnLoad only triggers when you walk into that cell so that won't work if the NPC dies while helping you against a bandit attack. And the onupdate event does fire for me, I get a new messagebox every 5 seconds. Link to comment Share on other sites More sharing options...
cscottydont Posted March 5, 2012 Share Posted March 5, 2012 convoluted workaround for scripts that receive actor events: Instead of using IsDead(), try making a new bool variable and setting it in an OnDying() event. I've had issues with OnDeath() events but OnDying() always fires in my experience. example: bool ActorDead = False Even OnDying(Actor akKiller) ActorDead = True ;you can now use <if ActorDead> instead of <if IsDead()> EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts