Jump to content

[LE] MMO-Style Boss Script (Mob Spawn) - Need Help improving and cleaning it up.


Medabev

Recommended Posts

Hello Everyone.

 

I've Been working hard on a project of mine, I'd like to get ready before AE arrives. In my Mod I have Boss NPC's that need to be defeated(something like a WoW Raid boss) . I've patched together a Script that somewhat works but I've reach a snag and it needs to be in better hands. I feel like I'm doing something wrong or missing something. The Script fires off, well but it won't stop looping. I've tried killing the script when I leave the cell or unload and it still keeps going. My goal is to keep having Enemies spawning, supporting the boss and if the boss is defeated, explosions everywhere. I'd like to add more effects but I can't think of anything else. But my main priority is to get it working first. Here is the Script:

 

Thank you for any assistance :thumbsup:

Scriptname MMO_BossMobs_SCRIPT extends Actor  

Actor Property PlayerRef Auto
												
ObjectReference property Xmarker1 auto
ObjectReference property Xmarker2 auto
ObjectReference property Xmarker3 auto
ObjectReference property Xmarker4 auto
ObjectReference property Xmarker5 auto
ObjectReference property Xmarker6 auto
ObjectReference property Xmarker7 auto
ObjectReference property Xmarker8 auto
ObjectReference property Xmarker9 auto
ObjectReference property Xmarker10 auto

ActorBase Property BossMobs Auto

ObjectReference MobNPC1
ObjectReference MobNPC2
ObjectReference MobNPC3
ObjectReference MobNPC4
ObjectReference MobNPC5
ObjectReference MobNPC6
ObjectReference MobNPC7
ObjectReference MobNPC8
ObjectReference MobNPC9
ObjectReference MobNPC10



Explosion Property ExplosionIllusionMassiveLight01 Auto
{Big Explosion for Pillar}

Explosion Property ExplosionIllusionLight Auto
{Big Explosion when Ambush Ends}

Explosion Property iExplo3 Auto
{Explosion when Battle is Over}

;===========================================================================

Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
 
If aeCombatState == 1
        Actor player = Game.GetPlayer()
        If akTarget == player
	Registerforsingleupdate(10.0)
			Endif
				Endif
		EndEvent
		

Event OnUpdate()


		If Self.IsDead()
		UnregisterforUpdate()
	else
		Endif		

	GoToState("Busy")
	
	self.PlaceAtme(ExplosionIllusionMassiveLight01)

	MobNPC1 = Xmarker1.PlaceAtme(BossMobs)
	Xmarker1.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC2 = Xmarker2.PlaceAtme(BossMobs)
	Xmarker2.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC3 = Xmarker3.PlaceAtme(BossMobs)
	Xmarker3.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC4 = Xmarker4.PlaceAtme(BossMobs)
	Xmarker4.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC5 = Xmarker5.PlaceAtme(BossMobs)
	Xmarker5.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC6 = Xmarker6.PlaceAtme(BossMobs)
	Xmarker6.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC7 = Xmarker7.PlaceAtme(BossMobs)
	Xmarker7.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC8 = Xmarker8.PlaceAtme(BossMobs)
	Xmarker8.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC9 = Xmarker9.PlaceAtme(BossMobs)
	Xmarker9.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)
	MobNPC10 = Xmarker10.PlaceAtme(BossMobs)
	Xmarker10.PlaceAtme(ExplosionIllusionLight)
	utility.wait(2.0)

		RegisterForSingleUpdate(30.0)
		
		GoToState("")
	
		EndEvent

;===========================

State Busy

Event OnUpdate()

EndEvent
	EndState

;===========================




Event OnDeath(Actor akKiller)

	
	Xmarker1.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker2.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker3.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker4.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker5.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker6.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker7.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker8.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker9.PlaceAtme(iExplo3)
	utility.wait(2.0)
	Xmarker10.PlaceAtme(iExplo3)
	utility.wait(3.0)
	self.PlaceAtme(ExplosionIllusionMassiveLight01)
	
		EndEvent
Link to comment
Share on other sites

In the OnCombatStateChanged event, you need to move the Endif to the end of the event. As it stands now, it unregisters for the update, but still registers again at the end of the event because the rest of the code isn't in the Else block. Make sure you indent properly so you can better see the logic. It should look like this:

 

Scriptname MMO_BossMobs_SCRIPT extends Actor  


Actor Property PlayerRef Auto
                                                
ObjectReference property Xmarker1 auto
ObjectReference property Xmarker2 auto
ObjectReference property Xmarker3 auto
ObjectReference property Xmarker4 auto
ObjectReference property Xmarker5 auto
ObjectReference property Xmarker6 auto
ObjectReference property Xmarker7 auto
ObjectReference property Xmarker8 auto
ObjectReference property Xmarker9 auto
ObjectReference property Xmarker10 auto


ActorBase Property BossMobs Auto


ObjectReference MobNPC1
ObjectReference MobNPC2
ObjectReference MobNPC3
ObjectReference MobNPC4
ObjectReference MobNPC5
ObjectReference MobNPC6
ObjectReference MobNPC7
ObjectReference MobNPC8
ObjectReference MobNPC9
ObjectReference MobNPC10


Explosion Property ExplosionIllusionMassiveLight01 Auto
{Big Explosion for Pillar}


Explosion Property ExplosionIllusionLight Auto
{Big Explosion when Ambush Ends}


Explosion Property iExplo3 Auto
{Explosion when Battle is Over}


;===========================================================================


Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
    If aeCombatState == 1
        Actor player = Game.GetPlayer()
        If akTarget == player
            Registerforsingleupdate(10.0)
        Endif
    Endif
EndEvent
        


Event OnUpdate()
    
    If Self.IsDead()
        UnregisterforUpdate()
    else
        
        GoToState("Busy")
        
        self.PlaceAtme(ExplosionIllusionMassiveLight01)


        MobNPC1 = Xmarker1.PlaceAtme(BossMobs)
        Xmarker1.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC2 = Xmarker2.PlaceAtme(BossMobs)
        Xmarker2.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC3 = Xmarker3.PlaceAtme(BossMobs)
        Xmarker3.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC4 = Xmarker4.PlaceAtme(BossMobs)
        Xmarker4.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC5 = Xmarker5.PlaceAtme(BossMobs)
        Xmarker5.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC6 = Xmarker6.PlaceAtme(BossMobs)
        Xmarker6.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC7 = Xmarker7.PlaceAtme(BossMobs)
        Xmarker7.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC8 = Xmarker8.PlaceAtme(BossMobs)
        Xmarker8.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC9 = Xmarker9.PlaceAtme(BossMobs)
        Xmarker9.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)
        MobNPC10 = Xmarker10.PlaceAtme(BossMobs)
        Xmarker10.PlaceAtme(ExplosionIllusionLight)
        utility.wait(2.0)


        RegisterForSingleUpdate(30.0)
        
        GoToState("")
    Endif       


EndEvent


;===========================


State Busy


    Event OnUpdate()


    EndEvent
EndState


;===========================








Event OnDeath(Actor akKiller)


    Xmarker1.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker2.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker3.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker4.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker5.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker6.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker7.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker8.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker9.PlaceAtme(iExplo3)
    utility.wait(2.0)
    Xmarker10.PlaceAtme(iExplo3)
    utility.wait(3.0)
    self.PlaceAtme(ExplosionIllusionMassiveLight01)
EndEvent
Link to comment
Share on other sites

@dylbill

 

I can't believe that's all it took to fix this script. I've spend a good two hours rewriting testing this thing yesterday before I gave up and decided to ask for help. I thought It was a problem with OnUpdate but never think it was the OnCombatStateChanged. This is one of my favorite scripts I've made, and I'm grateful that you helped me fix this thing up. I just tested it, and the battle is pretty chaotic, which is what I wanted plus the Loop as ended.

I'm still learning about the creation kit after all this time, and the good thing, thanks to tinkering with the script I got a better understanding on how states work. It's going to be fun going back to my other scripts and cleaning those up to. Thanks again for your assistance! :laugh:

Edited by Juebev
Link to comment
Share on other sites

No problem :) actually it was in the OnUpdate event, I mis typed. You had:

 

If Self.IsDead()
    UnregisterforUpdate()
else
Endif

In the original script. I just moved the Endif down so the rest of the code was in the Else block. As it was, the rest of the code still ran in every update because it wasn't conditionalized.

Link to comment
Share on other sites

Arrays are very useful for batch scripting. Example you could instead have ObjectReference[] Property Xmarkers and do the same thing in a much tidier block which is easier to review and test

 

Int Digit = Xmarkers.Length

While Digit as Bool

Digit -= 1

Xmarkers[Digit].PlaceAtMe(ExplosionIllusionLight)

; Whatever else too just showing the syntax

Utility.Wait(2.0)

EndWhile

 

You also dont need to declare player on the combat event. And you can do the If/Then route or just make it a one line string. Same result up to you

 

Event OnCombatStateChanged(Actor akTarget,Int aeCombatState)
aeCombatState == 1 && akTarget.GetFormID() == 0x14 && RegisterForSingleUpdate(10.0)
EndEvent

 

Outside of all of this, I would probably approach this differently, based on what it sounds like you are doing. Always do what you prefer but if you have certain goals you might benefit from other approaches. One example would be simply have 1 marker and have it move to drop an explosion. Etc

Link to comment
Share on other sites

 

Outside of all of this, I would probably approach this differently, based on what it sounds like you are doing. Always do what you prefer but if you have certain goals you might benefit from other approaches. One example would be simply have 1 marker and have it move to drop an explosion. Etc

 

I'm 100% there's a better way of writing this script as you proved and I'm all for it. I'm still learning as I go, I just copple together what I know and try and make something work. I have some other scripts I've been experimenting on for learning purposes, but this particular script I really wanted to work. Now that I have a working script, I'm definitely going to try and improve on it.

Edited by Juebev
Link to comment
Share on other sites

  • Recently Browsing   0 members

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