jeyoon Posted June 19, 2021 Share Posted June 19, 2021 So I was having a tough time creating custom potions with custom ingredients and having to add those ingredients to level lists etc. So I figured out a way to create potions by adding the below script to a custom activator. One example is to create a static of an alchemy table and then put a trigger box over it as the activator and add the script to it. Anyway it took me a while to figure it out, so I thought I would post to save someone time who might be wanting to do something similar. Also, if a someone has an improvement to this script I am always open to learning new things, but it does compile fine and the skill advances with each successful creation of the potion. Ingredient Property (your ingredient) Auto Ingredient Property (your ingredient) Auto Ingredient Property (your ingredient) Auto Ingredient Property (your ingredient) Auto Potion Property (your potion) Auto Event OnActivate(ObjectReference akActionRef)Actor PlayerRef = Game.GetPlayer()if PlayerRef.GetItemCount(your ingredient) >= 1PlayerRef.GetItemCount(your ingredient) >= 1PlayerRef.GetItemCount(your ingredient) >= 1PlayerRef.GetItemCount(your ingredient) >= 1PlayerRef.RemoveItem(your ingredient, 1)PlayerRef.RemoveItem(your ingredient, 1)PlayerRef.RemoveItem(your ingredient, 1)PlayerRef.RemoveItem(your ingredient, 1)Game.GetPlayer().Additem(your potion, 1)PlayerRef.GetItemCount(your potion) >= 1Game.AdvanceSkill("Alchemy", 50.0)Elsedebug.messagebox("You do not have enough ingredients") EndIfEndEvent Note: you will need to add the four ingredients and potion in as properties. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted June 20, 2021 Share Posted June 20, 2021 (edited) You wrote: "someone has an improvement to this script I am always open to learning new things" 1) missing condition for the actor, who is activating the objectyour code Event OnActivate(ObjectReference akActionRef) Actor PlayerRef = Game.GetPlayer() ; no check here EndEventright code Event OnActivate(ObjectReference akActionRef) IF (akActionRef == Game.GetPlayer() as ObjectReference) ; do something ELSE ; do nothing, NOT player activated ENDIF EndEvent2) you wrote: "but it does compile fine and the skill advances with each successful creation" Its not the question of compiling fine. Its a question of nice coding to split code into function(s) for better overview Scriptname xyzPotionMakerSampleScript extends ObjectReference ; https://forums.nexusmods.com/index.php?/topic/10160043-script-work-around-for-making-potions/ Potion PROPERTY myPotion auto ; potion to build with next ingredients Ingredient PROPERTY Ingr01 auto ; your ingredients to make a potion Ingredient PROPERTY Ingr02 auto Ingredient PROPERTY Ingr03 auto Ingredient PROPERTY Ingr04 auto ; -- EVENTs -- This script should be attached to a custom (vanilla duplicated) activator. EVENT OnInit() Debug.Trace(" OnInit() - has been reached for " +self) ENDEVENT EVENT OnActivate(ObjectReference akActionRef) IF (akActionRef = Game.GetPlayer() as ObjectReference) ELSE RETURN ; - STOP - saftey first, maybe this activator is touching through NPC or a floating object ENDIF ;--------------------- myF_Action(akActionRef as Actor) ENDEVENT ; -- FUNCTIONs -- 2 ;-------------------------------- FUNCTION myF_Action(Actor player) ; try to make the potion ;-------------------------------- form[] a = new Form[4] ; create temp array a[0] = Ingr01 a[1] = Ingr02 a[2] = Ingr03 a[3] = Ingr04 int i = a.Length WHILE (i) ; try to find all ingredients i = i - 1 IF (player.GetItemCount( a[i] ) == 0) Debug.MessageBox("You do not have the right ingredients! (" +i+ ")") RETURN ; - STOP - end this function here, not all ingredients are inside players inventory ENDIF ; ---------------------- ENDWHILE i = a.Length WHILE (i) ; remove required ingredients i = i - 1 player.RemoveItem(a[i], 1) ENDWHILE player.AddItem(myPotion, 1) ; give potion myF_HigherSkill() ENDFUNCTION ;------------------------- FUNCTION myF_HigherSkill() ; helper for better overview ;------------------------- ;;; Game.AdvanceSkill("Alchemy", 50.0) float f = Game.GetPlayer().GetActorValue("Alchemy") ; get current alchemy skill IF (f > 99.0) f = 99.0 ; cap the value ENDIF f = (100.0 - f) * 0.85 Game.AdvanceSkill("Alchemy", f)) ; add some points to increase this skill ENDFUNCTION 3) you wrote: "Note: you will need to add the four ingredients and potion in as properties." You have to name the script as unique as possible, because each mod and skyrim + DLCs as well share the same folder for papyrus scripts. And yes, to fill the properties with the CK is mandatory. Thank you for your posting to share experience with others. Edited June 20, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
jeyoon Posted June 29, 2021 Author Share Posted June 29, 2021 Awesome! Thanks so much for this information. I really appreciate that you took the time to help me improve. This is great. I will incorporate into the mod I am using this in. Link to comment Share on other sites More sharing options...
ItsAlways710 Posted July 30 Share Posted July 30 @ReDragon2013 Just saw this thread looking for something else and was reminded how much you helped me when I was just beginning with Papyrus, thank you again. Link to comment Share on other sites More sharing options...
Recommended Posts