Jump to content

How to make a script to spawn an actor upon opening a chest?


Recommended Posts

I can't seem to get this to work, here's what I got:

 

Scriptname placeholder extends ObjectReference

 

Actor Property Actor1 Auto

 

Auto State DoOnceState

 

Event OnActivate(ObjectReference akActionRef)

if (akActionRef == Game.GetPlayer())

if Game.GetPlayer().GetLevel() >= 30

Int Num = Utility.RandomInt(0, 1)

If Num == 1

GoToState ("DoNothingState")

Int Num2 = Utility.RandomInt(0, 1)

If Num2 == 1

Game.GetPlayer().PlaceAtMe(Actor1)

GoToState ("DoNothingState")

 

endIf

endIf

endIf

endIf

endEvent

 

EndState

 

State DoNothingState

EndState

Link to comment
Share on other sites

I just went and took a look at it in the Skyrim SE creation kit. It looks like they have the 3 npcs linked to an x-marker as enable parent. The X marker has and L shaped marker (Trap Linker) next to it, and has a Link Ref to the Trap linker but no scripts of its own. The Trap Linker has a Linked Ref to the X marker, and also an Activate Parent from the treasure chest itself. It has two scripts. One is a Trap Trigger Base (inherited from parent) which seems to list different variables and things like the light foot perk, light hands perk, owning actor, owning faction, etc. The other is DefaultActivateToggleLinkedRefOnce (added locally) and none of its properties seem to have been modded.

 

I don't know if any of this is helpful or not, but maybe.

Link to comment
Share on other sites

Assuming this a a Fallout4 script;

 

(1) you cant spawn an actor, only an ActorBase and that should use PlaceActorAtMe.

 

(2) You also have an Else missing so true will never trigger. Rather than multiple functions, work your the probability you want and run a single call;

 

(3) Game.GetPlayer() is a slow function call, if using multiple times assign a variable

 

(4) Debug.Trace *every step* so you can see where stuff is going wrong. Use console command [reloadscript placeholderscript] to update in the same game session.

Scriptname placeholderscript extends ObjectReference

ActorBase Property lvlRaider Auto Const Mandatory

Auto State DoOnceState
Event OnActivate(ObjectReference akActionRef)

Debug.Trace("placeholderscript.OnActivate " + Self)
Actor PlayerREF = Game.GetPlayer()

If (akActionRef == PlayerREF) && (PlayerREF.GetLevel() >= 30)
   Debug.Trace("placeholderscript.OnActivate " + Self + " player conditions met")
   If (Utility.RandomInt(0, 100) >= 75)
      Actor ThisActor = PlayerREF.PlaceActorAtMe(lvlRaider, aiLevelMod = 4, akZone = None)
      Debug.Trace("placeholderscript.OnActivate " + Self + " spawned " + ThisActor )
   Else
      Debug.Trace("placeholderscript.OnActivate " + Self + " no spawn")
   EndIf
   GoToState ("DoNothingState")
Else
   Debug.Trace("placeholderscript.OnActivate " + Self + " player conditions not met")
EndIf

EndEvent
EndState

State DoNothingState
   ;intentional blank
EndState
Link to comment
Share on other sites

 

Assuming this a a Fallout4 script;

 

(1) you cant spawn an actor, only an ActorBase and that should use PlaceActorAtMe.

 

(2) You also have an Else missing so true will never trigger. Rather than multiple functions, work your the probability you want and run a single call;

 

(3) Game.GetPlayer() is a slow function call, if using multiple times assign a variable

 

(4) Debug.Trace *every step* so you can see where stuff is going wrong. Use console command [reloadscript placeholderscript] to update in the same game session.

Scriptname placeholderscript extends ObjectReference

ActorBase Property lvlRaider Auto Const Mandatory

Auto State DoOnceState
Event OnActivate(ObjectReference akActionRef)

Debug.Trace("placeholderscript.OnActivate " + Self)
Actor PlayerREF = Game.GetPlayer()

If (akActionRef == PlayerREF) && (PlayerREF.GetLevel() >= 30)
   Debug.Trace("placeholderscript.OnActivate " + Self + " player conditions met")
   If (Utility.RandomInt(0, 100) >= 75)
      Actor ThisActor = PlayerREF.PlaceActorAtMe(lvlRaider, aiLevelMod = 4, akZone = None)
      Debug.Trace("placeholderscript.OnActivate " + Self + " spawned " + ThisActor )
   Else
      Debug.Trace("placeholderscript.OnActivate " + Self + " no spawn")
   EndIf
   GoToState ("DoNothingState")
Else
   Debug.Trace("placeholderscript.OnActivate " + Self + " player conditions not met")
EndIf

EndEvent
EndState

State DoNothingState
   ;intentional blank
EndState

 

Thanks SKK50! You're always so good with scripts. I'm still learning so this helps and will help with future scripts.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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