Basic idea for a Automatic Casting Perk

Post » Thu Jun 21, 2012 4:51 am

Hey guys,

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.
User avatar
Juan Cerda
 
Posts: 3426
Joined: Thu Jul 12, 2007 8:49 pm

Post » Thu Jun 21, 2012 3:41 am

I think you're making this much more complicated that it has to be.

Your perk can just use the perk entry point "Apply Combat Hit Spell" to apply a spell to the NPC you hit. Just give it the conditions that the player has to be equipped with a one handed sword and a spell (http://www.creationkit.com/GetEquippedItemType).
User avatar
Khamaji Taylor
 
Posts: 3437
Joined: Sun Jul 29, 2007 6:15 am

Post » Thu Jun 21, 2012 12:56 am

well, thanks for your help but i guess thats the point at which i stop to ask here in the forum. i might post it when finished..
see you
User avatar
Mrs. Patton
 
Posts: 3418
Joined: Fri Jan 26, 2007 8:00 am

Post » Thu Jun 21, 2012 6:25 am

If you use the "Apply Combat Hit Spell" perk entry point, you can choose the spell to be a scripted spell. The script can force the caster (ie the player) to cast whatever spell is in his/her left hand.

There's no need to go through all the trouble of dynamically attaching scripts to actors.
User avatar
Liii BLATES
 
Posts: 3423
Joined: Tue Aug 22, 2006 10:41 am

Post » Thu Jun 21, 2012 5:19 am

Ok, did it. And its working. Not everything tested but working with destructive spells so far. need to tweak it and more advanced testing.

Spoiler
Scriptname aaSpellswordDeliverScript extends activemagiceffect  ;Script runs on Target after it got hit. Belongs to Spellsword-Perk.Actor TargetSpell EquippedSpellObjectReference ActorObjectObjectReference TargetObjectEvent OnEffectStart(Actor akTarget, Actor akCaster)    if (Game.GetPlayer().GetEquippedItemType(1) == 9)    ;Right is Spell        EquippedSpell = Game.GetPlayer().GetEquippedSpell(1)            elseif (Game.GetPlayer().GetEquippedItemType(0) == 9)    ;Left is Spell        EquippedSpell = Game.GetPlayer().GetEquippedSpell(0)    EndIf        if (EquippedSpell.IsHostile())        Target = akTarget    Else        Target = Game.GetPlayer()    EndIf            ActorObject = Game.GetPlayer()        TargetObject = Target        EquippedSpell.Remotecast(ActorObject, Game.GetPlayer.(), TargetObject)        ;Player is caster and thus always responsible (first two parameters, ObjectReference and Actor.        ;Target might change depending on type of spell.                Dispel()EndEventt 

Does the actor who casts the spell use perks or do i have to add conditional checks and effects seperatly to cover the perks' effects which affect the spell?
I figured out that that "cast" doent deplete magicka. It seems I have to use UseMagic - AI-Packages....
User avatar
Chris Ellis
 
Posts: 3447
Joined: Thu Jul 26, 2007 10:00 am


Return to V - Skyrim