demidekidasu Posted September 3, 2012 Share Posted September 3, 2012 Hi all, Wondering if anyone knows if it is possible to detect if the player is being attacked (player is the target of a hostile AI) in a script? I have tried if (PlayerRef.GetCombatState() == 1) but then realised that this is for detecting if AI is in combat, and does not work on the player :facepalm: Cannot find anything of use on the wiki :( Thanks in advance, guys. Link to comment Share on other sites More sharing options...
Cipscis Posted September 3, 2012 Share Posted September 3, 2012 What about IsInCombat? Cipscis Link to comment Share on other sites More sharing options...
demidekidasu Posted September 3, 2012 Author Share Posted September 3, 2012 Thanks for the reply, Cipscis. I just found that myself, but cannot quite get my head around how to use it for this instance. I've tried this: if (PlayerRef.isincombat() == 1) but apparently it still does not work. Here is the full scipt: Actor property PlayerRef auto Sound property WitcherAmuletDetectCombatSound01 auto ImageSpaceModifier property WitcherAmuletEnterCombatIMOD auto Event OnUpdate() if (PlayerRef.isincombat() == 1) debug.messagebox("Your medallion vibrates...") WitcherAmuletEnterCombatIMOD.apply() WitcherAmuletDetectCombatSound01.play(PlayerRef) ElseIf (PlayerRef.isincombat() == 0) RegisterforSingleupdate(0.5) EndIf EndEvent Event OnEquipped(Actor akActor) RegisterforSingleupdate(0.5) EndEvent It is attached to an amulet which I want to alert the player to being attacked by applying an space modifier and playing a short sound. The debug message box is just there to help me test if it is working or not. Both the sound and the image space modifier are very short so don't need to be stopped/removed later in the script. Link to comment Share on other sites More sharing options...
Cipscis Posted September 3, 2012 Share Posted September 3, 2012 IsInCombat's return value is of type Bool, why are you comparing it to an Int? In fact, why are you comparing it at all? If it returns True then that will be enough to trigger that conditional block. How does this script work for you? Actor property PlayerRef auto Sound property WitcherAmuletDetectCombatSound01 auto ImageSpaceModifier property WitcherAmuletEnterCombatIMOD auto Event OnUpdate() If (PlayerRef.IsInCombat()) Debug.MessageBox("Your medallion vibrates...") WitcherAmuletEnterCombatIMOD.apply() WitcherAmuletDetectCombatSound01.play(PlayerRef) Else RegisterForSingleUpdate(0.5) EndIf EndEvent Event OnEquipped(Actor akActor) If (akActor == PlayerRef) Debug.Notification("Player equipped medallion") RegisterForSingleUpdate(0.5) EndIf EndEvent Link to comment Share on other sites More sharing options...
demidekidasu Posted September 3, 2012 Author Share Posted September 3, 2012 I get the equip notification, but nothing else. Would I be correct to assume then that "IsInCombat" is only for NPC's as well? Link to comment Share on other sites More sharing options...
Cipscis Posted September 4, 2012 Share Posted September 4, 2012 (edited) Hmm, possibly. If you're getting the first notification then I guess I don't need to ask if you've autofilled your PlayerRef property. I remember there an IsInCombat function for previous games that still exists as the console function IsInCombat. You could test in the console to see if it works and, if it does, use this approach to check it via Papyrus if it works. I'd hope there'd be a way of checking this directly via Papyrus, though. Kind of disappointed to see that neither of these functions seem to work. I guess I shouldn't be entirely surprised, though, given that the OnCombatStateChanged event will never be called on the player. Cipscis EDIT: Would you mind adding notes to the wiki's documentation for IsInCombat and GetCombatState detailing your findings? You just need to say that they don't work as expected for the player, and mention how they seem to work (like always returning a particular value, if that's what happens). Cipscis Edited September 4, 2012 by Cipscis Link to comment Share on other sites More sharing options...
demidekidasu Posted September 4, 2012 Author Share Posted September 4, 2012 I whacked a guard with my sword then checked via the console and it returned that my character was in combat. Specifically, it said, "Kara is in combat". I'm not sure I understand how to check it via papyrus... I've never touched spells before, nor abilities. I am quite the scripting/CK noob, lol. I will have a good look at my script to make sure that it's not the actual script at fault (probably is, knowing me). Even if that isn't the case, thanks for taking the time to help me out! Link to comment Share on other sites More sharing options...
steve40 Posted September 4, 2012 Share Posted September 4, 2012 (edited) Edit: Nevermind, I've just realised that you tried it already. Edit2: I'm fairly sure that GetCombatState() works on both Actors and the player, as I used it in my Jaws mod a few months back. Edit3: I'm a bit suspicious that you haven't set the PlayerRef property correctly. Could you try this and see if it works: Sound property WitcherAmuletDetectCombatSound01 auto ImageSpaceModifier property WitcherAmuletEnterCombatIMOD auto Event OnUpdate() if game.GetPlayer().GetCombatState() == 1 debug.messagebox("Your medallion vibrates...") WitcherAmuletEnterCombatIMOD.apply() WitcherAmuletDetectCombatSound01.play(game.GetPlayer()) Else RegisterforSingleupdate(0.5) EndIf EndEvent Event OnEquipped(Actor akActor) If akActor == Game.GetPlayer() RegisterforSingleupdate(0.5) EndIf EndEvent Edited September 4, 2012 by steve40 Link to comment Share on other sites More sharing options...
demidekidasu Posted September 4, 2012 Author Share Posted September 4, 2012 (edited) Thanks for the reply, steve40. GetCombatState is the first thing I tried and it did not work. I will try just using game.getplayer as you suggest, but you can see from my script that I referenced the player correctly with PlayerRef. I also have definitely set the properties in the property window outside of the script, hence why I get the equip message. -EDIT-Just tried Game.GetPlayer and no joy. Also tried it with IsInCombat instead of GetCombatState. From a bit of research on these two lines, it seems that they would only work if attached it to the NPC that attacks the player. There is seemingly no direct way to detect if the player is being attacked. Nice one, Bethesda... It looks like I would have to attach the script to every single NPC/monster in the game, which I don't really fancy doing. Plus, I don't know how I could make it so the script only works when the player has the medallion equiped. At one point I even tried GetRandomActor (is that what it is called? Can't remember off the top of my head), to essentially "scan" everyone nearby and see if they are attacking the player. Thought it would work in theory, but nothing happened. Edited September 4, 2012 by demidekidasu Link to comment Share on other sites More sharing options...
demidekidasu Posted September 4, 2012 Author Share Posted September 4, 2012 (edited) OK... I just cut it right down to this for testing: Event OnUpdate() Debug.trace("Amulet log") EndEvent Event OnEquipped(Actor akActor) Debug.Notification("Player equipped medallion") RegisterForUpdate(1.0) EndEvent Event OnUnEquipped(Actor akActor) Debug.Notification("Player unequipped medallion") UnRegisterForUpdate() EndEvent Nothing at all in the Papyrus log. WHAT-ON-EARTH?!?! I get the message about equiping the medallion, so I know the first part works. -EDIT-Tried again and this is in the script log: [09/04/2012 - 05:45:34PM] error: Unable to call RegisterForUpdate - no native object bound to the script object, or object is of incorrect type stack: [item 7 in container (00000014)].WitcherAmuletScript01.RegisterForUpdate() - "<native>" Line ? [item 7 in container (00000014)].WitcherAmuletScript01.OnEquipped() - "WitcherAmuletScript01.psc" Line 15 I don't quite understand what this is telling me. -EDIT 2-So, after more testing and messing around with the script, it looks like the problem lies either with "RegisterForUpdate" or "Event OnUpdate". I have seen a few forum posts via google that describe not being able to use these on apparel items... Are Bethesda taking the Mick? Edited September 4, 2012 by demidekidasu Link to comment Share on other sites More sharing options...
Recommended Posts