SirBeastling Posted January 24, 2019 Share Posted January 24, 2019 I am having trouble getting a scene to play when the player starts combat with an actor alias - in this case Anise. The scene is meant to be a none intrusive commentary before the invisible activator backs out. I am also trying to get a different scene to play when Anise dies through the same method. I have gotten scenes like these to work before, so I am not sure what I am doing wrong with this one: The code is posted below:Scriptname SirBeastXM01AniseRefScript extends ReferenceAlias ;-----PropertiesActor Property Player Auto Scene Property AniseAliveScene Auto Scene Property AniseDeadScene Auto ReferenceAlias Property XhiivAct Auto ObjectReference Property ActReturnMarker Auto ReferenceAlias Property Anise Auto Int Property FightingAnise = -1 Auto ;-----Events Event OnCombatStateChange(actor Target, int CS)if Target == Playerif CS == 1FightingAnise = 1debug.messagebox("Event has triggered")PlayAniseAliveScene()elseIf CS == 0if Anise.GetActorReference().IsDead()PlayAniseDeadScene()endifendifendifEndEvent ;-----Functions Function PlayAniseAliveScene()XhiivAct.GetReference().MoveTo(Player, -90.0 * Math.Sin(Player.GetAngleZ()), -90.0 * Math.Cos(Player.GetAngleZ()))AniseAliveScene.start()while AniseAliveScene.IsPlaying()utility.wait(1.0)endWhileXhiivAct.GetReference().MoveTo(ActReturnMarker)EndFunction Function PlayAniseDeadScene()XhiivAct.GetReference().MoveTo(Player, -90.0 * Math.Sin(Player.GetAngleZ()), -90.0 * Math.Cos(Player.GetAngleZ()))AniseDeadScene.start()while AniseDeadScene.IsPlaying()utility.wait(1.0)endWhileXhiivAct.GetReference().MoveTo(ActReturnMarker)EndFunction ---------------- I also have a different problem for the same mod where the dialogue box with the next options shows up when I have a character forcegreet the player, even as they are trying to do their intro speech. The details are at this page:https://forums.nexusmods.com/index.php?/topic/7337621-next-dialogue-branch-showing-on-forcegreet/ Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 24, 2019 Share Posted January 24, 2019 According to the CK wiki, OnCombatStateChanged does not work when the player changes combat states. It needs to be used with other actors. In your case then you will probably need to check if Anise has changed combat state. Link to comment Share on other sites More sharing options...
SirBeastling Posted January 24, 2019 Author Share Posted January 24, 2019 This script is attached to the Anise reference alias.However, the debug messagebox function never fires that I have added to see if it works, so I am not sure if Anise ever does change combat states. This is when she is waiting outside of her cabin for the player to come out of the basement. She is just standing idle, so I believe that she is not in combat with anything. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted January 24, 2019 Share Posted January 24, 2019 You wrote: "I am having trouble getting a scene to play". That can be of different causes. Cause and effect, you know!Use Debug.Trace() inside to monitor your scripts. It is more valid. SirBeastXM01AniseRefScript Scriptname SirBeastXM01AniseRefScript extends ReferenceAlias ; https://forums.nexusmods.com/index.php?/topic/7340111-getting-combatstatechange-to-work-with-actor-alias/ ; SirBeastling wrote: "I am having trouble getting a scene to play when the player starts combat with an actor alias" ; IsharaMeradin posted: " OnCombatStateChanged() does not work when the player changes combat states" ; The answer was "This script is attached to the Anise reference alias." Scene PROPERTY AniseAliveScene auto Scene PROPERTY AniseDeadScene auto ReferenceAlias PROPERTY XhiivAct auto ; What is that? ;ReferenceAlias Property Anise auto ; it is the same as self ObjectReference PROPERTY ActReturnMarker auto ; -- EVENTs -- 3 EVENT OnInit() Debug.Trace(" OnInit() - has been reached.. " +self) ENDEVENT EVENT OnCombatStateChanged(Actor akTarget, Int aeCombatState) ; aeCombatState as follow: 0 - not in combat, 1 - in combat, 2 - searching Debug.Notification("Anise has changed combat state to " +aeCombatState) ; *** debuggging only IF (akTarget == Game.GetPlayer()) ELSE RETURN ; - STOP - not the player ENDIF ;--------------------- IF (aeCombatState == 1) Debug.Notification("Anise enters combat with player") ; *** debuggging only PlayAniseAliveScene() ENDIF ENDEVENT EVENT OnDeath(Actor akKiller) ; triggered when this actor finishes dying (only if this alias points at an actor) IF (akKiller == Game.GetPlayer()) ELSE RETURN ; - STOP - not the player ENDIF ;--------------------- Debug.Notification("Anise was killed by the player") ; *** debuggging only PlayAniseDeadScene() ENDEVENT ; -- FUNCTIONs -- 4 ;------------------------------------------------- FUNCTION myF_Move(ReferenceAlias RA, Bool bPlayer) ;------------------------------------------------- IF (XhiivAct) && (ActReturnMarker) ELSE Debug.Trace(" myF_Move() - Error: Missing property RefAlias or ReturnMarker!") RETURN ; - STOP - ENDIF ;--------------------- objectReference oRef = RA.GetReference() IF ( oRef ) ELSE Debug.Trace(" myF_Move() - Error: ReferenceAlias is not filled!") RETURN ; - STOP - ENDIF ;--------------------- IF ( !bPlayer ) oRef.MoveTo(ActReturnMarker) ELSE actor player = Game.GetPlayer() float f = player.GetAngleZ() float fx = Math.SIN(f) * -90.0 float fy = Math.COS(f) * -90.0 oRef.MoveTo(player, fx, fy) ENDIF ENDFUNCTION ;-------------------------- FUNCTION myF_Play(Scene sc) ;-------------------------- myF_Move(XhiivAct, TRUE) sc.Start() WHILE (sc) && sc.IsPlaying() Utility.Wait(1.0) ENDWHILE myF_Move(XhiivAct, False) ENDFUNCTION ;----------------------------- FUNCTION PlayAniseAliveScene() ;----------------------------- IF AniseAliveScene.IsPlaying() ELSE myF_Play(AniseAliveScene) ENDIF ENDFUNCTION ;---------------------------- FUNCTION PlayAniseDeadScene() ;---------------------------- IF AniseDeadScene.IsPlaying() ELSE myF_Play(AniseDeadScene) ENDIF ENDFUNCTION Link to comment Share on other sites More sharing options...
Recommended Posts