Is it possible to "piggy-back" or interrupt a script

Post » Thu Jun 21, 2012 11:09 pm

I'm curious if such a scenario is possible, and if so, then how?


Person A writes a script to do something.
Person B writes a script to augment Person A's script.
Person A inserts a point in his script to allow Person B's script to interact if present, but not required.


That is assuming that Person A was kind enough to permit the use of Person B's script.
More specifically, is the following scenario possible?


Script A detects a hit, then runs it's own damage formula.
Script B determines if a hit is strong enough to cause damage or not.
Script A is modified to allow Script B (if present) to run whenever it detects a hit. If Script B returns true (or is not present), then Script A will continue with its own damage formula. If Script B returns false, no damage is applied.


How would such a thing work? Would it be dangerous for the original scripter to allow another person's script to run like that? Do you believe there would be many scripters open to such collaboration?


Thank you! :-D
User avatar
Maria Garcia
 
Posts: 3358
Joined: Sat Jul 01, 2006 6:59 am

Post » Fri Jun 22, 2012 12:55 am

This really depends on the scripts you're talking about and whether or not these scripts belong in the same mod. In the case of your example, this is entirely possible, and the second script doesn't even have to belong in a mod at all.

Script A version 1.0:
Spoiler
Scriptname ExampleA extends ActiveMagicEffectActor MySelfFloat HealthEvent OnEffectStart(Actor akTarget, Actor akCaster)	MySelf = akTarget	Health = MySelf.GetActorValue("Health")EndEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	Float Damage = Health - MySelf.GetActorValue("Health")	if (akSource as Spell) && (abSneakAttack)		Debug.Notification("Magical sneak attack! Triple damage!")		MySelf.DamageActorValue("Health", 2 * Damage)	endif	Health = MySelf.GetActorValue("Health")EndEvent

Script B:
Spoiler
Scriptname ExampleBBool Function GetDamageNegated(Actor Victim, Float Damage)	if (Damage < Victim.GetBaseActorValue("Health") * 0.05)		Debug.Notification("Damage was less than 5% of base health. Negated.")		Victim.RestoreActorValue("Health", Damage)		Return True	else		Return False	endifEndFunction

Script A version 2.0:
Spoiler
Scriptname ExampleA extends ActiveMagicEffectimport ExampleBActor MySelfFloat HealthEvent OnEffectStart(Actor akTarget, Actor akCaster)	MySelf = akTarget	Health = MySelf.GetActorValue("Health")EndEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	Float Damage = Health - MySelf.GetActorValue("Health")	Bool Ignore = GetDamageNegated(MySelf, Damage)	if !Ignore		if (akSource as Spell) && (abSneakAttack)			Debug.Notification("Magical sneak attack! Triple damage!")			MySelf.DamageActorValue("Health", 2 * Damage)		endif	endif	Health = MySelf.GetActorValue("Health")EndEvent
User avatar
Lori Joe
 
Posts: 3539
Joined: Tue Jun 20, 2006 6:10 am

Post » Thu Jun 21, 2012 9:43 am

Sounds great! Thank you so much! Especially for the examples! :-D
User avatar
Roanne Bardsley
 
Posts: 3414
Joined: Wed Nov 08, 2006 9:57 am


Return to V - Skyrim