Before I go on with scripting I would like to know your opinion if this idea is basically working as shown in the concepts. If you have better ideas, please tell me.
I am a total greenhorn in scripting, especially in terms of terminology and syntax, so please be lenient with me.
My perk idea:
If you have a One-Handed Weapon equipped in either hands and a spell in the other. After hitting an opponent with your One-Handed Weapon, if hostile the spell should be cast automatically at the same target. If not hostile, it should be cast at yourself (e.g. restoration spells).
Concept:
The basic idea is to distribute a script (ActivatorScript) containing an On-Hit activator to the Target, which then returns the targets' ID and change a variable "stating" the target got hit. The changed variable then can be used as an activator for another script (FireSpellScript) that fires the equipped spell at the target with the corresponding ID. It should be possible to define changes inside the FireSpellScript.
Momentary route:
1) I use the example of RandomNoob on the ck-wiki "Dynamically Attaching Scripts" - basically distributing a spell containing the ActivatorScript by using a Cloak which is placed on the player.
I just replaced the wiki-examples MonitorEffect-script with the ActivatorScript shown below. Additonally i am creating the FireSpellScript which will be put on the player and use the targets ID as well as the activator variable.
Another idea:
2) Using an ability with delivery type "OnContact" to directly deliver the ActivatorScript and then go on as above.
I have no idea if 2) will work at all and if yes, does it have big advantages over 1)? Maybe some modders can give me some feedback on these 2 ways to distribute the ActivatorScript or present me alternatives of how to accomplish this perk.
Regarding 1) I did some scripting. I dont have an idea what makes an object unique (or actor? - the NPC which is affected by the script). Therefore i just read out the FormID but I might be wrong totally.
Additionally i am not sure how to deliver the variables to another script. Afaik one can do this via properties.
(At the moment i learn by Trail and Error as well as reading up and down the wiki).
Working ActivatorScript
Spoiler
Scriptname aaSpellswordActivatorScript extends activemagiceffect Bool Property TGHit AutoInt Property MyPublicID AutoActor Property MyObjectName Auto;Defines properties to provide the detection of an On-Hit event on the Object "MyPublicID to other scripts"Actor MySelfint MyprivateIDEvent OnEffectStart(Actor akTarget, Actor akCaster) MySelf = akTarget MyObjectName = akTarget MyprivateID = MySelf.GetFormID() Debug.Notification("MySelf: " + MySelf + " and MyprivateID: " + MyprivateID + "")EndEvent;Saves the Actor-ID locally on initializingEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, \ bool abSneakAttack, bool abBashAttack, bool abHitBlocked) if (akAggressor == Game.GetPlayer()) TGHit = true MyPublicID = MyprivateID Debug.Notification("TargetGothit: " + TGHit + " , MyPublicID: " + MyPublicID + "") EndIf EndEvent;If the target is hit this event switches 'TGHit' to true, fetches the local variable 'MySelf' and delivers it to the property 'MyPublicID'Frame of FireSpellScript (maybe it helps to understand my intention)
Spoiler
Scriptname aaSpellswordOnHitFireSpellScript extends activemagiceffect Bool Property TGHit AutoInt Property MyPublicID AutoActor Property MyObjectName AutoInt CombatStateEvent OnCombatStateChanged(Actor akTarget, int aeCombatState) if (akTarget == Game.GetPlayer()) CombatState = aeCombatState if (CombatState == 0) ;not in Combat UnregisterForUpdate() Debug.Notification("Combat Ended") ElseIf (CombatState == 1) ;in Combat RegisterForSingleUpdate(0.25) Debug.Notification("In Combat") Endif EndIfEndEvent;Activator for OnUpdate Event triggered by CombatState.Event OnUpdate() if (TGHit == true && CombatState == 1) Debug.Notification("NPC " + MyobjectName + " with ID " + MyPublicID + "got hit") TGHit = False RegisterForSingleUpdate(0.25) EndIfEndEvent;Event which later contains the Spellcasting and is fired if Target Got Hit (TGHit == true)Ps.: Can anyone insert the URL to RandomNoobs Wiki entry? I will be allowed to link in 4 days.
