demidekidasu Posted September 4, 2012 Author Share Posted September 4, 2012 I have made it an enchantment. I put the following script as the magic effect:Actor property PlayerRef auto Sound property WitcherAmuletDetectCombatSound01 auto ImageSpaceModifier property WitcherAmuletEnterCombatIMOD auto Event OnUpdate() If (PlayerRef.IsInCombat()) Debug.Notification("Your medallion vibrates...") WitcherAmuletEnterCombatIMOD.apply() WitcherAmuletDetectCombatSound01.play(PlayerRef) Else Debug.Notification("Medallion update...") RegisterForSingleUpdate(5.0) EndIf EndEvent Event OnEffectStart(Actor akTarget, Actor akCaster) Debug.Notification("Player equipped medallion") RegisterForSingleUpdate(5.0) EndEvent I am more interested in seeing if I get the notifications, and guess what? That's right, I don't. I get the first one, indicating that the medallion is equiped, and I see the effect under magic effects in-game, but receive no notification messages, and the scripted effect obviously does not work. I am also seeing nothing in the logs. What the fudge is going on here? Why is there a problem with "RegisterForSingleUpdate" or "Event OnUpdate"? And, yes, I did set the properties. Link to comment Share on other sites More sharing options...
demidekidasu Posted September 5, 2012 Author Share Posted September 5, 2012 (edited) EUREKA!!! Actor property PlayerRef auto Sound property WitcherAmuletDetectCombatSound01 auto ImageSpaceModifier property WitcherAmuletEnterCombatIMOD auto Event OnEffectStart(Actor akTarget, Actor akCaster) Debug.Notification("Witcher's medallion equiped.") WitcherAmuletEnterCombatIMOD.apply() WitcherAmuletDetectCombatSound01.play(PlayerRef) RegisterForSingleUpdate(0.5) EndEvent Event OnUpdate() RegisterForSingleUpdate(0.5) ;Debug.Notification("No threats...") If ((Game.FindRandomActorFromRef(Game.GetPlayer(), 50000.0)).GetCombatTarget() == Game.GetPlayer()) Debug.Notification("Your medallion is vibrating...") ;WitcherAmuletEnterCombatIMOD.apply() WitcherAmuletDetectCombatSound01.play(PlayerRef) EndIf EndEvent Every 0.5 seconds, it picks a random actor within 50,000 units then checks if they are attacking the player, then does specified stuff if so. AND IT WORKS!!! I am absolutely over the moon. And the basis of this script can be used for other mods too, as a "detect if player is being attacked" script. Now I just need to tweak it and make it so it only works if the player equips it (easy part :laugh:). --------------------------------------------------------------------------------------------------------------------------- -EDIT-To summarise for anyone who may want to use this, the basic version would be this:Event OnUpdate() RegisterForSingleUpdate(0.5) If ((Game.FindRandomActorFromRef(Game.GetPlayer(), 50000.0)).GetCombatTarget() == Game.GetPlayer()) Debug.Notification("Player is in combat") EndIf EndEventEvery 0.5 seconds, it picks a random NPC from within 50,000 units and gets if they are attacking the player, doing specified stuff if so. In this case it merely prints a message, but you can have it do whatever. Edited September 5, 2012 by demidekidasu Link to comment Share on other sites More sharing options...
steve40 Posted September 6, 2012 Share Posted September 6, 2012 (edited) 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? The error message means that the script is running but it is no longer attached to a real object (amulet?). From the looks of it, you amulet was in the player's inventory. I think I remember reading something on the wiki about this problem when scripted objects are put in a container. It's not a bug, just something that needs to be handled differently, but I can't remember how. I think it might be happening because when you put certain items in a container, they get replaced by their base form rather than their object reference? Edited September 6, 2012 by steve40 Link to comment Share on other sites More sharing options...
steve40 Posted September 6, 2012 Share Posted September 6, 2012 (edited) code]Event OnUpdate() RegisterForSingleUpdate(0.5) If ((Game.FindRandomActorFromRef(Game.GetPlayer(), 50000.0)).GetCombatTarget() == Game.GetPlayer()) Debug.Notification("Player is in combat") EndIfEndEvent[/code] 50,000 units is rather extreme. Try something like 4,000 units, or about 9,000 tops. Most cells or objects get unloaded from memory when they are about >10,000 units away, but basically, the bigger the number used in the "FindRandom" type of functions, the more strain it puts on the game engine performance-wise. Edited September 6, 2012 by steve40 Link to comment Share on other sites More sharing options...
steve40 Posted September 6, 2012 Share Posted September 6, 2012 (edited) Now I just need to tweak it and make it so it only works if the player equips it (easy part :laugh:). Well, seeing as you are using a scripted magic effect, you could probably just add a Condition to the Spell to check that the amulet is equipped. The condition GetEquipped might work. What I was going to suggest as a more efficient alternative to your script (eg. avoiding having to use OnUpdate and FindRandomActor) would be that there is actually a Condition for checking if an actor is in combat :) So you could make a spell of constant effect for your amulet, and simply use the Condition Function "GetCombatState == 1" run on the PlayerRef to make it activate whenever the player is in combat. This might actually work on the player even if the scripted version of GetCombatState doesn't. Worth a try. Edited September 6, 2012 by steve40 Link to comment Share on other sites More sharing options...
Recommended Posts