Different monster spawn each map

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Pandut
Posts: 231
Joined: Tue Mar 23, 2010 4:47 pm
Preferred Pronouns: No Preference
Graphics Processor: nVidia with Vulkan support
Location: existential dread

Different monster spawn each map

Post by Pandut »

Issue is simple; I have 3 enemies that take the role of the standard DoomImp. I do not want to use a RandomSpawner because each monster has a different aesthetic and wouldn't mesh super well. My question is; how do I go about creating a system where each map it randomly chooses 1 of 3 of these monsters to replace the DoomImp per map? Can I do this in Decorate or would it require ZScript/ACS?

I've looked around but can't seem to find anything relation, nor any examples I could reference. Any help would be appreciateddd.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Different monster spawn each map

Post by Matt »

Might something like this work?

MAPINFO

Code: Select all

gameinfo{
    addeventhandlers="ImpRambler"
}
ZScript

Code: Select all

version "3.4" //added after OP reported the error below

class ImpRambler:EventHandler{
    override void WorldLoaded(WorldEvent e){
        int which=random(0,2);
        thinkeriterator impreplacer=thinkeriterator.create("doomimp");
        actor imppp=null;
        array<actor>impppdelend;
        while(imppp=actor(impreplacer.next())){
            class<actor> notimp="chaingunguy";
            if(which==1) notimp="lostsoul";
            else if(which==2) notimp="explosivebarrel";
            imppp.spawn(notimp,imppp.pos);
            impppdelend.push(imppp);
        }
        while(impppdelend.size()>0){
            impppdelend[0].destroy();
            impppdelend.delete(0);
        }
    }
}
Last edited by Matt on Wed Jun 13, 2018 2:10 pm, edited 1 time in total.
User avatar
Pandut
Posts: 231
Joined: Tue Mar 23, 2010 4:47 pm
Preferred Pronouns: No Preference
Graphics Processor: nVidia with Vulkan support
Location: existential dread

Re: Different monster spawn each map

Post by Pandut »

I've barely if not 0 experience with Zscript, tried to implement it but ended up with these errors;

Code: Select all

1Pan-ZRift.pk3:zscriptu/impspawn.zsc, line 1: Parent class EventHandler of ImpRambler not accessible to ZScript version 2.3.0
1Pan-ZRift.pk3:zscriptu/impspawn.zsc, line 3: Type WorldEvent not accessible to ZScript version 2.3.0
1Pan-ZRift.pk3:zscriptu/impspawn.zsc, line 3: Invalid type Type for function parameter
1Pan-ZRift.pk3:zscriptu/impspawn.zsc, line 3: Attempt to override non-existent virtual function WorldLoaded
It's likely I did something wrong, haha.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Different monster spawn each map

Post by Matt »

Sorry, I never remember to add the version number to the start of the ZScript file:

Code: Select all

version "3.4"
User avatar
Pandut
Posts: 231
Joined: Tue Mar 23, 2010 4:47 pm
Preferred Pronouns: No Preference
Graphics Processor: nVidia with Vulkan support
Location: existential dread

Re: Different monster spawn each map

Post by Pandut »

Yep! It works now, thank you so much!

Return to “Scripting”