Jump to content

Need help with Oncombat script


Maleagant

Recommended Posts

I can't figure out the exact Code but it should look something like this maybe:

 

Race OriginalSelfRace

Function GetSelfRace()

OriginalSelfRace = (Self).GetRace()

EndFunction



Event OnCombatStateChanged(Actor actorRef, int combatState)

       if (combatState == 1)   ;started combat
               WerewolfChange.Cast(Self)
       elseif (combatState == 0)       ;left combat
              
       endif

EndEvent


Race WerewolfRace

Function GetwerewolfRace()

GetRace (Self) = WerewolfRace()
SetRace(OriginalSelfRace)

EndFunction

 

 

Although I am not sure how to get it to understand not to change her back till she is out of combat.....

Edited by Maleagant
Link to comment
Share on other sites

Whats the werewolf spell property set to so I can test this myself.

 

Scriptname Example extends Actor  

Event OnCombatStateChanged(Actor actorRef, int combatState)
actorRef = Self
       if (combatState == 1)   ;started combat
	   StoreRace(actorRef)
               WerewolfChange.Cast(Self)
       elseif (combatState == 0)       ;left combat
               Self.DispelSpell(WerewolfChange)
	   RestoreRace(actorRef)
       endif

EndEvent


Race Function StoreRace(Actor actorRef)
actorRace = actorRef.GetActorBase().GetRace()
  Return actorRace ;dont think this even needs to return anything. Race was stored in property
EndFunction


Function RestoreRace(Actor actorRef)
actorRef.SetRace(actorRace )
EndFunction


Race Property actorRace Auto ;leave empty
SPELL Property WerewolfChange Auto

Link to comment
Share on other sites

Maybe something like this?

 

Scriptname Kythira01 extends Actor  

SPELL Property WerewolfChange Auto
Race Property actorRace Auto ;leave empty

Race Function StoreRace(Actor actorRef)

       actorRace = actorRef.GetActorBase().GetRace()

EndFunction

Function RestoreRace(Actor actorRef)

        actorRef.SetRace(actorRace) 

EndFunction


Event OnCombatStateChanged(Actor actorRef, int combatState)
actorRef = Self

       if (combatState == 1)   ;started combat
                  StoreRace(actorRef)
               WerewolfChange.Cast(Self)

       endif

EndEvent

if (combatState == 0)       ;left combat
	Self.DispelSpell(WerewolfChange)
                  RestoreRace(actorRef)
endif

EndEvent

 

The Problem seems to be with when it tells her to change back, or rather when it calls the function to restore her race, (And then of coarse not immediately turn her back into a werewolf until she again enters combat)

 

Almost have the answer I think keep them coming :D

Link to comment
Share on other sites

I haven't done any testing, but I think the reason it was doing that is because when the actor's race is changed, they go out of combat temporarily. You can solve this either by using a boolean or by using states. I think using states are supposed to be better, but they both work:

 

Scriptname Example extends Actor

SPELL Property WerewolfChange Auto
Race ActorRace
Bool Busy = False

Event OnCombatStateChanged(Actor actorRef, int combatState)

if (Busy == False)
	Busy = True
	if (combatState == 1)   ;started combat
		ActorRace = GetRace()
		WerewolfChange.Cast(Self)
	elseif (combatState == 0)       ;left combat
		DispelSpell(WerewolfChange)
		SetRace(ActorRace)
	endif
	Busy = False
endif

EndEvent

 

Scriptname Example extends Actor

SPELL Property WerewolfChange Auto
Race ActorRace

Auto State Waiting

Event OnCombatStateChanged(Actor actorRef, int combatState)

	GoToState("Busy")
	if (Busy == False)
		if (combatState == 1)   ;started combat
			ActorRace = GetRace()
			WerewolfChange.Cast(Self)
		elseif (combatState == 0)       ;left combat
			SetRace(ActorRace)
			DispelSpell(WerewolfChange)
		endif
	endif
	GoToState("Waiting")

EndEvent

EndState

State Busy
EndState

Link to comment
Share on other sites

I haven't done any testing, but I think the reason it was doing that is because when the actor's race is changed, they go out of combat temporarily. You can solve this either by using a boolean or by using states. I think using states are supposed to be better, but they both work:

 

Scriptname Example extends Actor

SPELL Property WerewolfChange Auto
Race ActorRace
Bool Busy = False

Event OnCombatStateChanged(Actor actorRef, int combatState)

if (Busy == False)
	Busy = True
	if (combatState == 1)   ;started combat
		ActorRace = GetRace()
		WerewolfChange.Cast(Self)
	elseif (combatState == 0)       ;left combat
		DispelSpell(WerewolfChange)
		SetRace(ActorRace)
	endif
	Busy = False
endif

EndEvent

 

Scriptname Example extends Actor

SPELL Property WerewolfChange Auto
Race ActorRace

Auto State Waiting

Event OnCombatStateChanged(Actor actorRef, int combatState)

	GoToState("Busy")
	if (Busy == False)
		if (combatState == 1)   ;started combat
			ActorRace = GetRace()
			WerewolfChange.Cast(Self)
		elseif (combatState == 0)       ;left combat
			SetRace(ActorRace)
			DispelSpell(WerewolfChange)
		endif
	endif
	GoToState("Waiting")

EndEvent

EndState

State Busy
EndState

 

Tried this several ways:

 

*** 1st one compiles, Same issue though she wont change back.

 

*** 2nd one wont compile gives this error (Maybe I did something wrong copy and pasted the script to test it for you)

 

Error:

 

Compiling "Kythira01"...

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\Kythira01.psc(12,20): variable Busy is undefined

c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\Kythira01.psc(12,25): cannot compare a none to a bool (cast missing or types unrelated)

No output generated for Kythira01, compilation failed.

 

Batch compile of 1 files finished. 0 succeeded, 1 failed.

Failed on Kythira01

 

 

***** 3rd attempt I slammed them both together into one script, it compiles just fine, however She changes immediately (Weather on combat or not if in the presence of another npc) and then back (Or rather seems to change then Change back (Pulls out a bow? Even though no bow is in her inventory... weird lol) Then changes back into a werewolf and stays that way even after combat. (Think I fixed the Bow issue, deleted her inside the zone and re-spawned her)

Edited by Maleagant
Link to comment
Share on other sites

The second script wouldn't compile because I forgot to take out the check for the variable when I was copy/pasting. Anyway, I took a closer look and figured out some more things. When you cast the spell, you don't immediately change into a werewolf.

 

I was setting the states/variable back to default too soon. The combat state change from changing race occurs after I stop looking out for them in the script. I tried a couple of different ways and this is what I came up with:

 

 

Scriptname fg109TestActorScript extends Actor

SPELL Property WerewolfChange Auto
Explosion Property ExplosionIllusionDark01 Auto
Race ActorRace
Bool IsWerewolf = False

Auto State Waiting
;/	Event OnBeginState()
	Debug.Notification("Waiting")
EndEvent/;
Event OnCombatStateChanged(Actor actorRef, int combatState)
	if (IsWerewolf)
		if (combatState == 0)	;stopped combat
			GoToState("Busy")
			RegisterForSingleUpdate(3)
			Transform(False)
		endif
	elseif (combatState == 1)	;entered combat
		GoToState("Busy")
		RegisterForSingleUpdate(11)	;WerewolfChangeFX has a failsafe check after 10 secs
		Transform()
	endif
EndEvent
EndState

State Busy
;/	Event OnBeginState()
	Debug.Notification("Busy")
EndEvent/;
Event OnUpdate()
	Debug.Notification("OnUpdate")
	if (IsWerewolf)
		if !(IsInCombat())
			Transform(False)
			RegisterForSingleUpdate(3)
			Return
		endif
	elseif (IsInCombat())
		Transform()
		RegisterForSingleUpdate(11)	;WerewolfChangeFX has a failsafe check after 10 secs
		Return
	endif
	GoToState("Waiting")
EndEvent
EndState

Function Transform(Bool bToWerewolf = True)
;	Debug.Notification("Transforming to werewolf = " + bToWerewolf)
IsWerewolf = bToWerewolf
if (bToWereWolf)
	ActorRace = GetRace()
	WerewolfChange.Cast(Self)
else
	PlaceAtMe(ExplosionIllusionDark01)
	SetRace(ActorRace)
	DispelSpell(WerewolfChange)
endif
EndFunction

 

 

There are probably some unnecessary code in there since I needed a couple of tries to get it right. The script would be much simpler if you didn't use a spell to change to a werewolf:

 

 

Scriptname fg109TestActorScript extends Actor

Race Property WerewolfBeastRace Auto
Race ActorRace

Event OnInit()
ActorRace = GetRace()
EndEvent

Auto State Waiting
Event OnCombatStateChanged(Actor actorRef, int combatState)
	GoToState("Busy")
	RegisterForSingleUpdate(1)
EndEvent
EndState

State Busy
Event OnUpdate()
	if (IsInCombat() && GetRace() == ActorRace)
		SetRace(WerewolfBeastRace)
	elseif (!IsInCombat() && GetRace() == WerewolfBeastRace)
		SetRace(ActorRace)
	else
		GoToState("Waiting")
		Return
	endif
	RegisterForSingleUpdate(1)
EndEvent
EndState

 

Edited by fg109
Link to comment
Share on other sites

The second script wouldn't compile because I forgot to take out the check for the variable when I was copy/pasting. Anyway, I took a closer look and figured out some more things. When you cast the spell, you don't immediately change into a werewolf.

 

I was setting the states/variable back to default too soon. The combat state change from changing race occurs after I stop looking out for them in the script. I tried a couple of different ways and this is what I came up with:

 

 

Scriptname fg109TestActorScript extends Actor

SPELL Property WerewolfChange Auto
Explosion Property ExplosionIllusionDark01 Auto
Race ActorRace
Bool IsWerewolf = False

Auto State Waiting
;/	Event OnBeginState()
	Debug.Notification("Waiting")
EndEvent/;
Event OnCombatStateChanged(Actor actorRef, int combatState)
	if (IsWerewolf)
		if (combatState == 0)	;stopped combat
			GoToState("Busy")
			RegisterForSingleUpdate(3)
			Transform(False)
		endif
	elseif (combatState == 1)	;entered combat
		GoToState("Busy")
		RegisterForSingleUpdate(11)	;WerewolfChangeFX has a failsafe check after 10 secs
		Transform()
	endif
EndEvent
EndState

State Busy
;/	Event OnBeginState()
	Debug.Notification("Busy")
EndEvent/;
Event OnUpdate()
	Debug.Notification("OnUpdate")
	if (IsWerewolf)
		if !(IsInCombat())
			Transform(False)
			RegisterForSingleUpdate(3)
			Return
		endif
	elseif (IsInCombat())
		Transform()
		RegisterForSingleUpdate(11)	;WerewolfChangeFX has a failsafe check after 10 secs
		Return
	endif
	GoToState("Waiting")
EndEvent
EndState

Function Transform(Bool bToWerewolf = True)
;	Debug.Notification("Transforming to werewolf = " + bToWerewolf)
IsWerewolf = bToWerewolf
if (bToWereWolf)
	ActorRace = GetRace()
	WerewolfChange.Cast(Self)
else
	PlaceAtMe(ExplosionIllusionDark01)
	SetRace(ActorRace)
	DispelSpell(WerewolfChange)
endif
EndFunction

 

 

There are probably some unnecessary code in there since I needed a couple of tries to get it right. The script would be much simpler if you didn't use a spell to change to a werewolf:

 

 

Scriptname fg109TestActorScript extends Actor

Race Property WerewolfBeastRace Auto
Race ActorRace

Event OnInit()
ActorRace = GetRace()
EndEvent

Auto State Waiting
Event OnCombatStateChanged(Actor actorRef, int combatState)
	GoToState("Busy")
	RegisterForSingleUpdate(1)
EndEvent
EndState

State Busy
Event OnUpdate()
	if (IsInCombat() && GetRace() == ActorRace)
		SetRace(WerewolfBeastRace)
	elseif (!IsInCombat() && GetRace() == WerewolfBeastRace)
		SetRace(ActorRace)
	else
		GoToState("Waiting")
		Return
	endif
	RegisterForSingleUpdate(1)
EndEvent
EndState

 

 

Yea the spell was just for testing, Well definitely go with whatever is easiest and works like its supposed to :D. If Id known the spell would be so much trouble would have started with simply a race change or something. Lesson learned I guess lol.

 

Script seems to work like a charm, awesome guys, and thanks a lot, Putting your names int he script itself as well as on the Mod page at steam, If you want to check out the mod after I update it tomorrow with the new stuff, it's called Shadowsong Mannor

Edited by Maleagant
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...