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...

New to scripting


vinny1919
 Share

Recommended Posts

hi im new to scripting and im trying to figure out how to write a script so i and use a activator "valve turns and message says water added to barrel." Ive got that figured out but how would i make it so when i went to that specific barrel adn click on it it would tell me that "water has been already added" ?  im guessing that they have to be linked together somehow. i would like some one to give me an example of how to write this as u would in a script. thanks !!:D

Link to comment
Share on other sites

The barrel would have to be an activator with a script attached, or would have to have a player-activated trigger with a script attached to it. That script would have to have a function that the valve activator could call to tell it when water has been added. Here is a sample function from a script on an activator (a fish spawner) that calls a function on another activator (a fish) to pass information.

Function SpawnFishAtRef(ObjectReference arSpawnRef)

    ; Spawns one fish inside the spawner ref. The type of fish
    ; is chosen at random from the FishTypes list. The reference
    ; is cast to the fpiAquariumFish base class.

    Activator FishType = FishTypes.GetAt(RandomInt(0, FishTypes.GetSize() - 1)) as Activator

    ObjectReference FishRef = arSpawnRef.PlaceAtMe(FishType, 1, false, true)
    fpiAquariumFish NewFish = FishRef as fpiAquariumFish

    ; Now we pass information about our properties to the new fish, so
    ; he knows who owns him and where he can go within our volume.

    NewFish.SetInitialSpawnerProperties(Self, fVolMaxZ, fVolMinZ, fVolMaxX, fVolMinX, fVolMaxY, fVolMinY, iCornerCount, fVolCornerX, fVolCornerY)

EndFunction

In your case, your valve would not have to create the barrel like this script creates the fish. It would just need a linked ref to the barrel that it uses. Here is a bit of code used on an activator that talks to an item with a script attached to retrieve a string. It could just as easily pass information. The activator has a linked ref to the item. "Self" in this case is the activator, which would be your valve activator. "fpiGalleryItem" is the name of the script attached to the item, which has a function named "GetGalleryDesc." In your case, the item would be the barrel activator or a trigger attached to the barrel, which would have a script named <whatever> with a function named <something> to receive the message that water has been added.

LookupRef = Self.GetLinkedRef()

if LookupRef
   ItemDesc = (LookupRef as fpiGalleryItem).GetGalleryDesc()
endif

Come to think of it, you wouldn't even necessarily have to call a funtion. If the barrel or trigger has a property such as "HasWater" then the valve script could just set that property to true or false directly. If you want an example of this, perhaps you should read the Papyrus 101 tutorial on properties here.


Edited by BrettM
Link to comment
Share on other sites

I took a little time and whipped up a complete example for you. This setup has an open barrel with a water plane in it and a "magic valve" to fill it. The water is invisible until the barrel is filled by the valve, at which point it fades into view.

 

1. In the Object Window under Miscellaneous-Keyword, define two new keywords that the valve will use to find the barrel and water. I used fpiKYWDBarrel and fpiKYWDBarrelWater for this. All you need to do is give each a unique name. There are no values you need to set or anything.

 

2. Under WorldObjects-Activator, set up three new activators for the barrel, water, and valve. I used fpiBarrel, fpiBarrelWater, and fpiBarrelValve.

 

For the barrel, I used the model BFXOilBarrelOpen01.nif, since it was a handy small, open barrel. I gave it a Name of Water Barrel, and put "Talk to" down in the Activate Override Text. So, when you activate the barrel, the prompt will say "Talk to Water Barrel" instead of "Activate Water Barrel".

 

For the water, I used the circular water plane from the TESA resource kit. I just picked some kind of murky marsh water for the water type.

 

For the magic valve, I just used a glowing doohickey from my FPI Gallery mod. But I could just as easily have used a chair, a chunk of rock, or any other random static item. I put "Magic Valve" in the Name field.

 

3. For fpiBarrel, I clicked Add-[New Script] and entered the following script:

 

Scriptname fpiBarrelScript extends ObjectReference
{FPI Research: Attached to water barrel to show water level.}

; ---------------------------------------------------------------
; Script attached to a barrel activator. IsDry property is set
; by the script on another activator, which fills the barrel
; with water.
; ---------------------------------------------------------------

Bool Property IsDry = TRUE auto
{Indicates empty/full state of barrel}

; ---------------------------------------------------------------

Event OnActivate(ObjectReference akActionRef)

    if IsDry
        Debug.MessageBox("How dry I am!")
    else
        Debug.MessageBox("I'm full of water.")
    endif

EndEvent

; ---------------------------------------------------------------

Function SetIsDry(Bool abIsDry)
    Self.IsDry = abIsDry
EndFunction

 

The function at the end will be called by the script on the Magic Valve to tell the barrel that it has been filled.

 

4. For fpiBarrelValve, I added the following script:

 

Scriptname fpiBarrelFillerScript extends ObjectReference
{FPI Research: Attached to valve that fills a water barrel.}

; ---------------------------------------------------------------
; Script attached to a valve activator that is linked to a water
; barrel and a water plane inside the barrel using keywords.
; When activated, it sets the IsDry property of the barrel to
; FALSE to show that water has been added and enables the water
; to make it visible.
; ---------------------------------------------------------------

; Properties: Define two keyword forms and assign them to these
; properties after adding this script to the valve activator.

Keyword Property fpiBarrel auto
{Identify the linked ref to barrel}

Keyword Property fpiBarrelWater auto
{Identify the linked ref to the water in the barrel}

; Variables to hold our linked references

fpiBarrelScript BarrelRef ; Linked ref to barrel
ObjectReference WaterRef  ; Linked ref to water

; ---------------------------------------------------------------

Event OnActivate(ObjectReference akActionRef)

    ; Get the linked reference to our barrel activator, casting
    ; it to the script attached to the barrel. Get the linked
    ; reference to the water in the barrel, which was set to
    ; initially disabled to keep it invisible.

    ; If we find the barrel then set its property to show that
    ; it has been filled, and make the water visible by
    ; fading it in.

    BarrelRef = Self.GetLinkedRef(fpiBarrel) as fpiBarrelScript
    WaterRef = Self.GetLinkedRef(fpiBarrelWater)

    if BarrelRef
        BarrelRef.SetIsDry(false)

        if WaterRef
            WaterRef.Enable(true)
        endif

        Debug.MessageBox("Water has been added to the barrel.")
    else
        Debug.MessageBox("I don't see any barrel here.")
    endif

EndEvent

 

After the script was compiled and saved, I clicked the Properties button and set the two Keyword properties to the keywords I added in step 1.

 

Edit: Note that the function call "BarrelRef.SetIsDry(false)" is not really necessary unless you want the barrel to do other things when told that it now has water. If you just need to set the property, as I did here, you could use "BarrelRef.IsDry = false" to set the property directly.

 

5. I dragged the new barrel activator into the Render Window to put it in my test cell. Then I dragged in the water, sized it to the barrel, and checked the Initially Disabled box to make it invisible. Finally I dragged in my Magic Valve and went to the Linked Ref tab of the edit window to add references to both the barrel and the water. Each reference was tagged with the appropriate keyword.

 

And that finished it. I had a working valve that would add water to the barrel, making it magically fade into view. I had a barrel that I could talk to that would tell me whether it was empty or full. I could just as easily have set the valve up with a menu to choose whether to fill the barrel or empty it, making the water appear and disappear. Or, I could have added another valve for draining the barrel using the same technique for telling the barrel and water what to do, using the same keywords and linked refs used by the filling valve.

Edited by BrettM
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...