Jump to content

[LE] Spawning Leveled Actors


Recommended Posts

Hey all!

I've just noticed a problem with a script - whenever it spawns an actor, the instance isn't leveled as it should be.

Example: I've set up a leveled actor list for what creature to spawn at level 1, 5 and 10, but whenever the script runs, it spawns them all randomly.

The leveled list doesn't use all actors below PC level, and is set to the value 4 ( None ) in the script, so I've no idea what could be causing this issue.

 

Here's the script:

ActorBase Property SpawnUnit Auto
Int activatemode = 0
Int Property MaxCount Auto
GlobalVariable Property SpawnCounter Auto

Event OnActivate(ObjectReference akActionRef)
    If (akActionRef == Game.GetPlayer())
        If (activatemode == 0)
            activatemode = 1
            While (activatemode == 1)
                If (SpawnCounter.GetValue() < MaxCount)
                    Self.PlaceActorAtMe(SpawnUnit, 4)
                    SpawnCounter.SetValue(SpawnCounter.GetValue() + 1)
                    Utility.Wait(15.0)
                EndIf
            EndWhile
        ElseIf (activatemode == 1)
            activatemode = 0
            Self.Disable()
        EndIf
    EndIf
EndEvent

Any help will be greatly appreciated!

Link to comment
Share on other sites

To spawn an LVL Actor you need to spawn the LVL Marker which handles the LVL Actors.


By script you need to create 3 Form Lists which each will contain your actors level 1, 5 and 10, then you obtain the player's lvl (if you wanna use the player's level to spawn actors) and generate a "RadomInt()" from the choosen 'Form List' to spawn an actor.

And you are done.

Link to comment
Share on other sites

In regards to maxarturo's and AnishaDawn's posting, I would suggest following script code.

Unfortuantely I did not really understand the formlist handling. Maybe I am wrong here. And yes, its always a good idea to avoid a long wait.

 

nikoSpawnLvlActorScript

 

Scriptname nikoSpawnLvlActorScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/10054038-spawning-leveled-actors/

  GlobalVariable PROPERTY SpawnCounter auto        ; new created by CK
  Int            PROPERTY MaxCount = 5 auto        ; [default=5], means at least 5 creatures to spawn

; create 3 Form Lists which each will contain your actors level 1, 5 and 10
  Formlist PROPERTY myList01 auto                ; leveled actor list
      ; creatures Level 1
 
  Formlist PROPERTY myList02 auto
      ; creatures Level 5
 
  Formlist PROPERTY myList03 auto
      ; creatures Level 10

  Bool bRun        ; [default=False]


; -- EVENTs -- 3 + "Waiting"

EVENT OnCellAttach()  ; every time player and this object share the same parent cell
IF ( bRun )
ELSE
    bRun = TRUE
    self.EnableNoWait()
ENDIF
ENDEVENT

EVENT OnCellDetach()  ; every time player has left the cell with this object
IF ( bRun )
    bRun = False
    self.DisableNoWait()
ENDIF
ENDEVENT


EVENT OnActivate(ObjectReference akActionRef)
IF myF_IsPlayer(akActionRef)
    IF ( bRun )
        bRun = False        ; ***
        self.Disable()
    ELSE
        gotoState("Waiting")        ; ### STATE ###
        RegisterForSingleUpdate(1.5)        ; cooldown of 1,5 seconds
        bRun = TRUE         ; *T*
    ENDIF
ENDIF
ENDEVENT


;=======================================
state Waiting
;============
    EVENT OnUpdate()
        gotoState("")                ; ### STATE ### allow loop breaking
        float f = 15.0
        WHILE (bRun)       ; (bRun == TRUE)
            IF (f >= 15.0)        ; spawn only after 15 seconds wait, except first spawn
                myF_SpawnActor()
                f = 1.0
            ELSE
                f = f + 1        ; increase the wait counter
            ENDIF
            Utility.Wait(1.0)
        ENDWHILE
    ENDEVENT

    EVENT OnActivate(ObjectReference akActionRef)
        ; keep it empty here
    ENDEVENT
;=======
endState



; -- FUNCTIONs -- 2

;------------------------------------------------------
Bool FUNCTION myF_IsPlayer(ObjectReference akActionRef)
;------------------------------------------------------
    RETURN (akActionRef == Game.GetPlayer() as ObjectReference)
ENDFUNCTION


;------------------------
FUNCTION myF_SpawnActor()
;------------------------
; https://www.creationkit.com/index.php?title=PlaceActorAtMe_-_ObjectReference

IF (SpawnCounter.GetValueInt() >= MaxCount)
    bRun = False        ; abort spawning, maximum reached
    RETURN    ; - STOP -
ENDIF
;---------------------
IF self.Is3DLoaded()
ELSE
    bRun = False        ; abort spawning, failsafe here
    RETURN    ; - STOP - object/anchor to spawn actors does not have 3D ready
ENDIF
;---------------------
    int i = Game.GetPlayer().GetLevel()        ; obtain players level
    formlist fml                               ; temp variable to hold formlist property

    IF     (i < 11)
                    fml = myList01    ; player is level 1..10, spawn creatures level 1
    ELSEIF (i < 25)
                    fml = myList02    ; player is level 11..24, spawn creatures level 5
    ELSE
                    fml = myList03    ; player is level 25 or higher, spawn creatures level 10
    ENDIF
    
    i = Utility.RandomInt(0, fml.GetSize() - 1)
        
    actor aRef = self.PlaceActorAtMe( fml.GetAt(i) )
    IF ( aRef )
        SpawnCounter.Mod(1)           ; increase the global counter, if spawning was successful
;;      #####
        Debug.Trace(" myF_SpawnActor() - Actor is level " +aRef.GetLevel())        ; debugging only, output to "papyrus.0.log" above Skyrim savegame folder
;;      #####
    ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

@ ReDragon2013

After reading my own post i did realize that i wasn't too clear, even i couldn't understand what i was trying to say.


I was trying to say that: If the OP wants to place a random actor from the chosen 'Form List' and not all actors from the 'Form List', then generate a 'RandomInt' to place a random actor.


Something like this:



Form RandomForm = MyFormList.GetAt(Utility.RandomInt(0, (MyFormlist.GetSize() - 1)))
actor aRef = Self.PlaceActorAtMe(RandomForm)



PS: I'm at work and i didn't put too much thought into this, but i think you get the idea...


Have a nice week everybody.

Edited by maxarturo
Link to comment
Share on other sites

Sorry for the late reply, I was away for a while...

I didn't explain it correctly, as everyone mentions form lists. I meant leveled character.

 

I made a leveled character that uses an actor base to inherit the data, placed the actor base as a property in my activator script, but the leveling part doesn't work. The rest of the script is as it should be.

Check the attached pictures for more detail if I didn't make myself clear enough again.

Link to comment
Share on other sites

You did explain it correctly, but you didn't understand the explanation provided.


An LVL Actor it's a "Marker", that "Marker" must already exist in the world to run its 'Hard Coded' "OnAttach()" function, which executes the spawn of the LVL Actor, placing via script a marker will not execute that function since it's directly attached to the cell's "Encounter Zone" which initallaize once you are entering a cell (loading a cell).


In other words:

When an actor defined by a leveled character template is placed in the world, the reference is typically represented by a generic marker instead of a model, since the Creation Kit has no way to know what model to place until the cell it's loaded and its Encounter Zone fixes all Actor Markers.


The suggestion with the 'Form Lists' it's the alternative of what you want to do.


* You cannot have a Leveled Character composed of Leveled Characters.


Have a nice weekend.

Edited by maxarturo
Link to comment
Share on other sites

Thank you for your help, Maxarturo!

You're right, but I know about markers, I've been modding Oblivion and then Skyrim since 2010. I was confused since in Oblivion it worked fine.

I didn't know about the hardcoded part - so that is why my level 45 character always got the highest level enemies in the cell, even when I changed his level via console...

 

I guess I'll have to try form lists, or possibly place the marker in a hidden unleveled cell and then use it?

 

* I'm not sure about that, seems to work as intended. I've been doing that for a long time. Probably because they aren't leveled per say, it's just a level 1 list.

Link to comment
Share on other sites

...modding Oblivion was 10000x easier. Ya didn't feel like you needed a degree in computer science..

 

Another thing to take note of is that if the cell has an encounter zone, the lvl of the leveled actors will be locked to the level of the player when the player first enters that cell, permanently.

Link to comment
Share on other sites

AnishaDawn, I have to agree with you completely. Actors, leveled stuff and scripts were a lot simpler.

 

I knew about it sticking with your level, but does permanently mean even on cell respawn?

 

Also why did they remove the count option in leveled lists... shame. They're leaving more and more stuff from Fallout and previous ES games that's just there, but cannot be used, like the open magic effect, VATS, addiction, fame, etc... Serves no purpose now.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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