Adding Disease Chance to Potions?

Post » Thu May 30, 2013 12:34 pm

I've spent pretty much all day trying to figure this one out; I'm pretty new to modding in general, and I'm not terribly good at coding or scripting, so it's been tough trying to find the answer on my own. I tried searching through the wiki, and even this forum, but I didn't get anything useful.

Basically, all I want to do is apply a low chance of contracting a specific disease from a specific potion. There's no way to set that without scripting, from what I saw.

If anyone could walk me through the code required, or even just point me in the direction of a relevent tutorial for Papyrus, that would be spectacular.

User avatar
Samantha Pattison
 
Posts: 3407
Joined: Sat Oct 28, 2006 8:19 pm

Post » Thu May 30, 2013 11:59 pm

hmm there's probably a way to do it without scripts, but probably best to do it with scripts for compatibility reasons and blah blah blah
just take this and stick it onto the player with a magic effect or a reference alias
http://www.creationkit.com/Dynamically_Attaching_Scripts

and of course replace the disease1 things with actual diseases, that would help too. lol

EVENT OnObjectEquipped(Form akBaseObject, ObjectReference akReference)  IF akBaseObject.HasKeyword(VendorItemPotion)    randomInteger = Utility.RandomInt()    IF randomInteger < 25      PlayerRef.AddSpell(Disease1)    ELSEIF randomInteger < 50      PlayerRef.AddSpell(Disease2)    ELSEIF randomInteger < 75      PlayerRef.AddSpell(Disease3)    ELSE      PlayerRef.AddSpell(Disease4)    ENDIF  ENDIFENDEVENTint randomIntegerKEYWORD PROPERTY VendorItemPotion AUTOACTOR PROPERTY PlayerRef AUTOSPELL PROPERTY Disease1 AUTOSPELL PROPERTY Disease2 AUTOSPELL PROPERTY Disease3 AUTOSPELL PROPERTY Disease4 AUTO
User avatar
Sharra Llenos
 
Posts: 3399
Joined: Wed Jan 17, 2007 1:09 pm

Post » Thu May 30, 2013 1:22 pm

So you need to add a script onto your MagicEffect for your potion. When you go to add a new script, you'll see a new window appear. The first line you have to enter is your scriptname. Name it whatever you want, but it's good practice to prefix your script with something (a unique few letters representing your name, mod name, etc) for compatibility with other mods.

Then you'll see by default that the script extends "ActiveMagicEffect." Leave this as it is. If you go to the Creation Kit wiki page for ActiveMagicEffect, you'll see all the functions you can call on this type of object, but most importantly for you is the Events. Events are special functions which are triggered by something, and they can also give you a few variables to use relating to whatever happened. For you, it would be easiest to use OnEffectStart, which is triggered as soon as the Magic Effect is applied. http://www.creationk...veMagicEffect.?/a> Here they give you variables pointing to both the target and the caster (akTarget/akCaster) of the effect so you can manipulate them however you want.

The next thing that is important for scripting is properties. These point to an object in the game (Spell, Message, etc) or hold a value (float, int, bool, string). You fill these out by right-clicking your script and selecting edit properties.

So to actually make your script, fill out the name for your script in the new script window and hit OK. Right click your script and select edit script. Something like this below should work for you. I added comments to explain what is going on in the script.

Scriptname _test_testscript extends ActiveMagicEffect ;your sciprt name goes in place of _test_testscriptSPELL Property MyDisease Auto ;fill these property out in the MagicEffect windowMessage Property MyMessage AutoFloat Property fChance Auto ;fill this property with the disease chance (ex: 15% = 15.0);This event is triggered when the magic effect is applied, the akTarget variable points to the target of the magic effect.;Likewise akCaster is the caster of the magic effect. akCaster and akTarget can be the same actor for self targeted effectsEvent OnEffectStart(Actor akTarget, Actor akCaster)    if Utility.RandomFloat(0.0, 100.0) <= fChance ;compare the randomly generated number to the disease chance        akTarget.AddSpell(MyDisease, false) ;Condition is met.  Adding the disease to the target.  The false parameter suppresses the default message "Disease added."        MyMessage.Show() ;"You have contracted MyDisease" make sure your message is not a messagebox    endIfendEvent

Also, if you want the player's disease risk to factor in, you have to take a few additional steps as the AddSpell function doesn't check that.

Scriptname _test_testscript extends ActiveMagicEffectSPELL Property MyDisease AutoMessage Property MyMessage AutoFloat Property fChance Auto Event OnEffectStart(Actor akTarget, Actor akCaster)    float fResist = akTarget.GetAV("DiseaseResist")    if fResist >= 100.0        return ;immediately ends the function because the target is immune to disease    endIf    if Utility.RandomFloat(0.0, 100.0) <= fChance*(100.0-fResist)*0.01 ;compare the randomly generated number to the disease chance        akTarget.AddSpell(MyDisease, false)         MyMessage.Show()    endIfendEvent
User avatar
Rob Davidson
 
Posts: 3422
Joined: Thu Aug 02, 2007 2:52 am


Return to V - Skyrim