So in the end I decided just to copy the BeginPlay from the RandomSpawner class and just modify it from there, seems to work well again.
Code: Select all
class CVARRandomSpawner : RandomSpawner
{
override void BeginPlay()
{
DropItem di; // di will be our drop item list iterator
DropItem drop; // while drop stays as the reference point.
int n = 0;
bool nomonsters = sv_nomonsters || level.nomonsters;
//Super.BeginPlay();
drop = di = GetDropItems();
if (di != null)
{
while (di != null)
{
if (di.Name != 'None')
{
if (!nomonsters || !IsMonster(di))
{
int amt = getCVARAmount (di.Amount);
if (amt < 0) amt = 1; // default value is -1, we need a positive value.
n += amt; // this is how we can weight the list.
}
di = di.Next;
}
}
if (n == 0)
{ // Nothing left to spawn. They must have all been monsters, and monsters are disabled.
Destroy();
return;
}
// Then we reset the iterator to the start position...
di = drop;
// Take a random number...
n = random[randomspawn](0, n-1);
// And iterate in the array up to the random number chosen.
while (n > -1 && di != null)
{
if (di.Name != 'None' &&
(!nomonsters || !IsMonster(di)))
{
int amt = getCVARAmount (di.Amount);
if (amt < 0) amt = 1;
n -= amt;
if ((di.Next != null) && (n > -1))
di = di.Next;
else
n = -1;
}
else
{
di = di.Next;
}
}
// So now we can spawn the dropped item.
if (di == null || bouncecount >= MAX_RANDOMSPAWNERS_RECURSION) // Prevents infinite recursions
{
Spawn("Unknown", Pos, NO_REPLACE); // Show that there's a problem.
Destroy();
return;
}
else if (random[randomspawn]() <= di.Probability) // prob 255 = always spawn, prob 0 = almost never spawn.
{
// Handle replacement here so as to get the proper speed and flags for missiles
Class<Actor> cls = di.Name;
if (cls != null)
{
Class<Actor> rep = GetReplacement(cls);
if (rep != null)
{
cls = rep;
}
}
if (cls != null)
{
Species = Name(cls);
readonly<Actor> defmobj = GetDefaultByType(cls);
Speed = defmobj.Speed;
bMissile |= defmobj.bMissile;
bSeekerMissile |= defmobj.bSeekerMissile;
bSpectral |= defmobj.bSpectral;
}
else
{
A_Log(TEXTCOLOR_RED .. "Unknown item class ".. di.Name .." to drop from a cvar random spawner\n");
Species = 'None';
}
}
}
}
int getCVARAmount (int amt)
{
int cvarAmountMin = 15;
int cvarAmountMax = 19;
string cvarAmountMap[20];
cvarAmountMap[15] = 'spawners_nephrite';
cvarAmountMap[16] = 'spawners_doom';
cvarAmountMap[17] = 'spawners_heretic';
cvarAmountMap[18] = 'spawners_hexen';
cvarAmountMap[19] = 'spawners_blood';
if (amt >= cvarAmountMin && amt <= cvarAmountMax)
{
CVar amountCvar = CVar.FindCVar(cvarAmountMap[amt]);
amt = amountCvar.GetInt();
}
return amt;
}
}
I suppose I should look into adding my own struct or something which can hold more information rather than using the amount as a hack, but this works for now!