Jump to content

Adding perks via potions/spells


Recommended Posts

This is probably a dumb question, but does PlayerRef need to be defined in every script instance? Like, if I attach the same script to five objects, I have to define it in all five?
Why would you need that? The script you attach to the potion extends ActiveMagicEffect, and you use event 'OnEffectStart.

 

Event OnEffectStart(Actor akTarget, Actor akCaster)

 

The only actor to ever make those potions, drink them and get that effect, is the Player. So the akTarget (and akCaster as well) already references the player. You do not need any other methods, just use akTarget.

You also don't really need five separate magic effects. Create a single effect, attach a script that goes like:

 

ScriptName MyPotionEffect extends ActiveMagicEffect

Event OnEffectStart(Actor akTarget, Actor akCaster)
    Float magnitude = Self.GetMagnitude()
    If magnitude == 10.0
        ; do one thing
    ElseIf magnitude == 20.0
        ; do second thing
    ElsleIf magnitude == 30.0
        ; do third thing
    ...
    EndIf
EndEvent

Then, you just attach the same effect to all 5 potions, but with different magnitudes.

 

Another dumb question: when you compile a script, how do you get it to display errors? I did it once by accident, but I don't remember how I did it.

 

I am frankly puzzled that you don't see them. In CK, I use 'Gameplay' menu - PapyrusScriptManager. I can put something in the filter so I can easily find the scripts I need.

 

87kQaxT.jpg

 

If I right-click a script and choose 'Compile', it gets compiled. There is a status popup, and on successful compile, it will just disappear. On a failed compile, the popup stays up:

And if I click on the script name, it gives me the compilation log. Unfortunately, there is no way to make that window bigger, so one has to scroll around. Or one can select everything in the window and copy-paste to notepad for easier viewing

 

la3eVOQ.jpg

 

One can also go Gameplay - Compile Papyrus Scripts, if they have a whole bunch of scripts to compile, and check the ones they want compiled.

 

TCC5Z8l.jpg

 

Then status window will have multiple scripts in it, and one can click on failed ones to see errors.

 

yqY37Pk.jpg

 

Link to comment
Share on other sites

This is probably a dumb question, but does PlayerRef need to be defined in every script instance? Like, if I attach the same script to five objects, I have to define it in all five?
Why would you need that? The script you attach to the potion extends ActiveMagicEffect, and you use event 'OnEffectStart.

 

Event OnEffectStart(Actor akTarget, Actor akCaster)

 

The only actor to ever make those potions, drink them and get that effect, is the Player. So the akTarget (and akCaster as well) already references the player. You do not need any other methods, just use akTarget.

 

Right, but the perks are being added to the player. You know:

 

 

    if !PlayerRef.HasPerk(Alchemist00AlchemyRedone)
   PlayerRef.AddPerk(Alchemist00AlchemyRedone) 

So, I'd still need it, right? Or could I just change PlayerRef to akTarget?

 

You also don't really need five separate magic effects. Create a single effect, attach a script that goes like:

I'm not using five separate effects - it's the same script attached to five different potions. They all different perks, but that's covered in the skill check.

 

 

If I right-click a script and choose 'Compile', it gets compiled. There is a status popup, and on successful compile, it will just disappear. On a failed compile, the popup stays up:

And if I click on the script name, it gives me the compilation log.

That's the part I wanted. I didn't know you had to click on the script name.

 

 

Anyway, I was checking out some other portable crafting mods and I got a working tool script:

 

 

Scriptname AlchemyRedonePortable extends ObjectReference
 
ObjectReference Property ToolReference Auto
ObjectReference Property CraftingStationReference Auto
 
Actor Property PlayerREF Auto
 
 
Event OnEquipped(Actor akActor)
 
akActor.EquipItem( ToolReference, True, True )
Utility.Wait(0.1)
akActor.UnequipItem( ToolReference, False, True )
CraftingStationReference.Activate(PlayerRef, true)
 
EndEvent
Link to comment
Share on other sites

Yes. you just use akTarget instead of PlayerRef.

 

Like this:

Scriptname AlchemyRedonePortable extends ObjectReference
 
ObjectReference Property ToolReference Auto
ObjectReference Property CraftingStationReference Auto
 
Event OnEquipped(Actor akActor)
    akActor.EquipItem( ToolReference, True, True )
    Utility.Wait(0.1)
    akActor.UnequipItem( ToolReference, False, True )
    CraftingStationReference.Activate(akActor, true)
EndEvent
Link to comment
Share on other sites

Argh. I'm not sure if I wrote the script incorrectly, or if I did something else wrong, but I still can't get the perks. The message doesn't show up, and when I check via the console, it says I don't have the perk. I tried swapping akTarget with PlayerRef, just for kicks, but that didn't work either... it's likely something else, but I'n not sure what.

Edit:
I'm an idiot. I mentioned before that I was working on a revision of an existing mod, but after learning how the scripts worked, it never occurred to me to go back to the original and see how *that one* worked. It's a very simple script:
Scriptname AlchemyRedoneAddPerkNote extends ObjectReference  
 
Perk property PerkToAdd auto
 
Event OnRead()
Game.GetPlayer().AddPerk(PerkToAdd)
EndEvent
PerkToAdd is filled in for each note with the specific perk to be added. I made some tweaks, attached it to my books, filled in the proper value and - voila! - it worked. I tried making a version for the potions, but sadly, it appears that it's not possible to add perks via magic effect (believe me, I tried), so I'll just have to make books for all the perks.
Anyway, I never would have learned all this if without all your help, so.... thank you.
Edited by WalkerInShadows
Link to comment
Share on other sites

I tried making a version for the potions, but sadly, it appears that it's not possible to add perks via magic effect (believe me, I tried)

 

I have this utility mod where I have defined a few magic effects with attached scripts, mainly for diagnostics (animation catcher, nioverride scanner, position adjuster via json, etc)

 

So, I just defined a Magic Effect of 'Fire and Forget' casting type, Script Archetype. I defined a potion, and attached this effect to it.

 

To the effect, I attached a script:

ScriptName PerkPotionEffect Extends ActiveMagicEffect

Perk Property Armsman00 Auto

Event OnEffectStart(Actor akTarget, Actor akCaster) 
    If !akTarget.hasPerk(Armsman00)
        akTarget.addPerk(Armsman00)
    Endif
EndEvent
I compiled the script, and made sure to fill the script property with 'Armsman00' perk (000BABE4)
Started new test game ('coc qasmoke' in main menu)
Used player.additem command to give myself that potion.
Checked my skills to make sure I got no perks.
Used the potion.
Checked skills again - my One-Handed now had 'Armsman (1/5)'
Link to comment
Share on other sites

  • 3 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...