Jump to content

Need help with CastAs Function


jags78

Recommended Posts

Hey Scripters

 

I'm trying to use the 'CastAs' function to trigger regis2k's outfit switcher mod. Here a snippet from my test-script:

If akTarget == PlayerRef && akCaster == PlayerRef && akEffect == WDC_PillMagicEffect
	ScriptObject scrOutfitSwitcher = PlayerRef.CastAs("OutfitSwitcher")

	If scrOutfitSwitcher
		int loadout = 1
		bool silent = false
		bool force  = false

		Var[] param = new Var[3]
		param[0] = loadout
		param[1] = silent
		param[2] = force
		scrOutfitSwitcher.CallFunction("ApplyLoadout", param)
	Else
		Debug.Notification("Ups...")
	EndIf

RegisterForMagicEffectApplyEvent(PlayerREF, PlayerREF, WDC_PillMagicEffect, true)
EndIf

The Event get triggered, but i get the "Ups..." notification.

 

Does someone c the error? Does this even work with quest-related scripts?

 

Link to comment
Share on other sites

Jep... That was it... Thx Reneer. You're the man.

 

I case somebody cares what the test-code looks like:

Event OnMagicEffectApply(ObjectReference akTarget, ObjectReference akCaster, MagicEffect akEffect)
	If akTarget == PlayerRef && akCaster == PlayerRef && akEffect == WDC_PillMagicEffect
		If Game.IsPluginInstalled("OutfitSwitcher.esp")
			Quest qOutfitSwitcher = Game.GetFormFromFile(0x00000802, "OutfitSwitcher.esp") as Quest
			
			ScriptObject scrOutfitSwitcher = qOutfitSwitcher.CastAs("OutfitSwitcher")
	
			If scrOutfitSwitcher
				int loadout = 1
				bool silent = false
				bool force  = false
	
				Var[] param = new Var[3]
				param[0] = loadout
				param[1] = silent
				param[2] = force
				scrOutfitSwitcher.CallFunction("ApplyLoadout", param)
			Else
				Debug.Notification("Ups...")
			EndIf
	
			RegisterForMagicEffectApplyEvent(PlayerREF, PlayerREF, WDC_PillMagicEffect, true)
		Else
			Debug.Notification("OutfitSwitcher not installed")
			RegisterForMagicEffectApplyEvent(PlayerREF, PlayerREF, WDC_PillMagicEffect, true)
		EndIf
	EndIf

EndEvent

C u when the next problem arises ;)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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