[SOLVED] Weird spawning issue

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Guardsoul
Forum Regular
Posts: 495
Joined: Wed Jun 06, 2012 6:09 pm
Location: Creating the world

[SOLVED] Weird spawning issue

#1

Post by Guardsoul » Thu Jun 19, 2014 5:41 pm

Hi there guys, I´ve been working in a spawning system for one of my maps that is similar to the stronghold one but I have detected a small problem.

Everything works fine until I reach wave 4 where it is supposed to spawn 5 imps, 5 shotgun guys and 20 spectres. The shotgunners and the imps spawn correctly but only spawns about 9-10 spectres and I dont know what is wrong in the code.

Code: Select all

Script 3 (int wave)
{
    switch(wave)
    {
        case 1:
            Monsters[0] = 15;
            break;
        case 2:
            Monsters[0] = 15;
            Monsters[1] = 10;
            Monsters[2] = 10;
            break;
        case 3:
            Monsters[2] = 15;
            Monsters[3] = 8;
            Monsters[4] = 8;
            break;
        case 4:
	        Monsters[1] = 5;
	        Monsters[2] = 5;
            Monsters[4] = 20;
            break;
        case 5:
            Monsters[2] = 10;
            Monsters[3] = 10;
            Monsters[4] = 10;
            Monsters[5] = 10;
            break;
    }
    int angle = GetActorAngle(1) >> 8;
    while(getAmount()>0)
    {
        int i = random(0,5);
        if(Monsters[i]>0)
        {
            Monsters[i]--;
            While(!Spawn(MonsterType[i],getCoords(1),getCoords(2),getCoords(3),100,angle))
            {
                Delay(1);
            }
            Delay(1);
            SpawnSpot("DoomTeleFog",100);
            Thing_ChangeTID(100,0);
            Delay(17);
        }
    }
    while((ThingCountName("TestZombieman",0) + ThingCountName("TestShotgunGuy",0) + ThingCountName("TestDoomImp",0) + ThingCountName("TestDemon",0) + ThingCountName("TestSpectre",0) + ThingCountName("TestCacodemon",0))>0)
    {
        Delay(1);
    }
	int next = wave;
	next++;
    ACS_Execute(2,0,next,0,0);
}
Regards.
Last edited by Guardsoul on Fri Jun 20, 2014 5:20 am, edited 1 time in total.
I dont care about how bad your maps are. Everything can be improved.
Banned for cheating at DoomBuilder.

User avatar
CloudFlash
Zandrone
Posts: 1074
Joined: Mon Jun 04, 2012 5:35 pm
Location: Wonderland (except not really)

RE: Weird spawning issue

#2

Post by CloudFlash » Thu Jun 19, 2014 7:12 pm

It might be a bit far-fetched, but maybe try replacing

Code: Select all

            Monsters[4] = 20;
            break;
With

Code: Select all

            Monsters[4] = 10;
            Monsters[4] = 10;
            break;
This is the only thing I can think of, see if that works :V
https://i.imgflip.com/i5tpe.jpg
*Hey, who wants to hear my solution to the modern world's problems? ^Me! %Me! @Me! #Me! *WELL TOO BAD @Did he just stab himself with this butcher knife? %Looks like it ^Hey, the pizza guy arrived! %Pizza! Yey

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: Weird spawning issue

#3

Post by Ijon Tichy » Thu Jun 19, 2014 7:24 pm

CloudFlash wrote: It might be a bit far-fetched, but maybe try replacing

Code: Select all

            Monsters[4] = 20;
            break;
With

Code: Select all

            Monsters[4] = 10;
            Monsters[4] = 10;
            break;
This is the only thing I can think of, see if that works :V
what devil-spawned illogic created this


@OP:
what index in monsters means what, and what is getAmount()
basically, pastebin the entire script
Last edited by Ijon Tichy on Thu Jun 19, 2014 7:24 pm, edited 1 time in total.

User avatar
Guardsoul
Forum Regular
Posts: 495
Joined: Wed Jun 06, 2012 6:09 pm
Location: Creating the world

RE: Weird spawning issue

#4

Post by Guardsoul » Thu Jun 19, 2014 7:32 pm

I dont care about how bad your maps are. Everything can be improved.
Banned for cheating at DoomBuilder.

User avatar
CloudFlash
Zandrone
Posts: 1074
Joined: Mon Jun 04, 2012 5:35 pm
Location: Wonderland (except not really)

RE: Weird spawning issue

#5

Post by CloudFlash » Thu Jun 19, 2014 7:46 pm

Ijon Tichy wrote: what devil-spawned illogic created this
Well, you see...
I assumed that this script is meant for Zandronum. This will be very important later.
I also assumed that everything in this code is right, except for that one line at wave 4. This would include the line in wave 5, in which he spawns exact same type of monster by the exact same spawner and it works properly, which might -or might not- indicate that the problem doesn't lie with the spawner itself.
Then, I glanced at the numbers. Turns out, the broken line contains the highest number.
Second later, I recalled that this is supposed to work for Zanzan. So that got me thinking, 'if Zanzan has problem with the spawner which is supposed to spawn 20 monsters, but doesn't give crap about exact same spawner when it has to spawn 10 monsters, then why not make 20 into 2 x 10'.
And then I wrote this post and became the king of this place, wow.
I will laugh like a maniac hyena if the solution turns out to be exactly this.[/size]
Last edited by CloudFlash on Thu Jun 19, 2014 7:47 pm, edited 1 time in total.
https://i.imgflip.com/i5tpe.jpg
*Hey, who wants to hear my solution to the modern world's problems? ^Me! %Me! @Me! #Me! *WELL TOO BAD @Did he just stab himself with this butcher knife? %Looks like it ^Hey, the pizza guy arrived! %Pizza! Yey

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: Weird spawning issue

#6

Post by Ijon Tichy » Thu Jun 19, 2014 8:00 pm

CloudFlash wrote: I will laugh like a maniac hyena if the solution turns out to be exactly this.
last I checked setting the same value to 10 twice did not magically make it 20.

and guess what, it wasn't, and it was in a part of the code you weren't given at first
the issue was that the function that counted how many monsters needed to spawn never went past index 2.
it was a user error entirely, and could've been very easily avoided with some smart constant usage.

this is completely untested but I see no reason it shouldn't work (missing script 2 and the message function since it's irrelevant to the bug)

Code: Select all

#include "zcommon.acs"

#define MONCOUNT 6

#define M_ZOMBIE    0
#define M_SHOTGUY   1
#define M_IMP       2
#define M_DEMON     3
#define M_SPECTRE   4
#define M_CACO      5

int Monsters[MONCOUNT];

str MonsterType[MONCOUNT] =
{
    "TestZombieman",
    "TestShotgunGuy",
    "TestDoomImp",
    "TestDemon",
    "TestSpectre",
    "TestCacodemon",
};

script 3 (int wave)
{
    int i;

    // should be unnecessary, but zero out monsters array just in case
    for (i = 0; i < MONCOUNT; i++)
    {
        Monsters[i] = 0;
    }

    switch(wave)
    {
      case 1:
        Monsters[M_ZOMBIE] = 15;
        break;

      case 2:
        Monsters[M_ZOMBIE]  = 15;
        Monsters[M_SHOTGUY] = 10;
        Monsters[M_IMP]     = 10;
        break;

      case 3:
        Monsters[M_IMP]     = 15;
        Monsters[M_DEMON]   = 8;
        Monsters[M_SPECTRE] = 8;
        break;

      case 4:
        Monsters[M_SHOTGUY] = 5;
        Monsters[M_IMP]     = 5;
        Monsters[M_SPECTRE] = 20;
        break;

      case 5:
        Monsters[M_IMP]     = 10;
        Monsters[M_DEMON]   = 10;
        Monsters[M_SPECTRE] = 10;
        Monsters[M_CACO]    = 10;
        break;
    }

    int angle = GetActorAngle(1) >> 8;

    while (monstersLeft() > 0)
    {
        i = random(0,5);
        if (Monsters[i] > 0)
        {
            Monsters[i]--;
            str mon = MonsterType[i];

            while (1)
            {
                int x = spawnCoords(1);
                int y = spawnCoords(2);
                int z = spawnCoords(3);
                
                if (Spawn(mon, x, y, z, 0, angle))
                {
                    Spawn("DoomTelefog", x, y, z);
                    Delay(18);
                    break;
                }

                Delay(1);
            }
        }
    }

    while (mapMonsterCount() > 0)
    {
        Delay(1);
    }

    ACS_Execute(2, 0, wave + 1);
}

function int monstersLeft(void)
{
    int i, res = 0;

    for (i = 0; i < MONCOUNT; i++)
    {
        res += Monsters[i];
    }

    return res;
}

function int mapMonsterCount(void)
{
    int i, ret = 0;

    for (i = 0; i < MONCOUNT; i++)
    {
        ret += ThingCountName(MonsterType[i], 0);
    }

    return ret;
}

function int spawnCoords(int which)
{
    int low, high;

    switch (which)
    {
      case 1:
        low  = GetActorX(1);
        high = GetActorX(2);
        break;

      case 2:
        low  = GetActorY(1);
        high = GetActorY(2);
        break;

      case 3:
        low  = GetActorZ(1);
        high = GetActorZ(2);
        break;
    }

    // XOR swap
    if (low > high) { low ^= high; high ^= low; low ^= high; }
    return random(low, high);
}
btw you're still fucking retarded and should never be allowed near a compiler
Last edited by Ijon Tichy on Thu Jun 19, 2014 8:16 pm, edited 1 time in total.

User avatar
Guardsoul
Forum Regular
Posts: 495
Joined: Wed Jun 06, 2012 6:09 pm
Location: Creating the world

RE: Weird spawning issue

#7

Post by Guardsoul » Fri Jun 20, 2014 5:20 am

OUCH, I forgot to change the function when I increased the amount of monsters it could spawn. I should have used constants for that. Thanks!
I dont care about how bad your maps are. Everything can be improved.
Banned for cheating at DoomBuilder.

Post Reply