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);endFunctionThis 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.
