Need Help With Scripting (Berserker mod)

Post » Sun Jun 17, 2012 9:42 pm

After some more studying on the wiki, I have no errors! Hurrah! Now to test to see if it works in game. Thanks a lot for all your help guys!

Here's the code, in case anyone was curious (I can probably cut out some extraneous crap now but I'll test it first):

Scriptname newscript1 Extends Quest;Sacrier's Blood Script version .1ReferenceAlias Player_Aliasint UnarmedDamage = 0int Health = 0int LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()ObjectReference Player = Player_Alias.GetReference()registerForUpdate(0.1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()  Boost = CurrentActorHealth - LastActorHealth  If LastActorHealth != Game.GetPlayer().GetActorValue(Health)   Game.GetPlayer().ModAV(UnarmedDamage, Boost)  EndIf  CurrentActorHealth = LastActorHealth  LastActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState
User avatar
Nicole Elocin
 
Posts: 3390
Joined: Sun Apr 15, 2007 9:12 am

Post » Sun Jun 17, 2012 11:37 pm

After some more studying on the wiki, I have no errors! Hurrah! Now to test to see if it works in game. Thanks a lot for all your help guys!

Here's the code, in case anyone was curious (I can probably cut out some extraneous crap now but I'll test it first):

Scriptname newscript1 Extends Quest;Sacrier's Blood Script version .1ReferenceAlias Player_Aliasint UnarmedDamage = 0int Health = 0int LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()ObjectReference Player = Player_Alias.GetReference()registerForUpdate(0.1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()  Boost = CurrentActorHealth - LastActorHealth  If LastActorHealth != Game.GetPlayer().GetActorValue(Health)   Game.GetPlayer().ModAV(UnarmedDamage, Boost)  EndIf  CurrentActorHealth = LastActorHealth  LastActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState

Is this all of your code for the script? It doesn't seem to make sense to me.

I see that you delcare:
ReferenceAlias Player_Alias
at the top of the script, but that's just an empty variable at that point in time. However, a few lines down, you attach the reference of this empty variable to Player. This doesn't make sense to me (and when I try it in my code, it gives me errors)
Also, it doesn't look as though you even use the reference, so I'm a bit puzzled.
User avatar
Marie
 
Posts: 3405
Joined: Thu Jun 29, 2006 12:05 am

Post » Sun Jun 17, 2012 1:05 pm

Scriptname SacriersBlood Extends Quest;Sacrier's Blood Script version .1int LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()registerForUpdate(0.1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()    Boost = CurrentActorHealth - LastActorHealth   If LastActorHealth != Game.GetPlayer().GetActorValue("health")    Game.GetPlayer().ModAV("UnarmedDamage", Boost)    Game.GetPlayer().ModAV("MeleeDamage", Boost)   EndIf  CurrentActorHealth = LastActorHealth  LastActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState

This is the cleaned up code. It appears to work 100% in game so far. Will be testing it quite a bit before release, if you get my meaning :D
User avatar
Fiori Pra
 
Posts: 3446
Joined: Thu Mar 15, 2007 12:30 pm

Post » Mon Jun 18, 2012 12:24 am

Scriptname SacriersBlood Extends Quest;Sacrier's Blood Script version .1int LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()registerForUpdate(0.1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()	Boost = CurrentActorHealth - LastActorHealth   If LastActorHealth != Game.GetPlayer().GetActorValue("health")	Game.GetPlayer().ModAV("UnarmedDamage", Boost)	Game.GetPlayer().ModAV("MeleeDamage", Boost)   EndIf  CurrentActorHealth = LastActorHealth  LastActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState

This is the cleaned up code. It appears to work 100% in game so far. Will be testing it quite a bit before release, if you get my meaning :biggrin:
Ah I see, thanks.
User avatar
Nina Mccormick
 
Posts: 3507
Joined: Mon Sep 18, 2006 5:38 pm

Post » Sun Jun 17, 2012 2:51 pm

So this isn't quite as done as I thought it was. It does exactly what it's supposed to, i.e. you deal more damage the more damage difference you take, but if you're at max health you deal no damage, as there is no difference to mod the ActorValues. So Now I need to set up a workaround that incorporates the Max Health and find out how to call for Base Actor Values... Any tips with that would be helpful.


Scriptname SacriersBlood Extends Quest;Sacrier's Blood Script version .1int MaxHealth = Game.GetPlayer().GetActorValue("health")int LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()registerForUpdate(0.1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()  Boost = (CurrentActorHealth - LastActorHealth)   If LastActorHealth == MaxHealth    Game.GetPlayer()GetBaseAV("UnarmedDamage")     ElseIf LastActorHealth != MaxHealth    Game.GetPlayer().ModAV("UnarmedDamage", Boost)    Game.GetPlayer().ModAV("MeleeDamage", Boost)   EndIf  CurrentActorHealth = LastActorHealth  LastActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState

Current (non working) state of the code.
User avatar
..xX Vin Xx..
 
Posts: 3531
Joined: Sun Jun 18, 2006 6:33 pm

Post » Sun Jun 17, 2012 1:02 pm

Alright, looks like I got the code working as intended! I'm fiddling with character creation stuff right now. I can't seem to get heads and faces from another race to copy over to my race, but I'll get it.

Here's the current code:

Scriptname SacriersBlood Extends Quest;Sacrier's Blood Script version .1int MaxHealthint LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()MaxHealth = Game.GetPlayer().GetBaseActorValue("health") as intregisterForUpdate(0.1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()  Boost = ((CurrentActorHealth - LastActorHealth)/2)   If LastActorHealth == MaxHealth    Game.GetPlayer().GetBaseActorValue("UnarmedDamage")    Game.GetPlayer().GetBaseActorValue("MeleeDamage")   ElseIf LastActorHealth <= CurrentActorHealth    Game.GetPlayer().ModAV("UnarmedDamage",(Game.GetPlayer().GetBaseActorValue("UnarmedDamage")+ Boost))    Game.GetPlayer().ModAV("MeleeDamage",(Game.GetPlayer().GetBaseActorValue("MeleeDamage")+ Boost))   ElseIf LastActorHealth >= CurrentActorHealth    Game.GetPlayer().ModAV("UnarmedDamage",(Game.GetPlayer().GetBaseActorValue("UnarmedDamage")- Boost))    Game.GetPlayer().ModAV("MeleeDamage",(Game.GetPlayer().GetBaseActorValue("MeleeDamage")- Boost))   EndIf  CurrentActorHealth = LastActorHealth  LastActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState
User avatar
Naughty not Nice
 
Posts: 3527
Joined: Sat Nov 04, 2006 6:14 am

Post » Mon Jun 18, 2012 2:33 am

Awesome job :D

I've been following this thread too since what I am doing (Dynamically increased walking speeds) depends on using similar methods. I tried my script out last night, it compiled successfully but didn't work. I feel like I am relying too much on states though, which I'm not sure how the script language determines if all states run at the same time or only the "active" state will ever run.

How did you decide to attach the script to the player? Did you do it via a quest or throughh the actual player actor? I'm going to look into the quest method myself, as I've not had luck with the former and also because I imagine it would be a lot more compatable with other mods that way.

And on another note, I'd watch out for registerforUpdate being so low. It can cause a lot of issues with performance and stability of the entire scripting engine to constantly have the script firing 10 times a second, and having script events overlap each other and build up (whcih the wiki warns against, saying to use the function UnregisterForUpdate and RegisterForSingleUpdate to prevent the script from overlapping itself.
User avatar
Mistress trades Melissa
 
Posts: 3464
Joined: Mon Jun 19, 2006 9:28 pm

Post » Sun Jun 17, 2012 9:28 pm

Awesome job :D

I've been following this thread too since what I am doing (Dynamically increased walking speeds) depends on using similar methods. I tried my script out last night, it compiled successfully but didn't work. I feel like I am relying too much on states though, which I'm not sure how the script language determines if all states run at the same time or only the "active" state will ever run.

How did you decide to attach the script to the player? Did you do it via a quest or throughh the actual player actor? I'm going to look into the quest method myself, as I've not had luck with the former and also because I imagine it would be a lot more compatable with other mods that way.

And on another note, I'd watch out for registerforUpdate being so low. It can cause a lot of issues with performance and stability of the entire scripting engine to constantly have the script firing 10 times a second, and having script events overlap each other and build up (whcih the wiki warns against, saying to use the function UnregisterForUpdate and RegisterForSingleUpdate to prevent the script from overlapping itself.

Truthfully I don't fully understand the point of states, as they seem to "lock down" your code. I'm sure they're useful for certain types of scripts but for general ones I don't see a reason to use them. As far as I'm aware only one state can run at a time, and it only runs if you tell it to run. (Though to be honest I'm not too sure...)
User avatar
Blackdrak
 
Posts: 3451
Joined: Thu May 17, 2007 11:40 pm

Post » Sun Jun 17, 2012 10:57 pm

States are basically a nice clean way of doing the sort of thing that would have required you to wrap large blocks of code in conditional statements, and possibly even create "state" variables, in previous games.

They don't exactly let you do anything new, but they let you do some of the same stuff more cleanly if you want to use them.

Cipscis
User avatar
Sxc-Mary
 
Posts: 3536
Joined: Wed Aug 23, 2006 12:53 pm

Post » Mon Jun 18, 2012 12:53 am

So after some testing, the script can be a little unpredictable. Sometimes when you're at full health, the ActorValues won't reset to their base like they should. So you can potentially be running around at full health dealing tons of damage...

Current version of the script, for reference:
Scriptname SacriersBlood Extends Quest;Sacrier's Blood Script version .1int BaseMeleeint BaseUnarmedint MaxHealthint LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()MaxHealth = Game.GetPlayer().GetBaseActorValue("health") as intBaseMelee = Game.GetPlayer().GetBaseActorValue("MeleeDamage") as intBaseUnarmed = Game.GetPlayer().GetBaseActorValue("UnarmedDamage") as intregisterForUpdate(1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()  Boost = ((CurrentActorHealth - LastActorHealth)/2)   If LastActorHealth == MaxHealth    Game.GetPlayer().ModAV("UnarmedDamage", BaseUnarmed)    Game.GetPlayer().ModAV("MeleeDamage", BaseMelee)   ElseIf LastActorHealth <= CurrentActorHealth    Game.GetPlayer().ModAV("UnarmedDamage",(Game.GetPlayer().GetBaseActorValue("UnarmedDamage")+ Boost))    Game.GetPlayer().ModAV("MeleeDamage",(Game.GetPlayer().GetBaseActorValue("MeleeDamage")+ Boost))   ElseIf LastActorHealth >= CurrentActorHealth    Game.GetPlayer().ModAV("UnarmedDamage",(Game.GetPlayer().GetBaseActorValue("UnarmedDamage")+ Boost))    Game.GetPlayer().ModAV("MeleeDamage",(Game.GetPlayer().GetBaseActorValue("MeleeDamage")+ Boost))   EndIf  CurrentActorHealth = LastActorHealth  LastActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState
User avatar
ILy- Forver
 
Posts: 3459
Joined: Sun Feb 04, 2007 3:18 am

Post » Sun Jun 17, 2012 6:06 pm

Fantastic! It works great now. I even tweaked it a little to make sure the damage isn't as crazy.

Here's the current script:

Scriptname SacriersBlood Extends Quest;Sacrier's Blood Script version .1int BaseMeleeint BaseUnarmedint MaxHealthint LastActorHealth = 0int CurrentActorHealth = 0int Boost = 0Event OnInit()MaxHealth = Game.GetPlayer().GetBaseActorValue("health") as intBaseMelee = Game.GetPlayer().GetBaseActorValue("MeleeDamage") as intBaseUnarmed = Game.GetPlayer().GetBaseActorValue("UnarmedDamage") as intregisterForUpdate(1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()  Boost = (LastActorHealth - CurrentActorHealth)/2   If CurrentActorHealth == MaxHealth    Game.GetPlayer().SetAV("UnarmedDamage", BaseUnarmed)    Game.GetPlayer().SetAV("MeleeDamage", BaseMelee)   ElseIf CurrentActorHealth > LastActorHealth    Game.GetPlayer().ModAV("UnarmedDamage",((Game.GetPlayer().GetBaseActorValue("UnarmedDamage")+ Boost)))    Game.GetPlayer().ModAV("MeleeDamage",((Game.GetPlayer().GetBaseActorValue("MeleeDamage")+ Boost)))   ElseIf CurrentActorHealth < LastActorHealth    Game.GetPlayer().ModAV("UnarmedDamage",((Game.GetPlayer().GetBaseActorValue("UnarmedDamage")+ Boost)))    Game.GetPlayer().ModAV("MeleeDamage",((Game.GetPlayer().GetBaseActorValue("MeleeDamage")+ Boost)))   ElseIf CurrentActorHealth == LastActorHealth    Game.GetPlayer().GetAV("UnarmedDamage")    Game.GetPlayer().GetAV("MeleeDamage")   EndIf  LastActorHealth = CurrentActorHealth  CurrentActorHealth = Game.GetPlayer().GetActorValue("health") as intEndEventendState

I only have one issue: My races hands do not show up in first person. I'm sure this is something small I missed, but if anyone has any ideas on how to fix it, please tell me! Thanks a ton for all of your help, and this will be uploaded once I fix the hands issue.
User avatar
Cedric Pearson
 
Posts: 3487
Joined: Fri Sep 28, 2007 9:39 pm

Post » Sun Jun 17, 2012 7:29 pm

All done! Published and ready to roll!

http://steamcommunity.com/sharedfiles/filedetails/?id=9879

Thanks again for all your guys' help! Couldn't have done this without you all.

Future plans: Make Armor, Make Heads, Make Hair, Make Weapons. I need nifscript support for skyrim before that, however...
User avatar
kristy dunn
 
Posts: 3410
Joined: Thu Mar 01, 2007 2:08 am

Post » Mon Jun 18, 2012 4:30 am

So we've almost got it working perfectly, but there's still one issue: When you're regenerating health, the damage boost goes down way too fast. Here's the current script:


Scriptname SacriersBlood Extends Quest;Sacrier's Blood Script version .2int BaseMeleeint BaseUnarmedint Boosterint CurrentHPint MaxHPEvent OnInit()BaseMelee = Game.GetPlayer().GetBaseAV("MeleeDamage") as intBaseUnarmed = Game.GetPlayer().GetBaseAV("UnarmedDamage") as intregisterForUpdate(0.1)gotoState ("Sacrier")endEventState SacrierEvent OnUpdate()  MaxHP = Game.GetPlayer().GetBaseAV("Health") as int  CurrentHP = Game.GetPlayer().GetAV("Health") as int  Booster = (MaxHP - CurrentHP)  Game.GetPlayer().ForceAV("MeleeDamage", BaseMelee + Booster)  Game.GetPlayer().ForceAV("UnarmedDamage", BaseUnarmed + Booster)EndEVENTEndState

Any ideas?
User avatar
Miss Hayley
 
Posts: 3414
Joined: Tue Jun 27, 2006 2:31 am

Post » Sun Jun 17, 2012 4:03 pm

Still looking for any help with this.
User avatar
tannis
 
Posts: 3446
Joined: Sat Dec 09, 2006 11:21 pm

Post » Sun Jun 17, 2012 4:37 pm

Hey all, still no idea why the health gained doesn't match up to damage lost. If anyone has some ideas, please post!
User avatar
lilmissparty
 
Posts: 3469
Joined: Sun Jul 23, 2006 7:51 pm

Post » Sun Jun 17, 2012 10:08 pm

I'd recommend reading the papyrus primer on the wiki and or the excellent papyrus for beginners tutorial a link was posted here.
I think you are making a lot of mistakes because you don't understand the fundamentals of papyrus or the object orientated programing approach.

While people are happy too offer help, I think that covering the basics would help you get more out of their advice and create better more efficient and robust scripts.
User avatar
Scott
 
Posts: 3385
Joined: Fri Nov 30, 2007 2:59 am

Previous

Return to V - Skyrim