Jump to content

object activate script


Recommended Posts

I'm trying to make an object spawn another which activates it's own script by itself

Scriptname obj1 extends ObjectReference Const

Explosion Property obj1 Auto Const Mandatory

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	If (!akNewContainer)
		
		Game.GetPlayer().PlaceAtMe(obj1 as form, 1, false, false, false)
		self.Disable()
		self.Delete()

	EndIf
EndEvent

would be the code to spawn the 1st object.

 

what would i put to make object placed at me to spawn a different item?

Edited by xBloodTigerx
Link to comment
Share on other sites

If you wan to do this with a script attach the following script the object you placed with the script you posted above:

 

Scriptname Obj2 Extends ObjectReference
 
;Add a property for Obj2 here
 
Event OnInit()
  Self.PlaceAtMe(Obj2 As Form) ; change the other parameters as needed.
EndEvent
But as obj1 appears to be an explosion they have the ability to place an item themselves in the creation kit. Open the explosion in the CK and look for where it says Placed object. And select what you want to place at your explosion in the dropdown menu.
Link to comment
Share on other sites

Biiiiig IIRC:

 

Bool only once ;placed under the properties

 

Only once = true ;before the end of the script

 

Or something like that, I may not be recalling correctly.

 

This may work:

disable.self

...or was it self.disable

...but that would disable the beginning object entirely after its run, so not sure if that's suitable or not.

Edited by BlahBlahDEEBlahBlah
Link to comment
Share on other sites

btw if i put that in itself, the object infinitly trigger the script. any way to trigger it once/two times using oninit?

This depends on what you mean by just once. If you mean once per explosion(obj1) the scipt I posted earlier will only trigger once. If you mean once across multiple separate explosions (multiple different obj1's) then yes it will keep creating Obj2's.

 

Basicaly every time a new obj1 is placed the script will trigger.

 

If you only want it to trigger once no matter how many times an obj1 is created use the following:

Scriptname Obj2Once Extends ObjcetReference

;Add a property for Obj2 here
GlobalVariable Property Obj2Created Auto ;create a globalvariable in the CK set its value to 0 and name it something unique so there won't be any conflicts with other mods and then make a property for it and replace the Obj2Created with the name of the globalvariable you made in this script.

Event OnInit()
   If(Obj2Created.GetValue() == 0)  ;If you want it to trigger multiple times you change this to <= x where x is the amount of times you want it to trigger.
      Self.PlaceAtMe(Obj2 As Form) ;Change the other parameters as needed.
      Obj2Created.SetValue(1)  ;If you want it to trigger multiple times use the following instead: Obj2Created.GetValue(Obj2Created.GetValue() + 1)
   EndIf
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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