Lose % of a stat

Post » Tue Jun 19, 2012 4:43 pm

I'd like to create an item that, when worn, a players stat is automatically minused a percentage amount. Is this possible? I couldn't find any Ench/Alch effects that do this. Though similar to poison except, not over time. I'd like it to be an instant loss. 50% - or 25% and of a stat I can change.
User avatar
Samantha Pattison
 
Posts: 3407
Joined: Sat Oct 28, 2006 8:19 pm

Post » Wed Jun 20, 2012 4:47 am

This can be done through math in a script. It consists of subtracting the actor values and multiplying them by a percentage.

Try using either .GetBaseAV() or .GetAV() (this accounts for buffs and debuffs)

An example for getting a percentage though damageAV

float property percentage auto;I used 0.2 (20%)akTarget.damageAV("health", (akTarget.GetAV("health") - (akTarget.GetAV("health") * percentage))

It just an example on how to go about using math this way.
User avatar
Ray
 
Posts: 3472
Joined: Tue Aug 07, 2007 10:17 am

Post » Wed Jun 20, 2012 3:41 am

"Better" math:
akTarget.damageAV("health", (akTarget.GetAV("health") * (1.0 - percentage))
User avatar
jessica sonny
 
Posts: 3531
Joined: Thu Nov 02, 2006 6:27 pm

Post » Tue Jun 19, 2012 9:50 pm

Thanks for chiming in guy - much appreciated.

So this something I can make a script out of and add to an item? [sorry I'm not very knowledgeable in scripting - or math for that matter]

Looking at the Ring of Namira as an example [since that's the only one I know of off hand]

ScriptName DA11RingofNamiraScript extends ObjectReferencePerk Property DA11Cannibalism  Auto  Event OnEquipped(Actor akActor)If akActor == Game.GetPlayer()Game.GetPlayer().AddPerk(DA11Cannibalism )EndIfEndEventEvent OnUnequipped(Actor akActor)If akActor == Game.GetPlayer()Game.GetPlayer().RemovePerk(DA11Cannibalism )EndIfEndEvent


It has the OnEquipped / Unequipped function so the percentage would only apply if the item is worn and subsequently removed if the item is taken off. It uses a Perk though - should I first set this up as a perk or just write it all into a script?
User avatar
Daniel Brown
 
Posts: 3463
Joined: Fri May 04, 2007 11:21 am

Post » Tue Jun 19, 2012 4:01 pm

There's different ways to do this but doing it like the Ring of Namira will work too.

You need to add a new script to the item you have created, something like this:
ScriptName YourScript extends ObjectReferenceEvent OnEquipped(Actor akActor)  If akActor == Game.GetPlayer()    akActor.damageAV("health", (akActor.GetAV("health") * (1.0 - 0.2))  EndIfEndEventEvent OnUnequipped(Actor akActor)  If akActor == Game.GetPlayer()    akActor.damageAV("health", (akActor.GetAV("health") * (1.0 + 0.2))  EndIfEndEvent

To be honest a much better approach in my opinion would be to enchant your item. Make a new magic effect that lowers health, then a new enchantment using the magic effect you just created.
Look on http://www.creationkit.com/Enchantment & http://www.creationkit.com/Magic_Effect for more information.
User avatar
JaNnatul Naimah
 
Posts: 3455
Joined: Fri Jun 23, 2006 8:33 am

Post » Wed Jun 20, 2012 5:20 am

Thanks for the help dudster.

I got the script working but I think the function is off. It takes a percentage of health away when you put it on and take it off - it doesn't reduce the players total health by a percentage. Sorry if I didn't explain it right. When the player wears the item, their total health is reduced by a percentage while wearing it. Say 50% for this. If I have 100max health and I put on this item, my max health is now 50. When I take the item off, My max health is back to 100.

Originally I just added an AbDamageHealth with a fixed magnitude but I want the effect to scale - hence, using percentage of total health rather than a fixed value.
User avatar
Setal Vara
 
Posts: 3390
Joined: Thu Nov 16, 2006 1:24 pm

Post » Wed Jun 20, 2012 6:38 am

Do you want it to take for instance 50% off everytime you put it on but never "give back" the health? Eg, the health would go to 50, then 25 next time you equip it, then 12.5 after that?
If so you would just remove the whole OnUnEquipped event.
User avatar
Liii BLATES
 
Posts: 3423
Joined: Tue Aug 22, 2006 10:41 am

Post » Tue Jun 19, 2012 4:05 pm

Definitely get it back OnUnequipped.

Here's what I've been playing with but it's not quite working out - I'm actually swapping 50% health into Magicka - so whatever the total is for the 50% of the health, the players magicka is raised by that amount.

Scriptname blahblahSCR extends ObjectReferenceEvent OnEquipped(Actor akActor)If akActor == Game.GetPlayer()  akActor.ForceAV("health", (akActor.GetBaseActorValue("health") * (1.0 - 0.5) ))  akActor.ForceAV("magicka", (akActor.GetBaseActorValue("health") * (1.0 + 0.5) ))EndIfEndEventEvent OnUnequipped(Actor akActor)If akActor == Game.GetPlayer()  akActor.ForceAV("health", (akActor.GetBaseActorValue("health") * (1.0) ))  akActor.ForceAV("magicka", (akActor.GetBaseActorValue("health") * (1.0) ))EndIfEndEvent

I'm trying to get it to get the value it took away from the health [the 50% from the base 100%] and convert that number over to magicka. As an example - If I have 100 Health and 200 Magicka - I lose 50% health = 50points and my magicka is raised by 50points. OnUnequipped - I get back my 50% health [50points] and lose that value from the Magicka.

The code above is janky - I'm not getting the % from health into the magicka, I'm manually saying take 50% and that's not right.
User avatar
Jade Barnes-Mackey
 
Posts: 3418
Joined: Thu Jul 13, 2006 7:29 am

Post » Wed Jun 20, 2012 5:57 am

you're multiplying by 1.0 in the OnUnEquiped event - that just sets the value to what it is already at.

Better is * 1 / (1.0 - 0.5) which would multiply by 2, reversing the 50%

Better yet would be to set quest to go with the item and record the number removed so you can add it back. Otherwise you're calculations get affected by other modifications to the same stat

[edit]

... or use a property on the script, I suppose. that would be simpler.
User avatar
KRistina Karlsson
 
Posts: 3383
Joined: Tue Jun 20, 2006 9:22 pm

Post » Tue Jun 19, 2012 8:50 pm

The OnUnequipped works for now - it sets the value back to what it was. What I'd like to be able to do is get the point value that was removed from the health and add it to the magicka. I'm struggling with that part the most.
User avatar
Josephine Gowing
 
Posts: 3545
Joined: Fri Jun 30, 2006 12:41 pm

Post » Tue Jun 19, 2012 9:33 pm

How about:

Scriptname blahblahSCR extends ObjectReferenceint loss = 0float percent = .2    ; percent to loseEvent OnEquipped(Actor akActor)    If akActor != Game.GetPlayer()        return    EndIf        int health = akActor.GetBaseActorValue("health")    loss = health * (1.0 - percent)    akActor.ForceAV("health", -loss)    akActor.ForceAV("magicka", loss)EndEventEvent OnUnequipped(Actor akActor)    If akActor != Game.GetPlayer()        return    EndIf    akActor.ForceAV("health", loss)    akActor.ForceAV("magicka", -loss)EndEvent
User avatar
Unstoppable Judge
 
Posts: 3337
Joined: Sat Jul 29, 2006 11:22 pm

Post » Tue Jun 19, 2012 5:59 pm

Make a magic effect for health, and in the spell, assign it a negative value (Say, -5HP) Then attach a script to your item that casts that on the player enough times to reduce his health to the percentage you want, and have a script in the effect that removes it when the item is taken off.

Magic effects can remove stat points, but there is no way I know of to set the magnitude based on the players' max health.
User avatar
Chloe Yarnall
 
Posts: 3461
Joined: Sun Oct 08, 2006 3:26 am

Post » Tue Jun 19, 2012 11:27 pm

How about:
Scriptname blahblahSCR extends ObjectReference int loss = 0 float percent = .2 ; percent to lose Event OnEquipped(Actor akActor) If akActor != Game.GetPlayer() return EndIf int health = akActor.GetBaseActorValue("health") loss = health * (1.0 - percent) akActor.ForceAV("health", -loss) akActor.ForceAV("magicka", loss) EndEvent Event OnUnequipped(Actor akActor) If akActor != Game.GetPlayer() return EndIf akActor.ForceAV("health", loss) akActor.ForceAV("magicka", -loss) EndEvent

Thanks for taking the time to write that out. Unfortunately it wont compile and I'm not skilled enough in papyrus to understand why.
User avatar
D IV
 
Posts: 3406
Joined: Fri Nov 24, 2006 1:32 am

Post » Tue Jun 19, 2012 5:01 pm

Thanks for taking the time to write that out. Unfortunately it wont compile and I'm not skilled enough in papyrus to understand why.

Well the first thing I notice is, you can't assign a float value to .2 - you have to use 0.2
User avatar
Eddie Howe
 
Posts: 3448
Joined: Sat Jun 30, 2007 6:06 am

Post » Tue Jun 19, 2012 6:06 pm

I tried 0.2. Still wouldnt compile.
User avatar
X(S.a.R.a.H)X
 
Posts: 3413
Joined: Tue Feb 20, 2007 2:38 pm

Post » Tue Jun 19, 2012 11:55 pm

this is what I get after i deal with the float and change that to 0.2.


blahblahSCR.psc(11,8): type mismatch while assigning to a int (cast missing or types unrelated)
blahblahSCR.psc(12,4): type mismatch while assigning to a int (cast missing or types unrelated)

11 is int health = akActor.GetBaseActorValue("health")
12 is loss = health * (1.0 - percent)
User avatar
Elina
 
Posts: 3411
Joined: Wed Jun 21, 2006 10:09 pm

Post » Wed Jun 20, 2012 3:19 am

try making 'int health' 'float health'
User avatar
Facebook me
 
Posts: 3442
Joined: Wed Nov 08, 2006 8:05 am

Post » Wed Jun 20, 2012 5:19 am

Not sure if this will fix it but you can try ModAV instead, also I would include a variable to remember how much health gets taken when the object is equipped (I put in Int healthMod) so you can give back the same amount when it gets unequipped
Scriptname blahblahSCR extends ObjectReferenceFloat healthModEvent OnEquipped(Actor akActor)	If akActor == Game.GetPlayer()		healthMod = akActor.GetBaseActorValue("health") * 0.5				akActor.ModAv("health", -healthMod)		akActor.ModAv("magicka", healthMod)	EndIfEndEventEvent OnUnequipped(Actor akActor)	If akActor == Game.GetPlayer()		akActor.ModAv("health", healthMod)		akActor.ModAv("magicka", -healthMod)	EndIfEndEvent

I'm manually saying take 50% and that's not right.
What do you mean by this?

Edit: messed up the signs for the adding and removing stats
User avatar
CSar L
 
Posts: 3404
Joined: Fri Nov 09, 2007 9:36 pm

Post » Wed Jun 20, 2012 6:03 am

Thanks Xtynct. It compiled with the following:

Scriptname blahblahSCR extends ObjectReference float loss = 0.0float percent = 0.2    ; percent to loseEvent OnEquipped(Actor akActor)    If akActor != Game.GetPlayer()	    return    EndIf   float health = akActor.GetBaseActorValue("health") as int    loss = health * (1.0 - percent)    akActor.ForceAV("health", -loss)    akActor.ForceAV("magicka", loss)EndEventEvent OnUnequipped(Actor akActor)    If akActor != Game.GetPlayer()	    return    EndIf    akActor.ForceAV("health", loss)    akActor.ForceAV("magicka", -loss)EndEvent

But when I test and put the item on it just kills me instantly.
User avatar
Brad Johnson
 
Posts: 3361
Joined: Thu May 24, 2007 7:19 pm

Post » Wed Jun 20, 2012 7:30 am

lol.

You dont need 'as int' if its a float

loss = health * (1.0 - percent)
That would make loss = to 80% of your health

akActor.ForceAV("health", -loss)
That would set your health to -80% of your health (80% UNDER dead, which is why you die instantly)
User avatar
Catharine Krupinski
 
Posts: 3377
Joined: Sun Aug 12, 2007 3:39 pm

Post » Tue Jun 19, 2012 5:25 pm

Brilliant Xtynct! Your's worked! I only had to swap the - from healthmod in akActor.ModAv("magicka", healthMod) for on and un equip to send the same amount it removed from health and put it into magicka and then remove it from magicka after unequipping.
User avatar
Cartoon
 
Posts: 3350
Joined: Mon Jun 25, 2007 4:31 pm

Post » Tue Jun 19, 2012 10:08 pm

lol.

You dont need 'as int' if its a float


That would make loss = to 80% of your health


That would set your health to -80% of your health (80% UNDER dead)

Ah - UNDER dead... nice (:
User avatar
Angela
 
Posts: 3492
Joined: Mon Mar 05, 2007 8:33 am

Post » Wed Jun 20, 2012 4:13 am

Hehe
User avatar
sally coker
 
Posts: 3349
Joined: Wed Jul 26, 2006 7:51 pm

Post » Tue Jun 19, 2012 11:28 pm

Also yours saves modded health values as well which is a real bonus. In my earlier testing I was at 164 buffed health and when I removed the item, I was down to 151 unbuffed health. Great way to unbuff yourself but not very practical.
User avatar
X(S.a.R.a.H)X
 
Posts: 3413
Joined: Tue Feb 20, 2007 2:38 pm

Post » Wed Jun 20, 2012 7:55 am

Ah - UNDER dead... nice (:

Hey, there's no kill like overkill.
User avatar
Flesh Tunnel
 
Posts: 3409
Joined: Mon Sep 18, 2006 7:43 pm

Next

Return to V - Skyrim