Getting a script to work properly...

Post » Sun Sep 29, 2013 6:28 am

This is the script I've been trying to get to work:

Scriptname Cerebral_TrainingDummy extends ObjectReference  {Allows training dummies to be used for leveling. Usefulness declines as you grow stronger in your skill.};====== Ranged Weapons ===================Keyword Property WeapTypeBow  AutoKeyword Property VendorItemArrow  AutoKeyword Property WeapTypeBoundArrow  Auto;====== One-Handed Weapons================Keyword Property WeapTypeMace  AutoKeyword Property WeapTypeWarAxe  AutoKeyword Property WeapTypeDagger  AutoKeyword Property WeapTypeSword  Auto;====== Two-Handed Weapons================Keyword Property WeapTypeGreatsword  AutoKeyword Property WeapTypeBattleaxe  AutoKeyword Property WeapTypeWarhammer  Auto;====== Destruction Magic=================Keyword Property MagicDamageFire  AutoKeyword Property MagicDamageFrost  AutoKeyword Property MagicDamageShock  Auto;====== Other Properties==================Actor Property Player AutoEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	;Debug.Notification("Hit detected.")    	if (akAggressor == Game.GetPlayer())		Debug.Notification("The player hit me!")		if akSource.HasKeyword(WeapTypeSword)			Debug.Notification("Hit with a one-handed weapon!")			Game.AdvanceSkill("OneHanded", 10.0)		endif	endifEndEvent

The code works great at detecting when the player hits the activator, but it fails to recognize when I'm hitting it with an iron sword.

User avatar
Laura-Jayne Lee
 
Posts: 3474
Joined: Sun Jul 02, 2006 4:35 pm

Post » Sun Sep 29, 2013 4:01 pm

Are your properties filled?

User avatar
Kayla Bee
 
Posts: 3349
Joined: Fri Aug 24, 2007 5:34 pm

Post » Sun Sep 29, 2013 6:02 pm

probably might need to cast that akSource before checking keyword (to weapon?)?

User avatar
Khamaji Taylor
 
Posts: 3437
Joined: Sun Jul 29, 2007 6:15 am

Post » Sun Sep 29, 2013 7:27 pm

The properties auto-fill, don't they? And what do you mean about casting akSource?

User avatar
Mizz.Jayy
 
Posts: 3483
Joined: Sat Mar 03, 2007 5:56 pm

Post » Sun Sep 29, 2013 10:41 am

They auto-fill if you hit the auto-fill button in the CK. Without this, they point to nothing.

And by casting he means (akSource as Weapon). akSource is a Form Type object, so you can only use Form functions on it. If you cast it to Weapon (which extends Form) you can use both Weapon and Form functions on it (assuming that the object is indeed a Weapon). However I don't believe that should be necessary as HasKeyword is just a Form function....

Also, I noticed you have a Player property in your script but don't use it. You should replace Game.GetPlayer() with this property as using it will make your script run a bit faster. Also "PlayerRef" will autofill instead of just "Player".

User avatar
Benji
 
Posts: 3447
Joined: Tue May 15, 2007 11:58 pm


Return to V - Skyrim