For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Simple actor spawner? [WRITTEN]

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
User avatar
LOL_PEANUTS
OldUnreal Member
Posts: 11
Joined: Wed Mar 14, 2007 7:17 pm

Simple actor spawner? [WRITTEN]

Post by LOL_PEANUTS »

SOLVED AND WRITTEN.
SEE THE ANSWER IN A LATER POST OF MINE.
HEY, USCRIPT KIDDIES- I'VE GOT A CHALLENGE FOR YOU:

I was trying to create a simple mass actor spawner, but I fail miserably at everything USEFUL that uscript has to offer. Here's what I had in mind:

The spawner, let's refer to it as "SimpleActorSpawner," would randomly distribute actors within a set radius of the spawnpoint's original position. Instead of only spawning one type of actor, it would choose between a maximum of four different types of actors, with weighting on each.

SUGGESTED VARIABLES TO BE ACCESSIBLE THROUGH THE CLASS'S PROPERTIES EXPANDER:
MinSpawnRadius (float) -The minimum radius that the actors can spawn in. Helpful for spawning a horde of enemies around a specific area. Set to zero to ignore
MaxSpawnRadius (float) -The maximum radius that the actors can spawn in
SpawnNumber (byte) -The number of actors that spawn in the field
bFaceParentOnSpawn (bool) -Whether or not the actors spawned will face the SimpleActorSpawner that created them. Useful for the same reason that I suggested MinSpawnRadius, in my opinion
Thing1 (class) -One of the actors that can spawn
Thing2 (class) -One of the actors that can spawn
Thing3 (class) -One of the actors that can spawn
Thing4 (class) -One of the actors that can spawn
Thing1OddsOfAppearing (float) -The chance that Thing1 will spawn, integer 0 to 1 style
Thing2OddsOfAppearing (float) -The chance that Thing2 will spawn, integer 0 to 1 style
Thing3OddsOfAppearing (float) -The chance that Thing3 will spawn, integer 0 to 1 style
Thing4OddsOfAppearing (float) -The chance that Thing4 will spawn, integer 0 to 1 style

NOTE: Thing1OddsOfAppearing, Thing2OddsOfAppearing, Thing3OddsOfAppearing, and Thing4OddsOfAppearing must add up to 1.000000. Basically, multiply ThingxOddsOfAppearing by 100, and that's the percent chance that an actor spawned by the spawnpoint is Thingx. I've seen this method used several times by the original unreal uscript programmers (the Skaarj's speech technique, for example. They didn't use variables, but it was a way to split a chance 1/3-1/3-1/3). So yeah, it should work.

OTHER RECOMMENDATIONS FOR THE ACTOR CLASS:
-If bFaceParentOnSpawn is false, all actors spawned should have the same rotation values as the SimpleActorSpawner that spawned it. This would save a lot of time for me, and it wouldn't be difficult at all to implement (although bFaceParentOnSpawn's true value may be =D).
-It would probably be best for this to be a child of the original actor class. It doesn't really need to borrow code from other classes.

EPILOGUE:

The reason I would like this is because I need a way to easily spawn one actor (probably a simple modification of this condensed to a .U, with my own settings for all the variables) during gameplay, and instantly get an army. Plus, this would be a fabulous script, even if a similar one exists, this one would hopefully introduce some new ideas. It's simple, elegant, and the end result could be a hassle-free, and possibly revolutionary spawner.

Sorry for posting such a ridiculously complicated request, but I really feel this has potential.

EDITS:
ten minutes after i posted this, added to "OTHER RECOMMENDATIONS"
Last edited by LOL_PEANUTS on Mon Feb 09, 2009 2:04 am, edited 1 time in total.
User avatar
Shivaxi
OldUnreal Member
Posts: 2232
Joined: Wed Mar 08, 2006 4:43 pm

Re: Simple actor spawner? [LONG POST]

Post by Shivaxi »

i talked to Cheese and he had a look and he said that he has a mutator that can do this...its called iCMutate...976 runz it :P

talk to him and he'll give it to ya cause its not released yet :P
Image  Image
User avatar
Cheese
OldUnreal Member
Posts: 24
Joined: Tue May 22, 2007 11:38 pm

Re: Simple actor spawner? [LONG POST]

Post by Cheese »

Well It doesn't quite do what you're asking. There are a few things similar, As in creating armies of monsters throughout the level, etc. But I'll see what I can do.
Currently lurking...
User avatar
deathpax
OldUnreal Member
Posts: 21
Joined: Mon Apr 30, 2007 8:38 pm

Re: Simple actor spawner? [LONG POST]

Post by deathpax »

This post caught my attention :P it deals with a number of problems i ran into experimenting with particle emitters Ill see if i can't whip up some code for ya
User avatar
deathpax
OldUnreal Member
Posts: 21
Joined: Mon Apr 30, 2007 8:38 pm

Re: Simple actor spawner? [LONG POST]

Post by deathpax »

heres the math side of it anyway, someone else can extend this

The way most people would generate a random location in a radius is flawed
the spawn locations are usually clustered towards the center of the disc

to use this simply plug in the maxradius and minradius, the function returns the random location

Code: Select all

// CalculateWithinDisc.
// Calculate a TRUE random location within an X/Y planar Disc
// Author: Death Pax
function vector CalculateWithinDisc(float MaxRadius, float MinRadius)
{
      local vector SpawnLoc;
      local float RandAngle;
      local float Radius;
      RandAngle=Frand()*(2*Pi);//Random angle in radians (2 Pi = circle)
      //Random Radius between max and min radius, scaled for gaussian distribution
      Radius=MinRadius+((MaxRadius-MinRadius)*sqrt(Frand()));
      SpawnLoc.X = Location.X - Radius * Sin(RandAngle);
      SpawnLoc.Y = Location.Y + Radius * Cos(RandAngle);
      SpawnLoc.Z = Location.Z;
      return SpawnLoc;
}
For Instance:

Code: Select all

function SpawnGroup(class aClass, int Quantity, float MaxRadius, float MinRadius)
{
      local int i;
      for( i=0; i
User avatar
LOL_PEANUTS
OldUnreal Member
Posts: 11
Joined: Wed Mar 14, 2007 7:17 pm

Re: Simple actor spawner? [LONG POST]

Post by LOL_PEANUTS »

Okay, 363 days later, I've gotten a little proficient at uscript. All the same, I'm rather lost when I run into almost any problem.

Here's what I've got so far:

Code: Select all

//=============================================================================
// PSpawner v1
// A massive failure by LOL_PEANUTS
//=============================================================================
class PSpawner expands Keypoint;

var() int ActorsToSpawn;
var() float DistanceToCenterMin,DistanceToCenterMax;
var() class      Actor[8];
var() float ActorProbability[8];
var() const enum EDetermineDirectionVia{
      FACE_Direction,
      FACE_Center,
      FACE_Away,
      FACE_Random
} DetermineDirectionVia;
var() name ActorTag;
var int ActorsToSpawnR;
var class ActorR;
var float RotToUse;

function PostBeginPlay()
{
      log("step1");
      ActorsToSpawnR=0;
}

function SpawnActors()
{
local actor w;
local rotator DTRot;
local bool Satisfied;
RotToUse=FRand() * 65535;
log("step2");
DTRot.Pitch=0;
DTRot.Roll=0;
DTRot.Yaw=RotToUse;
Satisfied=false;
ActorR=Actor[0];
if (Actor[1]!=None && FRand()
Last edited by LOL_PEANUTS on Fri Aug 29, 2008 5:36 pm, edited 1 time in total.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Simple actor spawner? [still need help, 8/29/08]

Post by []KAOS[]Casey »

PostBeginPlay needs to call SpawnActors() in the function or else it will do nothing but log.

You'll have to use a loop or something to spawn multiple

Code: Select all

function PostBeginPlay()
{
      local int I;

      for(I=0; I
User avatar
Smartball
Global Moderator
Posts: 241
Joined: Fri Mar 22, 2002 4:01 am

Re: Simple actor spawner? [still need help, 8/29/08]

Post by Smartball »

DeathPax already posted the most difficult part of implementing a script like this, but here's my take on it (following DeathPax's method):

Code: Select all

class RadiusSpawner extends Actor;

var() float MinSpawnRadius;      // The minimum radius distance for spawned items
var() float MaxSpawnRadius;      // The maximum radius distance for spawned items
var() int SpawnCount;      // How many items to spawn total
var() int ItemCount;      // How many items are used in the SpawnClasses array

var() bool bFaceParentOnSpawn;      // Should the items face this object when spawned?

var() class SpawnClasses[10];      // The potential classes to spawn

var() float SpawnProbability[10];      // The probabilities for each of the potential classes

var float CumulativeProbabilities[10];      // The combined probability of each item, used internally for picking which item to spawn

function PostBeginPlay()
{
      local int i;
      local float totalProb;

      if(MinSpawnRadius >= 0) {
            if(MaxSpawnRadius >= MinSpawnRadius) {
                  totalProb = 0;
                  for(i = 0; i < ItemCount; ++i)
                  {
                        if(SpawnProbability[i] < 0.0f)      // Probabilities shouldn't be negative :/
                        {
                              log("Negative probability found for item -> "$SpawnClasses[0]);
                              return;
                        }
                        else if(SpawnClasses[i] == None) // We should have a class here
                        {
                              log("Missing SpawnClass at index "$i);
                              return;
                        }
                        else
                              totalProb += SpawnProbability[i];
                  }

                  if(totalProb != 1.0)      // The probabilities should add up to 1.0
                        log("Probabilities do not add up to 1.0!");
                  else
                        GenerateAllItems();
            }
            else      // Max < Min?
                  log("MaxSpawnRadius is less than MinSpawnRadius!");
      }
      else      // Negative radius?
            log("MinSpawnRadius is negative!");
}

function GenerateCumulativeProbabilities() {
      local int i;
      local int j;
      for(i = 0; i < ItemCount; ++i)
            for(j = 0; j
Last edited by Smartball on Sat Aug 30, 2008 2:45 am, edited 1 time in total.
Of all the things I've lost, I miss my mind the most.
User avatar
Chaos13
OldUnreal Member
Posts: 951
Joined: Sat Feb 16, 2008 10:24 am

Re: Simple actor spawner? [still need help, 8/29/08]

Post by Chaos13 »

WIP is on my iSpawner, current variables:

Code: Select all

//-----------------------------------------------------------
// Ikuto's Actor Spawner
//-----------------------------------------------------------
class iSpawner expands Actor;

enum EPickType { PT_Random, PT_Linear };

var (iS_General) enum ELocType { LT_None, LT_Box, LT_Sphere, LT_HemiSphere,
                                                LT_Cylinder, LT_Disc, LT_Defined } LocType; //LT
var (iS_General) int NumToSpawn; //Num of actors to spawn (total)
var (iS_General) name AssignTag; //New tag to spawned Actors
var (iS_General) name AssignEvent; //New event to spawned Actors
var (iS_General) enum EFaceType { FT_Constant, FT_Random, FT_RandomConstrainted,
                                                 FT_Spawner, FT_SpawnerNega, FT_Actor } FaceType; //FT
var (iS_General) enum ESpawnerType { ST_OnSpawn, ST_OnTrigger, ST_Factory } SpawnType; //ST

var (iS_Class) EPickType PickType; //PT
var (iS_Class) class SpawnClass[64]; //Classes to spawn
var (iS_Class) float SpawnProbability[64]; //Probabilities
var private int ClLin;

var (iS_Factory) bool bActive; //Used for FT_Factory
var (iS_Factory) float ActorsPerSec; //Speed of spawning
var (iS_Factory) bool bTriggerToggles; //Trigger toggles bActive
var (iS_Factory) bool bFactInfinite; //Ignore NumToSpawn

var (iS_OnTrigger) int NumToSpawnPerTrigger; //No comments
var (iS_OnTrigger) bool bInfinite; //Ignore NumToSpawn

var (iS_Location_Box) BoundingBox SpawnBox; //For LT_Box
var (iS_Location_Box) BoundingBox NoSpawnBox; //Not spawned here

var (iS_Location_Cylinder) float CylinderZMax; //Relative
var (iS_Location_Cylinder) float CylinderZMin; // heights

var (iS_Location_Defined) vector Locations[64]; //Locations
var (iS_Location_Defined) float LocationProbability[64]; //Loc probability
var (iS_Location_Defined) EPickType LocPickType; //PT
var private int LcLin;

var (iS_Location_HemiSphere) float MinAngle; //-180...180
var (iS_Location_HemiSphere) float MaxAngle; //180...-180

var (iS_Location_Radius) float SpawnRadiusMax; //Radius max
var (iS_Location_Radius) float SpawnRadiusMin; //Radius min

var (iS_Rotation_Actor) actor TargetActor; //New actors will be facing this (if FT_Actor)

var (iS_Rotation_Constant) rotator ConstantRotation;

var (iS_Rotation_Constraints) rotator ConstraintMin; //Minimal constraint
var (iS_Rotation_Constraints) rotator ConstraintMax; //Maximal constraint

var (iS_Rotation_PostProcess) float PostProcessVect; //Multiplier
var (iS_Rotation_PostProcess) float PostProcessRot; //Multiplier
var (iS_Rotation_PostProcess) vector PostProcessVectAxis; //Multiplier per axis
var (iS_Rotation_PostProcess) rotator PostProcessRotAxis; //Multiplier per axis
FT_SpawnerNega is same to FT_Spawner with PostProcessVect=-1 aka Facing away from the Spawner
Last edited by Chaos13 on Sat Aug 30, 2008 12:22 pm, edited 1 time in total.
Skydev = Chaos13 = Dimension4
User avatar
LOL_PEANUTS
OldUnreal Member
Posts: 11
Joined: Wed Mar 14, 2007 7:17 pm

Re: Simple actor spawner? [WRITTEN]

Post by LOL_PEANUTS »

SOLVED! Well, about a year and a half after writing this request, I'm able to write the code. Rather pathetic how long it took me. I have a lot that needs to be done around here— work, education, film, etc., so I only put forth effort into learning more about UScript a couple hours every few months.

[img]http://i39.tinypic.com/141jbrm.jpg[/img]
The peanuts spawner, v0.9.

It works very well. So far I've had lots of fun making subclass spawners that have settings for groups of SkaarjTroopers of various class clusters, I've also made a "Deathtrap," which is a subclass with settings to create a bunch of razorjack blades that constrict whoever is unfortunate enough to be in the middle of them. The latter isn't really useful for level creation, but still has some sort of use for ridiculous servers.

There's still one thing I want to implement, but nothing that can't be done in a few minutes.

In properties variables:
Actor[8]: Eight actor slots.
ActorProbability[8]: Chance that the corresponding actor will be spawned, from 0 to 1. All of the values in the ActorProbability array must add up to 1.
ActorsToSpawn: Number of times the spawner will try and create an actor. If something is in the way, there will be one less actor in the cluster.
ActorTag: Tag of the actors spawned.
DetermineDirectionVia: Determines the method by which the actors created by the spawner will be rotated.
FACE_Direction: Actors face a specific direction specified by the direction which the spawner faces.
FACE_Center: Actors face the spawner.
FACE_Away: Actors face away from the spawner.
FACE_Random: Each actor will face a random direction.
DistanceToCenterMin(and Max): The donut in which the actors will spawn. Uses deathpax's brilliant mathematical concept that evens the distribution.
MaxHeightDeviation: The height of the donut spawn field.
FacingDeviation: The randomness of the direction a spawned actor will face, in Unreal rotation units (an integer between 0 and 65535. an example value, 16384, would mean that within 90 degree field of randomness centered about the direction in which the actor should face according to DetermineDirectionVia, the rotation value of each actor spawned would exist). I do agree that in makes FACE_Random unnecessary, but I haven't removed it yet.

Coming soon in v1.0:
ArcRadius: The.... let me just describe all of these spawn zone parameters visually:

[img]http://i44.tinypic.com/2rzvvnr.png[/img]
A: DistanceToCenterMax
B: DistanceToCenterMin
C: MaxHeightDeviation
D: ArcRadius
The ArcRadius is centered about the direction the actor is facing, which I depicted badly in the diagram. Yes, I set bDirectional to true.
The actor itself is in the very middle of the cylinder, speaking XY&Z.

The script:

Code: Select all

class PSpawner expands Keypoint;

var() int ActorsToSpawn,FacingDeviation;
var() float DistanceToCenterMin,DistanceToCenterMax,MaxHeightDeviation;
var() class      Actor[8];
var() float ActorProbability[8];
var() const enum EDetermineDirectionVia{
      FACE_Direction,
      FACE_Center,
      FACE_Away,
      FACE_Random
} DetermineDirectionVia;
var() name ActorTag;
var class ActorR;
var float RotToUse;
var rotator DTRot;

function PostBeginPlay()
{
      local int i;
      for(i=0; i
Last edited by LOL_PEANUTS on Mon Feb 09, 2009 2:04 am, edited 1 time in total.

Return to “UScript Board”