Jump to content

Papyrus - Assistance With Script


SabinXL

Recommended Posts

Looking to get a bit of assistance on the following script I'm looking to create which takes the armor value of one piece of armor and sets it for another. I'm pretty sure I have the code right (it compiles just fine) but I think I'm getting stuck at where I should be placing and executing the script for it to work.

 

Below is the code:

 

Scriptname ArmorApplicationScript extends Armor

Armor Property CraftedArmor Auto
Armor Property OriginalArmor Auto

Event OnInit()

Debug.MessageBox("Script Running!")
CraftedArmor.SetAR(OriginalArmor.GetAR())
Debug.MessageBox("Script Finished!")

EndEvent

 

I need to leverage the SetAR and GetAR functions from SKSE, so I went and extended my script with Armor, as this is what houses the functions I'm looking for... is this correct? I pass off the pieces of armor to CraftedArmor and OriginalArmor just fine with no issues, but I'm at the point where I'm not sure where to put the script - ideally it would be done as soon as the game is loaded.

 

Can anyone give me advice as to whether or not my code is wrong, or where I should be executing the script for it to work?

Link to comment
Share on other sites

The script doesn't necessarily need to extend armor unless you want to put it on an armor form.

Both of your properties are armors, and it is on those Properties that you are calling the SKSE functions.

 

Probably what you need to do is set up a little quest that runs when the game starts ("start game enabled"), and simply run the SetAR function as a fragment on the Start Up stage.

Edited by steve40
Link to comment
Share on other sites

Question for a mallard scripter. One question about attaching scripts to quests and calling their functions vs creating a fragment and calling setstage(). As far as I understand these two example are basically the same in the background.

 

 

creating a quest and adding the code to stage one will create a quest fragment that looks something like this. Then if you want to run the code you just call QuestName.SetStage(0).

Function Fragment_0()
       Debug.MessageBox("Script Running!")
       CraftedArmor.SetAR(OriginalArmor.GetAR())
       Debug.MessageBox("Script Finished!")
EndFunction

 

 

But it seems nearly exactly the same as attaching your own script that extends quest and calling the function from anywhere using.

 

MyQuestScript property MyQuest Auto ;define where the function lives and call it just like set stage

event OnInit()
        MyQuest.GetArmorAR()
;The same as MyQuest.SetStage(0) ?
endevent

;code lives on quest object ready to be called.
function GetArmorAR()
       Debug.MessageBox("Script Running! Getting AR")
       CraftedArmor.SetAR(OriginalArmor.GetAR())
       Debug.MessageBox(self + " CraftedArmor == " + CraftedArmor) ;better debug
endfunction

 

What are the pros and cons of each example?

Link to comment
Share on other sites

Awesome. That was the missing link, Steve - I thought you could only use the functions that were provided by what script you extended with.

 

Went ahead, extended it to Quest and attached it to a quest that ran at the start of the game and it worked like a charm.

Link to comment
Share on other sites

Awesome. That was the missing link, Steve - I thought you could only use the functions that were provided by what script you extended with.

 

Went ahead, extended it to Quest and attached it to a quest that ran at the start of the game and it worked like a charm.

 

I'm not sure offhand but I'd guess that SetAV() might not persist through a save and reload, and your OnInit() won't run again after reloading either since the quest is technically still running. So in order to re-apply the modification when loading a save, you may have to add a Player alias to that quest with an OnPlayerLoadGame() event handler.

Link to comment
Share on other sites

Awesome. That was the missing link, Steve - I thought you could only use the functions that were provided by what script you extended with.

 

Went ahead, extended it to Quest and attached it to a quest that ran at the start of the game and it worked like a charm.

 

I'm not sure offhand but I'd guess that SetAV() might not persist through a save and reload, and your OnInit() won't run again after reloading either since the quest is technically still running. So in order to re-apply the modification when loading a save, you may have to add a Player alias to that quest with an OnPlayerLoadGame() event handler.

 

Hmm.. you're right, I just went and did a bit of testing on it.

 

To be clear, you're talking about creating a reference alias in the quest and then attaching the scripts to that alias, changing OnInit to OnPlayerLoadGame(), yes?

Link to comment
Share on other sites

Awesome. That was the missing link, Steve - I thought you could only use the functions that were provided by what script you extended with.

 

Went ahead, extended it to Quest and attached it to a quest that ran at the start of the game and it worked like a charm.

 

I'm not sure offhand but I'd guess that SetAV() might not persist through a save and reload, and your OnInit() won't run again after reloading either since the quest is technically still running. So in order to re-apply the modification when loading a save, you may have to add a Player alias to that quest with an OnPlayerLoadGame() event handler.

 

Hmm.. you're right, I just went and did a bit of testing on it.

 

To be clear, you're talking about creating a reference alias in the quest and then attaching the scripts to that alias, changing OnInit to OnPlayerLoadGame(), yes?

 

Yes -- or rather, you can just make a separate script which will attach to the player alias, and that script needs to have OnPlayerLoadGame(). Your existing script attached to the quest itself can probably remain with its OnInit() -- that one will fire the very first time the mod is installed and the quest runs (it's start game enabled, right? or triggered by something?), and then the script on the player alias will fire every time the save is reloaded after that (but it won't fire the first time).

Link to comment
Share on other sites

 

Awesome. That was the missing link, Steve - I thought you could only use the functions that were provided by what script you extended with.

 

Went ahead, extended it to Quest and attached it to a quest that ran at the start of the game and it worked like a charm.

 

I'm not sure offhand but I'd guess that SetAV() might not persist through a save and reload, and your OnInit() won't run again after reloading either since the quest is technically still running. So in order to re-apply the modification when loading a save, you may have to add a Player alias to that quest with an OnPlayerLoadGame() event handler.

 

Hmm.. you're right, I just went and did a bit of testing on it.

 

To be clear, you're talking about creating a reference alias in the quest and then attaching the scripts to that alias, changing OnInit to OnPlayerLoadGame(), yes?

 

 

Yes -- or rather, you can just make a separate script which will attach to the player alias, and that script needs to have OnPlayerLoadGame(). Your existing script attached to the quest itself can probably remain with its OnInit() -- that one will fire the very first time the mod is installed and the quest runs (it's start game enabled, right? or triggered by something?), and then the script on the player alias will fire every time the save is reloaded after that (but it won't fire the first time).

 

Yes, I have the quest set to start game enabled. When I make this new script to add to the alias, will I need to change what I extend it to, like ReferenceAlias instead of Quest? Or is Quest good enough?

Link to comment
Share on other sites

Yes, I have the quest set to start game enabled. When I make this new script to add to the alias, will I need to change what I extend it to, like ReferenceAlias instead of Quest? Or is Quest good enough?

 

You will have to change it -- the script you attach to your Quest extends Quest, so likewise the script you attach to your ReferenceAlias will have to extend ReferenceAlias instead.

Link to comment
Share on other sites

@SabinXL: try this:

 

Scriptname _myQuest extends Quest
{this is your Quest script}

Armor Property CraftedArmor Auto
Armor Property OriginalArmor Auto

Event OnInit()
UpdateArmor()
EndEvent

Function UpdateArmor()
CraftedArmor.SetAR(OriginalArmor.GetAR())
EndFunction

 

Scriptname _myPlayerAliasScript extends ReferenceAlias
{attach this script to the player alias)

_myQuest Property QuestScript Auto ; inherits all the functions of the former

Event OnPlayerLoadGame()
	QuestScript.UpdateArmor()
EndEvent

Edited by steve40
Link to comment
Share on other sites

  • Recently Browsing   0 members

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