Attaching OnHit() to Player.

Post » Wed Jun 20, 2012 6:10 am

So I've read that it's possible to attach the OnHit event to the player by using the ReferenceAlias in the quest tab.

So, let's say that I want to record a bit of data every time the player is hit with power attack and has less than 25% of health left and the code looks a little like this:

Scriptname MyHitScript extends ReferenceAlias{Record data when player is hit.}GlobalVariable property WoundLevel autoEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)if (abPowerAttack == true)int PlayerHealth = Game.GetPlayer().GetActorValuePercentage("Health") as intActorBase PlayerBase = Game.GetPlayer().GetBaseObject() as ActorBaseRace PlayerRace = PlayerBase.GetRace()       If (PlayerHealth <= 0.25)          debug.MessageBox("The strike was permanently crippling! Your abilities have been affacted, and you have a scar!")          WoundLevel.Mod(1)	  endifendifEndEvent

I create a new quest and then click on the Quest Alias tab and create new by selecting "Unique Actor - Player". I then attach the above script to that Alias. Make sure that the quest runs at launch, and that it is set to start up.

If anyone knows what I am missing or doing wrong please be so kind to point me in the right direction.
User avatar
dean Cutler
 
Posts: 3411
Joined: Wed Jul 18, 2007 7:29 am

Post » Wed Jun 20, 2012 8:14 am

I'm assuming it isn't working? You never said if it wasn't or not :tongue:

I'm pretty sure the script is supposed to extend to Actor, not ReferenceAlias. But I could be wrong.

EDIT: also you never declaired your "PlayerHealth" integer. At least, I think. I'm no expert :PYou need to do that at the start of the script like you would with your "WoundLevel" property.

To declare it, simply go "int PlayerHealth"

This lets the script know that you want to keep track of some variable called "PlayerHealth" somewhere in the script.

Then when you want to set what the actual value for PlayerHealth is, you do pretty much what you did, except get rid of the "int" before.
User avatar
Jay Baby
 
Posts: 3369
Joined: Sat Sep 15, 2007 12:43 pm

Post » Wed Jun 20, 2012 12:25 pm

I can't see anything wrong with your script. The way you described creating the Quest and Alias Reference sounds correct, too.
The only advice I can give you is to add a lot of "Debug.Notification()" to see if your variables are set up properly, the trigger is running, etc.

I don't know what you're using these two lines for:

ActorBase PlayerBase = Game.GetPlayer().GetBaseObject() as ActorBaseRace PlayerRace = PlayerBase.GetRace()

I assume you know, but I reccomend putting a semi-colon infront of them (make the comments) so that they don't affect the script. -Since, as far as I can tell, your script isn't using the information anyway.



I'm pretty sure the script is supposed to extend to Actor, not ReferenceAlias. But I could be wrong.

EDIT: also you never declaired your "PlayerHealth" integer. At least, I think. I'm no expert :PYou need to do that at the start of the script like you would with your "WoundLevel" property.

Since it's attached to an Alias "ReferenceAlias" is the correct extension.
He declares the variable when setting it. -Personally I would move it outside of the first "if-statement", though, but I doubt it makes any difference.
User avatar
Francesca
 
Posts: 3485
Joined: Thu Jun 22, 2006 5:26 pm

Post » Wed Jun 20, 2012 6:56 am

You didn't say what the error was, so I'm going to assume it compiles fine, because I don't see anything wrong with it. I think your problem might be this line:

int PlayerHealth = Game.GetPlayer().GetActorValuePercentage("Health") as int 

Int means integer. That means a whole number. You can see the problem, right?
User avatar
Daramis McGee
 
Posts: 3378
Joined: Mon Sep 03, 2007 10:47 am

Post » Wed Jun 20, 2012 2:56 am

I'm assuming it isn't working? You never said if it wasn't or not :tongue:

I'm pretty sure the script is supposed to extend to Actor, not ReferenceAlias. But I could be wrong.

EDIT: also you never declaired your "PlayerHealth" integer. At least, I think. I'm no expert :PYou need to do that at the start of the script like you would with your "WoundLevel" property.

To declare it, simply go "int PlayerHealth"

This lets the script know that you want to keep track of some variable called "PlayerHealth" somewhere in the script.

Then when you want to set what the actual value for PlayerHealth is, you do pretty much what you did, except get rid of the "int" before.


this script is just roughly written up... i have declared playerhealth in the full script but, you were correct, it still isn't working. :P
User avatar
GabiiE Liiziiouz
 
Posts: 3360
Joined: Mon Jan 22, 2007 3:20 am

Post » Tue Jun 19, 2012 11:18 pm

Variables in Papyrus have block scope, so your PlayerHealth variable will be destroyed after the conditional statement in which it's declared has finished. You can leave the assignment in there, but you'll need to move the declaration out of the event if you want the variable to persist, but otherwise it'll be fine just where it is.

The problem is, as RandomNoob said, that you're using the wrong data type. Use a variable of type float instead.

Cipscis
User avatar
Josh Trembly
 
Posts: 3381
Joined: Fri Nov 02, 2007 9:25 am

Post » Wed Jun 20, 2012 4:43 am

Yeah, I noticed. Thanks for pointing that out.

It seems as though the only problem was wrong variable type. Script is now working :)
User avatar
emily grieve
 
Posts: 3408
Joined: Thu Jun 22, 2006 11:55 pm


Return to V - Skyrim