Help with an OnHit script

Post » Fri Nov 16, 2012 6:41 pm

So I want to make a script that watches to see if there player is using magic or a weapon when they hit the desired object/actor. In the companions quest you can only fight Vilkas with a weapon and not magic but I couldn't find the script that was used to do this. Any one know how to do this?
User avatar
Carolyne Bolt
 
Posts: 3401
Joined: Mon Jul 10, 2006 4:56 am

Post » Sat Nov 17, 2012 1:23 am

No one knows how? All I'm looking for is a script that see's whether the player is using a weap or not. It's going to be for brawl, when the player brawls if he uses a weapon I want the brawl to end. So i'm looking for a way for it to check if the player is using a weapon or not when they hit the brawler. Does anyone know if this is even possible?
User avatar
Carlos Vazquez
 
Posts: 3407
Joined: Sat Aug 25, 2007 10:19 am

Post » Fri Nov 16, 2012 8:30 pm

Actor property Player AutoState BusyEndStateEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \			bool abBashAttack, bool abHitBlocked)GoToState("Busy")If IsWeapMagicEquipped()   ;end BrawlEndIfGoToState("")EndEventBool Function IsWeapMagicEquipped()Int i = 1While i <= 9   If Player.GetEquippedItemType(0) == i || Player.GetEquippedItemType(1) == i	   Return True   EndIf   i += 1EndWhileReturn FalseEndFunction

GetEquippedItemType() returns an Int tied to what the actor currently has equipped in his Hands. 1 thru 9 are for weapons and magic, so if you check for if the player has one of those equipped each hit (State change will prevent the Stack from flooding), you can end the brawl.
User avatar
candice keenan
 
Posts: 3510
Joined: Tue Dec 05, 2006 10:43 pm

Post » Sat Nov 17, 2012 5:54 am

Thanks, Thomas! This is very helpful, and I learned something new in scripting. :biggrin:
User avatar
Jordan Fletcher
 
Posts: 3355
Joined: Tue Oct 16, 2007 5:27 am

Post » Fri Nov 16, 2012 8:55 pm

I would rather use something like this:

Actor Property playerRef autoState BusyEndStateEvent OnHit(ObjectReference attacker, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)GoToState("Busy")if((attacker as actor) == playerRef)   if(aksource as weapon)	 debug.notification("Player used a weapon!")   elseif(aksource as spell)	 debug.notification("Player used a spell!")   endifendifGoToState("")EndEvent
User avatar
Jason White
 
Posts: 3531
Joined: Fri Jul 27, 2007 12:54 pm

Post » Fri Nov 16, 2012 11:30 pm

hand-to-hand is considered a weapon so this won't work, this is how I thought it would look though.
User avatar
Emma Louise Adams
 
Posts: 3527
Joined: Wed Jun 28, 2006 4:15 pm

Post » Fri Nov 16, 2012 9:40 pm

I would rather use something like this:



Won't work. Hand-to-hand is classified as a Weapon (I checked), so the script will fire off every time you hit the guy including with your fists.

Which is why you need to perform the EquippedItemType check, it's the only way you can effectively detect if the player is unarmed.
User avatar
Matthew Aaron Evans
 
Posts: 3361
Joined: Wed Jul 25, 2007 2:59 am

Post » Sat Nov 17, 2012 12:45 am

You could streamline it down to this, though:

Actor property Player AutoState BusyEndStateEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \			bool abBashAttack, bool abHitBlocked)GoToState("Busy")If IsWeapMagicEquipped()   ;end BrawlEndIfGoToState("")EndEventBool Function IsWeapMagicEquipped()Int i = 1If Player.getEquipped Weapon() == True || Player.getEquippedWeapon(false) == True   Return TrueElseIf Player.getEquippedSpell(0) == True || Player.getEquippedSpell(1) == True   Return TrueElse   Return FalseEndIfEndFunction

Even though Hand-to-hand is considered a weapon, it is never considered to be equipped. So while checking for the source as a Weapon in this context will fail, checking if the player has something specific equipped will work.

Or even this, perhaps:

Weapon property Unarmed AutoState BusyEndStateEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \			bool abBashAttack, bool abHitBlocked)GoToState("Busy")If akSource != Unarmed   ;end BrawlEndIfGoToState("")EndEvent

Since Unarmed is a defined record in the CK (it's the hardcoded Weapon hand-to-hand uses), you could do that just fine.
User avatar
Marcia Renton
 
Posts: 3563
Joined: Fri Jan 26, 2007 5:15 am

Post » Fri Nov 16, 2012 5:48 pm

Wow that last option seems so obvious, I don't know how I didn't think of that. :facepalm:
User avatar
John Moore
 
Posts: 3294
Joined: Sun Jun 10, 2007 8:18 am

Post » Fri Nov 16, 2012 8:32 pm

You could also use that script universally, not just for the player. So you could perform the detection on anyone you choose. Might make for an interesting mechanic regarding cheaters in your mod. :)
User avatar
mishionary
 
Posts: 3414
Joined: Tue Feb 20, 2007 6:19 am

Post » Sat Nov 17, 2012 4:04 am

Another way to do it is to use the onMagicEffectApply event... that's what the Vilkas script uses. The source is "C00TrainerScript" and the C00.. files that have Vilkas in the name.
User avatar
Joanne
 
Posts: 3357
Joined: Fri Oct 27, 2006 1:25 pm


Return to V - Skyrim