Jump to content

casting spells on an activator


cfh85

Recommended Posts

Scriptname CFHSpellDarkWelkyndDefenceScript

Ref TempRef
Ref Disabled1Ref
Ref Disabled2Ref
Ref Disabled3Ref
Ref Disabled4Ref
Ref Disabled5Ref

Float Pos

Short Counter
Short DisabledCount

Begin ScripteffectStart
Set DisabledCount to 0
Set Counter to (GetNumRefs 18 0)
Set TempRef to (GetFirstRef 18 0)
While Counter > 0
	Let Counter -= 1
	if CompareModelPath "CFHARTrapEvilStonePCDefence"
		If DisabledCount == 0
			CFHARTrapEvilStonePCDefence1Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence1Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence1Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence1Ref.SetPos Z pos
			Set Disabled1Ref to TempRef
			Disabled1Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 1
		ElseIf DisabledCount == 1
			CFHARTrapEvilStonePCDefence2Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence2Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence2Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence2Ref.SetPos Z pos
			Set Disabled2Ref to TempRef
			Disabled2Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 2
		ElseIf DisabledCount == 2
			CFHARTrapEvilStonePCDefence3Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence3Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence3Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence3Ref.SetPos Z pos
			Set Disabled3Ref to TempRef
			Disabled3Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 3
		ElseIf DisabledCount == 3
			CFHARTrapEvilStonePCDefence4Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence4Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence4Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence4Ref.SetPos Z pos
			Set Disabled4Ref to TempRef
			Disabled4Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 4
		ElseIf DisabledCount == 4
			CFHARTrapEvilStonePCDefence5Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence5Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence5Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence5Ref.SetPos Z pos
			Set Disabled5Ref to TempRef
			Disabled5Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 5
		EndIf
	EndIf
	Set TempRef to GetNextRef
Loop

If DisabledCount > 0
	Message "Dark Welkynd Stones are disabled"
EndIf
End

ScriptEffectFinish is the same. The only difference is the first 'if'

 

I tested it in my testinghall and it didn't work. When I changed it for the specific editor IDs it had no problem

Link to comment
Share on other sites

Now that the spell is no longer cast on the activator, as you realized activators can't run spell effects, the default reference in this spell script is the player or whatever it's running on now. You need to tell CompareModelPath the model path of "what" to compare with this string. Try either

 

TempRef.CompareModelPath "CFHARTrapEvilStonePCDefence"

 

or if that doesn't work,

 

CompareModelPath "CFHARTrapEvilStonePCDefence" TempRef

 

One of them should work.

 

Though, what exactly should this comparison check for now? As it is right now it will only replace Activators using your replacement's NIF model (I take it "CFHARTrapEvilStonePCDefence" is found inside your replacement's NIF filename). This is surely not intended. I would compare the model path with the filename of the actual Dark Welkynd Stones ("ARTrapEvilStone01"), so those will be what gets replaced.

Link to comment
Share on other sites

TempRef.CompareModelPath "CFHARTrapEvilStonePCDefence" - this means it will compare the Nif of TempRef with "CFHARTrapEvilStonePCDefence"? if so it shouldn't make a difference... it's the same Nif . It's no problem to change it though.

And yes it is cast on-self now. I didn't think to set an ref to compare it to. Still learning.

 

What do you think of adding

                Let Counter -= 1
	If TempRef.GetID == CFHARTrapEvilStonePCDefence
		return
	EndIf
               if CompareModelPath "CFHARTrapEvilStonePCDefence"

should return be break?

I don't want the spell to be cast multiple times. I've seen simpler scripts get messed up by using them to add/remove/move when they can't find what they think should be there. Sometimes the engine seems to do strange things. Given what the spell is doing I may make it a Greater Power, though that would be in my main mod as I'd want the PC to earn it.

 

You said previously about the spell not removing all the Dark Stones if there is more than five. Is there any cells in vanilla with more than 5? I thought that would be a lot. I know given the mods available there could be a cell with 50. However the more I add in game the longer the script and the more persistent references (PS's) I'd have to create. I'm sure I read somewhere about PS's slowing the game.

Link to comment
Share on other sites

TempRef.CompareModelPath "CFHARTrapEvilStonePCDefence" will search for "CFHARTrapEvilStonePCDefence" to occur inside the model path of TempRef. So for example an object with a model path of "/meshes/architecture/ayleid/something/CFHARTrapEvilStonePCDefence.nif" will pass this check as true, whereas an actual Welkynd Stone Trap, with model path "/something/something/ARTrapEvilStone01.nif", will not pass this test.

It does not compare the model path of the object TempRef to the model path of the object CFHARTrapEvilStonePCDefence. The filename has to contain this string literally for the test to return true.

 

I couldn't find a function GetID, but using "If TempRef.GetIsID CFHARTrapEvilStonePCDefence" should do the trick. However, the function documentation fails to show how it's used on a specific reference. There is no "reference.GetIsID baseobject" but only "GetIsID baseobject". I 'think' it is the same as all other functions and "reference.GetIsID baseobject" is the way to go, but I can't guarantee it.

 

And inside of a While Loop to skip to the next step it should be "continue".

"break" will terminate the whole loop and jump immediately to after the "Loop" line,

and "return" will terminate the function execution entirely once it hits one of your placeholders.

Edited by DrakeTheDragon
Link to comment
Share on other sites

I didn't understand how comparemodelpath works. Thanks for explaining. I don't know why I wrote GedID, too tired probably

 

Thanks for all your help with this.

The current script - I will now be working on the new stone's script to make it attack enemies

 

Scriptname CFHSpellDarkWelkyndDefenceScript

Ref TempRef
Ref Disabled1Ref
Ref Disabled2Ref
Ref Disabled3Ref
Ref Disabled4Ref
Ref Disabled5Ref

Float Pos

Short Counter
Short DisabledCount

Begin ScripteffectStart
Set DisabledCount to 0
Set Counter to (GetNumRefs 18 0)
Set TempRef to (GetFirstRef 18 0)
While Counter > 0
	Let Counter -= 1
	If TempRef.GetIsID CFHARTrapEvilStonePCDefence
		Break
	EndIf
	If TempRef.CompareModelPath "ARTrapEvilStone01"
		If DisabledCount == 0
			CFHARTrapEvilStonePCDefence1Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence1Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence1Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence1Ref.SetPos Z pos
			Set Disabled1Ref to TempRef
			Disabled1Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 1
		ElseIf DisabledCount == 1
			CFHARTrapEvilStonePCDefence2Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence2Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence2Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence2Ref.SetPos Z pos
			Set Disabled2Ref to TempRef
			Disabled2Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 2
		ElseIf DisabledCount == 2
			CFHARTrapEvilStonePCDefence3Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence3Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence3Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence3Ref.SetPos Z pos
			Set Disabled3Ref to TempRef
			Disabled3Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 3
		ElseIf DisabledCount == 3
			CFHARTrapEvilStonePCDefence4Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence4Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence4Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence4Ref.SetPos Z pos
			Set Disabled4Ref to TempRef
			Disabled4Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 4
		ElseIf DisabledCount == 4
			CFHARTrapEvilStonePCDefence5Ref.MoveTo TempRef
			Set Pos to TempRef.GetPos X
			CFHARTrapEvilStonePCDefence5Ref.SetPos X pos
			Set Pos to TempRef.GetPos Y
			CFHARTrapEvilStonePCDefence5Ref.SetPos Y pos
			Set Pos to TempRef.GetPos Z
			CFHARTrapEvilStonePCDefence5Ref.SetPos Z pos
			Set Disabled5Ref to TempRef
			Disabled5Ref.MoveTo CFHDarkWelkyndStorageRef
			Set DisabledCount to 5
		EndIf
	EndIf
	Set TempRef to GetNextRef
Loop

If DisabledCount > 0
	Message "Dark Welkynd Stones are disabled"
EndIf
End

Begin ScriptEffectFinish
If DisabledCount == 0
	Return
EndIf
If DisabledCount >=1
	Disabled1Ref.MoveTo CFHARTrapEvilStonePCDefence1Ref
	Set Pos to CFHARTrapEvilStonePCDefence1Ref.GetPos X
	Disabled1Ref.SetPos X pos
	Set Pos to CFHARTrapEvilStonePCDefence1Ref.GetPos Y
	Disabled1Ref.SetPos Y pos
	Set Pos to CFHARTrapEvilStonePCDefence1Ref.GetPos Z
	Disabled1Ref.SetPos Z pos
	CFHARTrapEvilStonePCDefence1Ref.MoveTo CFHDarkWelkyndStorageRef
EndIf
If DisabledCount >=2
	Disabled2Ref.MoveTo CFHARTrapEvilStonePCDefence2Ref
	Set Pos to CFHARTrapEvilStonePCDefence2Ref.GetPos X
	Disabled2Ref.SetPos X pos
	Set Pos to CFHARTrapEvilStonePCDefence2Ref.GetPos Y
	Disabled2Ref.SetPos Y pos
	Set Pos to CFHARTrapEvilStonePCDefence2Ref.GetPos Z
	Disabled2Ref.SetPos Z pos
	CFHARTrapEvilStonePCDefence2Ref.MoveTo CFHDarkWelkyndStorageRef
EndIf
If DisabledCount >=3
	Disabled3Ref.MoveTo CFHARTrapEvilStonePCDefence3Ref
	Set Pos to CFHARTrapEvilStonePCDefence3Ref.GetPos X
	Disabled3Ref.SetPos X pos
	Set Pos to CFHARTrapEvilStonePCDefence3Ref.GetPos Y
	Disabled3Ref.SetPos Y pos
	Set Pos to CFHARTrapEvilStonePCDefence3Ref.GetPos Z
	Disabled3Ref.SetPos Z pos
	CFHARTrapEvilStonePCDefence3Ref.MoveTo CFHDarkWelkyndStorageRef
EndIf
If DisabledCount >=4
	Disabled4Ref.MoveTo CFHARTrapEvilStonePCDefence4Ref
	Set Pos to CFHARTrapEvilStonePCDefence4Ref.GetPos X
	Disabled4Ref.SetPos X pos
	Set Pos to CFHARTrapEvilStonePCDefence4Ref.GetPos Y
	Disabled4Ref.SetPos Y pos
	Set Pos to CFHARTrapEvilStonePCDefence4Ref.GetPos Z
	Disabled4Ref.SetPos Z pos
	CFHARTrapEvilStonePCDefence4Ref.MoveTo CFHDarkWelkyndStorageRef
EndIf
If DisabledCount >=5
	Disabled5Ref.MoveTo CFHARTrapEvilStonePCDefence5Ref
	Set Pos to CFHARTrapEvilStonePCDefence5Ref.GetPos X
	Disabled5Ref.SetPos X pos
	Set Pos to CFHARTrapEvilStonePCDefence5Ref.GetPos Y
	Disabled5Ref.SetPos Y pos
	Set Pos to CFHARTrapEvilStonePCDefence5Ref.GetPos Z
	Disabled5Ref.SetPos Z pos
	CFHARTrapEvilStonePCDefence5Ref.MoveTo CFHDarkWelkyndStorageRef
EndIf
End

 

New script to make the replacement stones attack the PC's enemies. I added a few lines to the above script, all they do is reset the TempTimer in the script below

 

Scriptname CFHDarkWelkyndAttackScript

Ref TempRef
Ref Self

Float SpellRank
Float Counter
Float Aggro
Float Dispo
Float Timer
Float TempTimer
Float Distance

Begin GameMode
If Player.GetLevel <= 5
	Set SpellRank to 1
ElseIf (Player.GetLevel >= 6) && (Player.GetLevel <= 10)
	Set SpellRank to 2
ElseIf (Player.GetLevel >= 11) && (Player.GetLevel <= 15)
	Set SpellRank to 3
ElseIf (Player.GetLevel >= 16) && (Player.GetLevel <= 20)
	Set SpellRank to 4
ElseIf (Player.GetLevel >= 21)
	Set SpellRank to 5
EndIf

Set Timer to (GetSecondsPassed - TempTimer)

Set Self to GetSelf

If Timer >= 8
	Set Counter to (GetNumRefs 69 0)
	Set TempRef to (GetFirstRef 69 0)
	While Counter > 0
		Let Counter -= 1
		set Distance to (TempRef.GetDistance Player)
		If (TempRef.GetLOS Self) && (Distance < 700)
			Set Aggro to (TempRef.GetAv Aggression)
			Set Dispo to (TempRef.GetDisposition Player)
			If (0 > Dispo - Aggro)
				If SpellRank == 1
					Cast StandardShockDamageTarget1Novice TempRef
				ElseIf SpellRank == 2
					Cast StandardShockDamageTarget2Apprentice TempRef
				ElseIf SpellRank == 3
					Cast StandardShockDamageTarget3Journeyman TempRef
				ElseIf SpellRank == 4
					Cast StandardShockDamageTarget4Expert TempRef
				ElseIf SpellRank == 5
					Cast StandardShockDamageTarget5Master TempRef
				EndIf
			EndIf
		EndIf
		Set TempRef to (GetNextRef 69 0)
	Loop
	Set TempTimer to GetSecondsPassed
EndIf
End

 

Edited by cfh85
Link to comment
Share on other sites

I figured as much for the "GetID" part, a typo, but I had to make sure you are using the correct one in your scripts.

 

Nice idea, "reprogramming" the turrets to friendly fire. Definitely a funny situation to see Ayleid remnants getting fried by their own traps! Reminds me of FO3 and hacking defence systems.

 

Just glad it's working now.

 

Only one thing:

Better use "continue" in place of "break".

The way it is now the "break" statement will stop the whole scanning as soon as it comes across a replacement stone, no matter how many other stones there still are left to be replaced!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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