Swarm of Insects: Part II

Post » Thu Jun 21, 2012 7:33 am

So, I've made a spell that summons a swarm of insects (it also creates a cloak that prevents spellcasting) but there are a few aesthetic problems. First I'll post the script, and then I'll discuss it. Maybe someone will have some helpful hints as to future directions this can go.

Scriptname DnDSwarmCurseScript extends activemagiceffectimport Critterimport Utilityint property iMaxCritterCount autoint property iCurrentCritterCount autoFormList Property CritterTypes autoActivator Property DnDSwarmBug autoint property fMaxPLayerDistance autoevent OnEffectStart(Actor akTarget, Actor akCaster); How many do we need to spawn?int icrittersToSpawn = iMaxCritterCount; Create that many crittersint i = 0;while (i < icrittersToSpawn)  ; Create one critter at a time  ;SpawnCritteratRef(akCaster as ObjectReference)  ObjectReference critterRef = akCaster.PlaceAtMe(Game.GetForm(0x020048AD), 1, false, false)  ; Wait a bit before the next spawn  ;Wait(fFastSpawnInterval)  ; Next  i = i + 1endWhile;Debug.MessageBox("generation complete")endEvent; Spawns one Critter at a specific locationFunction SpawnCritterAtRef(ObjectReference arSpawnRef); Pick a random critter typeActivator critterType = CritterTypes.GetAt(RandomInt(0, CritterTypes.GetSize() - 1)) as Activator; Create the critter and cast it to the critter base classObjectReference critterRef = arSpawnRef.PlaceAtMe(critterType, 1, true, false);Critter thecritter = critterRef as Critter; Set initial variables on the critter; ;  Debug.TraceConditional("Spawner " + self + " is creating Critter " + thecritter, bPrintDebug);endFunction

This script is just a little snippet from some of Beth's code with a bit of modifying, but it works well at spawning bees wherever the player is. Now for the real script.

Scriptname DnDBeeSwarmingScript extends ObjectReference  import Mathint Property duration autoevent OnLoad()   self.RegisterForSingleUpdate(duration)   MoveBee()endEventfunction MoveBee()   int i = 0   int randomx = 0   int randomy = 0   int randomz = 0   randomx = Utility.RandomInt(-50, 50)   randomy = Utility.RandomInt(-50, 50)   randomz = Utility.RandomInt(-50, 50)   int randomxori = randomx + self.GetPositionX() as int   int randomyori = randomy + self.GetPositionY() as int   int randomzori = randomz + self.GetPositionZ() as int   self.SplineTranslateTo(randomXori, randomYori, randomZori, Math.sin(randomy/randomx), 0, Math.sin(randomy/randomx), 1, 85)endFunctionEvent OnTranslationComplete()   MoveBee()endEventevent OnUpdate()   Self.disable()   Utility.Wait(0.2)   Self.delete()endEvent

Simple enough. The problem I'm having is that I would like to
1) (SOLVED)Spawn all the bees on player simultaneously, but as this is 300 objects, I worry about overloading the game. Does anyone know a "safe" number of objects to spawn simultaneously? (I'm using 10 at at a time, and the visual effect is very cool.)
2) (SOLVED)More importantly, the bees all face the same direction no matter where they move. Does anyone know of a good way to make the bees always face the direction that they are going? I have a feeling it just involves some basic trigonometry, but trig was never my strong suit.
3) The bees make these little "quantum jumps" where after they complete a translation, the suddenly pop somewhere else. Not sure what to make of that.

EDIT: Changed second script a little. Its closer now, but still isn't quite beautiful.
User avatar
Miragel Ginza
 
Posts: 3502
Joined: Thu Dec 21, 2006 6:19 am

Post » Thu Jun 21, 2012 2:10 am

3) The bees make these little "quantum jumps" where after they complete a translation, the suddenly pop somewhere else. Not sure what to make of that.

EDIT: Changed second script a little. Its closer now, but still isn't quite beautiful.
Have you tried using Event OnTranslationAlmostComplete()?
User avatar
Kayla Bee
 
Posts: 3349
Joined: Fri Aug 24, 2007 5:34 pm

Post » Thu Jun 21, 2012 2:39 pm

Have you tried using Event OnTranslationAlmostComplete()?

I was actually just reading about that, thanks for the input!
User avatar
Soph
 
Posts: 3499
Joined: Fri Oct 13, 2006 8:24 am

Post » Thu Jun 21, 2012 12:48 am

Why do you have so many comments/properties you don't use in your spell script?
User avatar
biiibi
 
Posts: 3384
Joined: Sun Apr 08, 2007 4:39 am

Post » Wed Jun 20, 2012 10:41 pm

Why do you have so many comments/properties you don't use in your spell script?

Like I said, its just pared down Bethesda code. I wasn't sure what things I would wind up requiring, so I just left it all in in case I need the functionality to change somehow in the future.
User avatar
Mr.Broom30
 
Posts: 3433
Joined: Thu Nov 08, 2007 2:05 pm


Return to V - Skyrim