Jump to content

Help with container changed please.


Recommended Posts

Two ways to do that:

One method would be my earlier example of moving the script to the player and listening for when they pick up the object the first time.

 

The other method would be to add a global variable property with a comparison check to the script that goes on the object. By using a global variable and changing the value you can cause future instances of the object to skip processing even if the script is on the base object.

 

Since the one already has an example posted earlier, I'll just add an example of the second one. Adapting maxarturo's example:

 

 

Sound Property MySoundFX  Auto
{Sound FX to play when this item is picked up}
 
Message PROPERTY MyMessage auto
{Message to show when this item is picked up}
 
bool property DoOnce = false auto
{Checked this -TRUE - to fire only once then goes to a state that does nothing, default FALSE}

GlobalVariable Property MyGV Auto
{Create a global variable record with a value of 0 and assign it here}
 
int instanceID ;used to store sound ref
 
auto state waiting
  Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)
    if (newContainer == Game.GetPlayer()) && MyGV.GetValue() == 0.0
      ;check that the player is the new container AND that the global variable value is unchanged.

      MyGV.SetValue(1.0) 
      ;change value so that the condition statement will fail going forward even on new instances

      instanceIDA =  MySoundFX. Play(Game.GetPlayer())
      Utility.wait(2.0)             
      MyMessage.Show()
    endif
    if ( DoOnce )
      DoOnce = TRUE
      GoToState("Done")
    endif
  EndEvent
endstate

 

 

FYI - I should have thought of adding the global variable the first time around. Oh well, we all have our off days.

Link to comment
Share on other sites

As IsharaMeradin already said, posted before i could.



By "locally" i mean into the object's Reference menu (in the script tab - add script - make NEW Script) to the object selected in the Render window (add the script to only ONE object). That means "Do NOT edit Base".

Here is a simpliest version of the same script that will fire only ONCE uppon picking up the object then will go to a state that will do nothing :



Sound Property MySoundFX Auto
{Sound FX to play when this item is picked up}

Message PROPERTY MyMessage auto
{Message to show when this item is picked up}

int instanceID ;used to store sound ref


auto state waiting
Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)
if (newContainer == Game.GetPlayer())
instanceID = MySoundFX. Play(Game.GetPlayer())
Utility.wait(2.0)
MyMessage.Show()
GoToState("Done")
endif
EndEvent
endstate




"so wherever an instance of it is found in the world, player gets the message and knows what to do with it ONCE."


If you want the message to appear every time the player finds and picks up the item, then (assuming you have made your own object and you are not using a default vanilla object) edit BASE and place the script there, now it will fire every time you find the particular object



Link to comment
Share on other sites

Thank you both for your help. Got it working now. Believe it or not I used to know all of this 4-5 years ago. I can compare it to taking night classes to learn German - I spoke decent basic German but after a while of not having anybody to speak German with - I forgot 90%+ of it. it is coming back to me as I see more scripts.

@IsharaMeradin In two of the scripts you wrote for me you have a typo error on the same line...

 

instanceIDA = MySoundFX. Play(Game.GetPlayer())

 

 

Not to worry, it was pointed out to me.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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