An unusual random spawner problem

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

An unusual random spawner problem

Post by krokots »

Couple of years ago (2 I think) i made a small mod for myself, which randomized monsters, but not in a typical shuffle way. It made all monsters of particular class change to something else (example: all imps would be changed to shadows for all gameplay), and restarting game would change the imp class to something else. Now, when i run it on new zdoom, it doesn't work (monsters don't show up - they change to nothing at all). So i recreated a small part of it, to check what is wrong. But i don't see (yet?). I'm a "sunday" coder i would say, as i mod games once in a blue moon, so the code possibly looks like poo.

OK, this in theory change all imps to: 50% imps, or 50% agauri. But it doesnt (no imps show up). Why?

Decorate:

Code: Select all

actor DoomImpClassic : DoomImp {}


actor DoomImpReplacer replaces DoomImp
{
states
{
Spawn:
	TNT1 A 0
        TNT1 A 0 A_JumpIf(1 == (ACS_ExecuteWithResult(802,0,0,0)), "SpClassicI")
        TNT1 A 0 A_JumpIf(2 == (ACS_ExecuteWithResult(802,0,0,0)), "SpAgaures")
        TNT1 A 0   
	stop
SpClassicI: 
        TNT1 A 0
	TNT1 A 0 A_SpawnItemEx("DoomImpClassic")
	stop
SpAgaures: 
        TNT1 A 0
	TNT1 A 0 A_SpawnItemEx("Agaures")
	stop
}
}
ACS

Code: Select all

#library "SCR" // Name of the library
#include "zcommon.acs"

// ####################################################################
global int 1:imp;

// ####################################################################

script 800 (void) 
{
print(s:"\cdimp is " , d: imp);
}

// ####################################################################

script 801 ENTER
{
if (imp == 0)

   {
   imp = (random(1,2));
   }
}

script 802 (void) 
{
    SetResultValue(imp);
}
When it worked, there was a bug where all monsters in the level were instantly alerted, so still it was shit. But whatever, i'll try to recreate it without bugs.
Help me see where what's wrong with it.
User avatar
Galaxy_Stranger
Posts: 1326
Joined: Sat Aug 16, 2003 11:42 pm
Location: Shropshire
Contact:

Re: An unusual random spawner problem

Post by Galaxy_Stranger »

Doesn't quite make sense to me what you're trying to accomplish. Make a bulleted list of what you want it to do in English words.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: An unusual random spawner problem

Post by krokots »

In theory, it's simple.
- ACS: when you start a new game, first script generate random number, let it be 1 or 2 for example (each number represent a different monster), second script return the generated number.
- Decorate: monster is replaced with a spawner. At spawn, it have a chance to go to state 1 or 2, depending on result from the second script
- Different states spawn different monsters (via SpawnItemEx)

The most important thing, is that every monster class is completely replaced with another similar random monster. So, all imps in first gameplay will be devils. All barons - changed to archons of hell, etc.
User avatar
phantombeta
Posts: 2175
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: An unusual random spawner problem

Post by phantombeta »

'2 == (ACS_ExecuteWithResult(802,0,0,0))'
Shouldn't it be 'ACS_ExecuteWithResult(802,0,0,0) == 2' ?
It should also be an OPEN script instead of an ENTER script.
And 'global int 1:imp;' can be changed to 'int imp;'
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: An unusual random spawner problem

Post by Fishytza »

If I had to guess, I'd say that script 802 is run before the ENTER (801) script. Could be completely, utterly wrong, though.

At any case, why rely on OPEN or ENTER scripts? Why not put it into one script so that there's no uncertainty about which script comes before? Since it's important that the choice is made before any result is returned, right?

eg:

Code: Select all

Script 802 (void)
{
    if( imp == 0 )
        imp = random(1, 2);

    SetResultValue(imp);
}
In case you're wondering, no, this wouldn't make the script 'slower'.

EDIT:
phantombeta wrote:And 'global int 1:imp;' can be changed to 'int imp;'
Not if he wants it to last for the entire playthrough, and not just a single map.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: An unusual random spawner problem

Post by krokots »

FishyClockwork wrote:If I had to guess, I'd say that script 802 is run before the ENTER (801) script. Could be completely, utterly wrong, though.

At any case, why rely on OPEN or ENTER scripts? Why not put it into one script so that there's no uncertainty about which script comes before? Since it's important that the choice is made before any result is returned, right?

eg:

Code: Select all

Script 802 (void)
{
    if( imp == 0 )
        imp = random(1, 2);

    SetResultValue(imp);
}
In case you're wondering, no, this wouldn't make the script 'slower'.
Nice! This worked. Many thanks!
Locked

Return to “Editing (Archive)”