Jump to content

Reset timer for tiny actor spawn script in trigger


Recommended Posts

Hello,
I'm trying to work out a timer for a trigger so that on entry it spawns actors every, for example, 10 minutes (regardless of if the player character walks through the trigger several times in the meantime).

Basically to self.disable itself, then self.enable after x amount of time.
I used to know this...but now I can't even remember where to start (and, goodness knows, I've tried). =/

Scriptname ASmallAdditionSpawnPoints001 extends ObjectReference

ActorBase property asmalladditiongreenarmyworkshopnpc auto

ObjectReference property SpawnPlace auto
ObjectReference property SpawnPlace1 auto
ObjectReference property SpawnPlace2 auto
ObjectReference property SpawnPlace3 auto
ObjectReference property SpawnPlace4 auto


Event Ontriggerenter(ObjectReference akActionRef)
 SpawnPlace.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
 SpawnPlace1.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
 SpawnPlace2.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
 SpawnPlace3.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
 SpawnPlace4.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)

EndEvent

I think it's something like:
float Property DaysUntilReset = -1.0 Const Auto

...but much more. =/ Yeah, that part is not right at all.

Any ideas, please?

Thank you.

Edit: ...and I messed up the title, meant to delete "Reset", as that is incorrect...and I named my property with the actor name instead of something more general like "ActorToSpawn"...geez, what a day. =/

Link to comment
Share on other sites

Maybe something like this would work?

Scriptname ASmallAdditionSpawnPoints001 extends ObjectReference

ActorBase property asmalladditiongreenarmyworkshopnpc auto

ObjectReference property SpawnPlace auto
ObjectReference property SpawnPlace1 auto
ObjectReference property SpawnPlace2 auto
ObjectReference property SpawnPlace3 auto
ObjectReference property SpawnPlace4 auto

Event OnInit()
  GoToState("TriggerIdle")
EndEvent

State TriggerIdle
Event OnTriggerEnter(ObjectReference akActionRef)
  GoToState("TriggerActive")
EndEvent

State TriggerActive
Event OnBeginState(string asOldState)
  self.BlockActivation()
  SpawnPlace.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace1.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace2.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace3.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace4.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  StartTimer(600)
  SpawnPlace.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace1.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace2.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace3.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace4.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  StartTimer(600)
  SpawnPlace.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace1.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace2.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace3.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  SpawnPlace4.PlaceActorAtMe(asmalladditiongreenarmyworkshopnpc, 0)
  self.BlockActivation(false)
  GoToState("TriggerIdle")
EndEvent

Once the player enters the trigger it spawns your 5 actors then waits 10 minutes (600 seconds) before doing it again, then repeating it a total of 3 times (Although you could copy it as many times as you wanted or create some kind of loop). After the third time, the trigger is switched back to idle at which point it has to be triggered again. This *should* also prevent the player from triggering it multiple times while it's still running.

Edited by someoneyouknow
Link to comment
Share on other sites

I like the look of it. I'll test it out tonight.

Good job. =)

 

Also, thank you for getting my meaning. I was all over the place grammatically...and just couldn't figure out how to say what I was looking for.

 

I think my real thoughts are something like 3-10 seconds in between, to stagger them a little (I'm a little waffle'y about the repeat number, but 3 sounds about right, yeah).

 

Will probably try to add on at the end, before idle, another wait of maybe an hour. *Should* keep it from being activated again for such amount of time. Not sure how acceptable, code performance optimization wise (code faux pas?), that hour wait would be however.

Link to comment
Share on other sites

Thanks. Let me know if it works. :smile:

 

EDIT: For that last bit I'm not sure if you mean a real hour or an in-game hour, but I'm guessing you mean a real hour. If that's the case, an event using "RegisterForSingleUpdate" and "OnUpdate" may be what you're looking for on the end if you're planning on such a long delay as it's better than using Timer. https://www.creationkit.com/index.php?title=RegisterForSingleUpdate_-_Form

Edited by someoneyouknow
Link to comment
Share on other sites

It's not a hard hour yet either way. Figure I'd probably end up adjusting it anyhow...

 

So, where as the timer is (finally) looking familiar, onupdate and blablahupdate are not (but, again, my memory is shot). I'll have to look at that link. Another good idea.

 

Have to try tomorrow (just too busy today...beginning to think I may never "finish" this mod).

 

Once this is all done, and I've (assuming I can make my brain work) got them moving along to where I want with patrol markers, sandboxes and such or a 'move to player' script, I'm hopeful this will make a good spawn setup for small areas. Kind of a simulated random encounter deal,with the trigger boxes made small and placed in various places on the map.

Link to comment
Share on other sites

A safer none scripting alternative is use an enable parent with those actors(they can be placed on timers, in seconds). Still perm persistent, but you're not relying on

calling a function like that several times in a row.

 

Both scripts in this thread, needs to be corrected in a few areas. I could help more(and presented in a "teaching" way), but maybe later.

Edited by Lisselli
Link to comment
Share on other sites

Ok I have come up with this. Still on the slow side, but keeps offers the VM some breathing room and you don't need PlaceActorAtMe. I also offered a choice of deleting the actors. This is all untested.

Scriptname TriggerDisablingScript extends ObjectReference

ActorBase property asmalladditiongreenarmyworkshopnpc auto

ObjectReference property SpawnPlace auto
ObjectReference property SpawnPlace1 auto
ObjectReference property SpawnPlace2 auto
ObjectReference property SpawnPlace3 auto
ObjectReference property SpawnPlace4 auto

Form kActorRef
Actor[] CreatedActors

Event OnInit()
CreatedActors = new Actor[5]
kActorRef = asmalladditiongreenarmyworkshopnpc as form

EndEvent

; Ill use this to track how many times the update has run.
Int iTimesUpdateRan

; When needing a trigger to do different things, always start the first thing you want it to do in the auto state.
AUTO STATE DefaultState
    Event OnTriggerEnter(ObjectReference akActionRef)
        if akActionRef == Game.GetPlayer()
            ; Player has walked through me. Turn myself off.
            GoToState("Waiting")
            ; Have Update handle my spawning.
            RegisterForSingleUpdateGameTime(0.1) ; 10 minutes.
            ; Note this is in Game Time, not Real time.
        endif
    EndEvent
ENDSTATE
    
STATE Waiting
    ; Dont need to add anything in the Event. Its to block the trigger.
    Event OnTriggerEnter(ObjectReference akActionRef)
    ; empty event is thrown out by the game engine.
    EndEvent
ENDSTATE

Event OnUpdateGameTime()
    GoToState("DefaultState")
    if iTimesUpdateRan == 0
        ; We're going to spawn our first actor.'
        SpawnPlace.PlaceAtMe(kActorRef)
        iTimesUpdateRan += 1
        CreatedActors[0] = kActorRef as Actor
    elseif iTimesUpdateRan == 1
        SpawnPlace1.PlaceAtMe(kActorRef)
        iTimesUpdateRan += 1
        CreatedActors[1] = kActorRef as Actor
    elseif iTimesUpdateRan == 2
        SpawnPlace2.PlaceAtMe(kActorRef)
        iTimesUpdateRan += 1
        CreatedActors[2] = kActorRef as Actor
    elseif iTimesUpdateRan == 3
        SpawnPlace3.PlaceAtMe(kActorRef)
        iTimesUpdateRan += 1
        CreatedActors[3] = kActorRef as Actor
    elseif iTimesUpdateRan == 4
        SpawnPlace4.PlaceAtMe(kActorRef)
        CreatedActors[4] = kActorRef as Actor
        ; All spawns have been placed. Disable this trigger for good.
        GoToState("Waiting")
    endif
        
EndEvent

Function DeleteCreatedActors()
    ; Stores the amount of indexs in this array.
    Int Index = CreatedActors.Length
        
    While Index
        ; Loop until it reaches the first element.
        Index -= 1
        
        ; We need to disable the actors.
        CreatedActors[Index].Disable()
        
        ; Now we delet them.
        CreatedActors[Index].Delete()
    EndWhile
EndFunction
Edited by Lisselli
Link to comment
Share on other sites

Okay, had a few minutes last night to work on this.

Though a good attempt by Someoneyouknow (thank you), Lisselli is right, compiler was complaining about expecting endstate.

 

That was okay, however, as I did clear that up myself (I do remember some things sometimes, heh), along with fooling with onbeginstate (shifting all states a bit, really), and adding in ids for the timers (though I don't think I remembered that correctly, had "starttimer(10, 1)" and "blah...2"...but I *think* I needed to define them...? Anywho...).

 

Still, they would all spawn at once onenter and the trigger would never activate again (which is something I'd like to happen after x amount of time, ex: 1 hour) on any subsequent entries (regardless of time between).

 

Registerforupdate I never attampted as I never got far enough to warrant testing of that.

 

In other words, after my 20 minutes of free time to myself (whack!), I was still floundering. =P

 

So, Lisselli, I'll take a look at your code hopefully tonight. It looks fancy, for sure. =)

Thank you, I appreciate the suggestions.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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