Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

GetObjectReference or...not? Please help this confused noob.


d81
 Share

Recommended Posts

This is my first post, go easy on me please :)

 

For the past two days I've started learning Papyrus.  I'm not new to scripting or programming concepts, although I am just a humble hobbiest.  I thought I would try something "easy" to acclimate myself to the language.  My goal was to give a certain amount of ingredients to the player when harvesting a plant based on the Alchemy skill and the potency of the ingredient.  Easier said than done!

 

After I finally wrapped my head around the fact that Papyrus is separate from the game data and "Properties" must be attached to objects I was able to write this script to attach to certain Flora forms:

 

Scriptname d81HarvestFloraScript extends ObjectReference
{Contols amount of ingredients harvested based on Alchemy skill.}

FormList Property d81HarvestFloraEasyList Auto
{List containing easy to harvest 'flora' forms}
FormList Property d81HarvestFloraAverageList Auto
{List containing average harvest difficulty 'flora' forms}
FormList Property d81HarvestFloraHardList Auto
{List containing hard to harvest 'flora' forms}

Flora Property FloraForm Auto
{The flora form attached to the this script.}

Message Property d81DebugMsg Auto
Message Property d81HarvestEmptyMsg Auto
{Message for failed harvest.}
Sound Property HarvestSFX Auto
{Still play sound for failed harvest.}

Bool Property IsEasyHarvest Auto
Bool Property IsAverageHarvest Auto
Bool Property IsHardHarvest Auto

Float Property AlchemySkill Auto
{Current Alchemy Actor Value.}

int Property FinalIngred Auto
{Number of ingredient to give to player.}
Ingredient Property GivenIngred Auto
{Ingredient item distributed to player.}


Event OnActivate(ObjectReference akActionRef)

    If akActionRef.IsActivationBlocked()
        Return
    Else
        ; Determine general difficulty of harvest.
        If d81HarvestFloraEasyList.HasForm(FloraForm)
            IsEasyHarvest = true
        ElseIf d81HarvestFloraAverageList.HasForm(FloraForm)
            IsAverageHarvest = true
        ElseIf d81HarvestFloraHardList.HasForm(FloraForm)
            IsHardHarvest = true
        Else
            d81DebugMsg.Show()
        EndIf

        AlchemySkill = Game.GetPlayer().GetActorValue("Alchemy")

        If AlchemySkill < 25
            If IsEasyHarvest == true
                FinalIngred = 1
            ElseIf IsAverageHarvest == true
                FinalIngred = Utility.RandomInt(0, 1)
            ElseIf IsHardHarvest == true
                FinalIngred = 0
            EndIf
        ElseIf AlchemySkill >= 25 && AlchemySkill < 50
            If IsEasyHarvest == true
                FinalIngred = Utility.RandomInt(1, 2)
            ElseIf IsAverageHarvest == true
                FinalIngred = 1
            ElseIf IsHardHarvest == true
                FinalIngred = Utility.RandomInt(0, 1)
            EndIf
        ElseIf AlchemySkill >= 50 && AlchemySkill < 75
            If IsEasyHarvest == true
                FinalIngred = Utility.RandomInt(1, 3)
            ElseIf IsAverageHarvest == true
                FinalIngred = Utility.RandomInt(1, 2)
            ElseIf IsHardHarvest == true
                FinalIngred = Utility.RandomInt(0, 2)
            EndIf
        ElseIf AlchemySkill == 100
            If IsEasyHarvest == true
                FinalIngred = Utility.RandomInt(3, 6)
            ElseIf IsAverageHarvest == true
                FinalIngred = Utility.RandomInt(2, 6)
            ElseIf IsHardHarvest == true
                FinalIngred = Utility.RandomInt(1, 6)
            EndIf
        EndIf

        If FinalIngred > 0
            Game.GetPlayer().AddItem(GivenIngred, FinalIngred)
        ElseIf FinalIngred == 0
            d81HarvestEmptyMsg.Show()
            int instanceID = HarvestSFX.play(akActionRef)
            Sound.SetInstanceVolume(instanceID, 0.7)
        EndIf
    EndIf
EndEvent

 

This is probably not the most eligant solution, but it does work (to my amazement on the first try).  I ran into a problem when I realized a script cannot be attached to Tree forms.  It seems that anything that needs movement data such as swaying, like the mountain flowers, needs to be a Tree.  I can attach scripts to the references in the world but not the base forms.  Naturally this led to dynamically attaching a script to Tree forms in a form list, which works fine using reference aliases in a quest.  The thing is I can't figure out how to differentiate within the script which base object is being activated in order to determine the ingedient given to the player.

 

Do I need to create a script and reference alias for each tree?  How do I get the base object for the tree reference from within the script and then use the single script to determine the distributed ingredient?  Do I have to declare every single ingredient and tree form as properties in the script (which I did and didn't work)?

 

For example this doesn't work:

 

Scriptname d81HarvestTreeScript extends ReferenceAlias

FormList Property d81HarvestTreeEasyList Auto

Form Property TreeRef Auto  ;can't declare "Tree" like "Flora" so use "Form" instead?


Ingredient Property MountainFlower01Blue Auto

 

Message Property d81DebugMsg Auto

 

Event OnActivate(ObjectReference akActionRef)

 

    TreeRef = akActionRef.GetBaseObject()

 

    If d81HarvestTreeEasyList.HasForm(TreeRef)

        Game.GetPlayer().AddItem(MountainFlower01Blue, 1)

    Else

        d81DebugMsg.Show()

    EndIf

EndEvent

 

This compiles but I only ever get the message.  Does GetBaseObject only work on certain objects?  Am I misunderstanding GetBaseObject entirely?  I couldn't find much info on this function.  What is the proper way to write this script?  Am I even on the right track?

 

I think I covered everthing, but probably not :)

Edited by d81
  • Upvote 1
Link to comment
Share on other sites

Welcome to the forums, d18, here's a welcome cookie for you: :cookie4u::pints:

 

 

The issue with the second script is probably this line

TreeRef = akActionRef.GetBaseObject()

ObjectReference akActionRef is the reference that activated the tree, not the tree that was activated. Most likely it's the player, so the condition will never become true.

The function should be called on 'self' and you also need GetReference() to retrieve the reference of the alias.

 

TreeRef = self.GetReference().GetBaseObject()

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...