Jump to content

Help request for script with SKSE functions


VRNord

Recommended Posts

Hello!

 

I am trying to write a script to reimagine the DLC2 Chaos enchantment. I want to randomly select one of fire, frost or shock spells (instead of vanilla that has a 50% chance of each for each hit, meaning sometimes you get no effect and sometimes 2 or 3 overlap). I wrote a simple script for that that works like a charm.

 

 

 

ScriptName RandomEffectScript extends ActiveMagicEffect
Spell Property FireEffect Auto
Spell Property FrostEffect Auto
Spell Property ShockEffect Auto
Event OnEffectStart(Actor akTarget, Actor akCaster)
; Generate a random number between 1 and 3
int randomNum = Utility.RandomInt(1,3)
; Apply a random effect based on the random number
if (randomNum == 1)
; Apply Effect A
FireEffect.Cast(akTarget)
elseif (randomNum == 2)
; Apply Effect B
FrostEffect.Cast(akTarget)
else
; Apply Effect C
ShockEffect.Cast(akTarget)
endif
EndEvent

 

However, then I decided to get fancy. I want to apply the random fire/frost/shock spell to the weapon upon drawing it and again after each hit so I can apply the appropriate visual enchantment shader and art to the weapon and have that visual effect change after every hit. (So draw the sword and it shows shock visual shader/art. Hit NPC and he has shock damage. The weapon then switches to the next random spell, fire in this case, and shows the fire visual effect. When I hit the NPC again he takes fire damage, rinse and repeat.)

 

So I found that SKSE has the necessary functions to do this: SetEnchantShader() and SetEnchantArt() in its MagicEffect.psc script.

 

I wrote the following script that theoretically, at least, will do what I want:

 

 

 

ScriptName RandomEffectScript2 extends ActiveMagicEffect
Spell Property FireEffect Auto
Spell Property FrostEffect Auto
Spell Property ShockEffect Auto
Enchantment Property FireShader Auto
Enchantment Property FrostShader Auto
Enchantment Property ShockShader Auto
Art Property FireArt Auto
Art Property FrostArt Auto
Art Property ShockArt Auto
ObjectReference Property akSource Auto
Projectile Property akProjectile Auto
Event OnEffectStart(Actor akTarget, Actor akCaster)
akSource = akCaster as ObjectReference
EndEvent
Event OnHit(ObjectReference akAggressor, Form akSourceForm, Projectile akProjectileRef, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
CastRandomSpell(akSource as ObjectReference)
akProjectile = akProjectileRef
EndEvent
Function CastRandomSpell(ObjectReference akTarget)
int randomNum = Utility.RandomInt(1,3)
if (randomNum == 1)
FireEffect.Cast(akTarget)
akSource.SetEnchantShader(FireShader)
akSource.SetEnchantArt(FireArt)
akProjectile.SetEnchantShader(FireShader)
akProjectile.SetEnchantArt(FireArt)
elseif (randomNum == 2)
FrostEffect.Cast(akTarget)
akSource.SetEnchantShader(FrostShader)
akSource.SetEnchantArt(FrostArt)
akProjectile.SetEnchantShader(FrostShader)
akProjectile.SetEnchantArt(FrostArt)
else
ShockEffect.Cast(akTarget)
akSource.SetEnchantShader(ShockShader)
akSource.SetEnchantArt(ShockArt)
akProjectile.SetEnchantShader(ShockShader)
akProjectile.SetEnchantArt(ShockArt)
endif
EndFunction

...but it won't compile, spits out the error message that it can't find the SetEnchantShader and SetEnchantArt functions. I unzipped all the SKSE scripts to data\source\scripts and in the CK Papyrus Manager I can even see/read them (and compile them!) but when I then try to compile the above script it tells me it can't find those 2 functions. Grrr..
Am I missing something? All I can figure is either I did something so wrong with my RandomEffectScript2 script that it can't even figure out what I am trying to do, or maybe I need to do something so the compiler knows to look at the SKSE MagicEffect.psc script to find those functions.
I am using CK to compile, and it can compile the SKSE scripts so I know it is working.
Thoughts? (also any other thoughts on ways the script could be improved to better achieve what I am after would be appreciated!)
EDIT: I am realizing the SKSE function SetEnchantment() would be a lot cleaner! But can't get that to compile either..
Edited by JaymzPaul
Link to comment
Share on other sites

That's a good point. I actually got it to compile with just setEnchantment():

 

 

 

Scriptname ApplyRandomEnchantment extends ActiveMagicEffect
Enchantment Property Enchantment1 Auto
Enchantment Property Enchantment2 Auto
Enchantment Property Enchantment3 Auto
Function SetEnchantment(Enchantment source, float maxCharge) Native
Event OnEffectStart(Actor akTarget, Actor akCaster)
EquipEvent()
EndEvent
Event OnWeaponHit(Actor akAggressor, Form akWeapon, Projectile akProjectile)
EquipEvent()
EndEvent
Function EquipEvent()
Int iRand = Utility.RandomInt(1, 3)
If iRand == 1
SetEnchantment(Enchantment1, 100.0)
ElseIf iRand == 2
SetEnchantment(Enchantment2, 100.0)
Else
SetEnchantment(Enchantment3, 100.0)
EndIf
EndFunction

...but it doesn't do anything in game. I think that may be due to the Equip Enchantment bug fixed with this mod which isn't available for VR - since the weapon is already equipped when the enchantment changes are applied nothing happens. That is my theory anyway.
Link to comment
Share on other sites

 

how would you do that? SKSE isn't a plugin.

At least in MO2 the scripts and their source must be made into a plugin and activated like any mod, while the dlls and exe are placed in the main Skyrim folder along with skyrim.exe

 

The scripts and source scripts for SKSE do not need to made into a mod folder for MO2. They can be applied to the correct locations within the main game folder. The only reason to create a mod folder for use in MO2 is when the user wants to maintain an "as clean as possible" game folder. Even then there is no "plugin". There is just a mod folder needing to be active in the priority window (left side). Plugins are listed in the load order (right side) and nothing of SKSE should appear within the plugin list.

 

@JaymzPaul

SetEnchantment applies to the base object and not a specific object reference. As such, it most likely won't take affect until the equipped reference gets unequipped. So, have you tried force unequipping and re-equipping? Might look weird in game and might not be ideal either. But at least you would know if the enchantments are applying.

 

You could also try putting all three magic effects (fire, frost and shock) on the same enchantment. Use conditions for a global variable to be at a specific value. At each use randomize the value and update the global variable. That might work, might not.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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