Changing thing spawns based on player class?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
salahmander2
Posts: 140
Joined: Wed Nov 19, 2014 7:20 pm

Re: Changing thing spawns based on player class?

Post by salahmander2 »

fakemai wrote: Thu Nov 20, 2025 1:03 pm The important part. If you were to use consoleplayer in my example what'll happen is each player's copy of the game will spawn different items (if different classes at least) and it WILL desync. Even if you don't care about multiplayer there's no sense in doing it that way, it's potential to break as other bad scope interactions have in later versions of GZDoom. It is fine to use consoleplayer in some circumstances, like reading from play to render to the HUD.

Also my example's just as rough and has bugs but it's not my intention to do all the work, only to point to a solution to the problem, and one that at least has the possibility of multiplayer if that's desirable.
Managing to get adjusted to it, only problem I got is the angle, do you know if there is a way for the angle to be maintained? Unfortunately SpawnAngle has no effect and while Angle does, it has the zombiemen all face the exact same direction.
User avatar
salahmander2
Posts: 140
Joined: Wed Nov 19, 2014 7:20 pm

Re: Changing thing spawns based on player class?

Post by salahmander2 »

Been working on another type of method for now, doing it via a mappostprocessor, the change works, but alas I'm looking for a way that sets it by which playerclass is being used, what is the best way for it? This is what I got so far?

class ScalPostProcessor : LevelPostProcessor
{
protected void Apply(Name checksum, String mapname)
{

if ("PlayerClassNum" == 0)
{
for (uint i = 0; i < GetThingCount(); i++)
{
int ednum = GetThingEdNum(i);
if(ednum == 2012) //Baron
{
SetThingEdNum(i, 31102); //Knight
}
}
}
}
}
User avatar
stainedofmind
Posts: 273
Joined: Sun Sep 01, 2019 10:59 am

Re: Changing thing spawns based on player class?

Post by stainedofmind »

fakemai wrote: Thu Nov 20, 2025 1:03 pm The important part. If you were to use consoleplayer in my example what'll happen is each player's copy of the game will spawn different items (if different classes at least) and it WILL desync. Even if you don't care about multiplayer there's no sense in doing it that way, it's potential to break as other bad scope interactions have in later versions of GZDoom. It is fine to use consoleplayer in some circumstances, like reading from play to render to the HUD.

Also my example's just as rough and has bugs but it's not my intention to do all the work, only to point to a solution to the problem, and one that at least has the possibility of multiplayer if that's desirable.
Thanks for the info. I've definitely been misusing consoleplayer in my mods. I'll have to reevaluate how I'm doing things when I get a moment.
User avatar
fakemai
Posts: 419
Joined: Mon Feb 12, 2018 12:26 am
Location: Australia

Re: Changing thing spawns based on player class?

Post by fakemai »

I'd actually considered if it was possible to leverage the feature that exists in UDMF and to a lesser extent Hexen maps of spawn flags by class, but I don't think LevelPostProcessor can change any of those things, and it would not cover items that are spawned or dropped during a map anyway. There is also the option of using an eventhandler to override WorldThingSpawned, or CheckReplacement, but the option I provided is probably the simplest For the angle setting, can't you just assign it like I did with the test of setting the velocity except with the spawner's actor Like m.angle = self.angle; or something? Again, check the link to RandomSpawner's ZScript, it copies a LOT of stuff in that fashion when it's spawning its chosen actor. Actually, if you don't care about multiplayer, you could just make a new subclass of RandomSpawner and override its ChooseSpawn virtual with the kind of logic in my example. Then you'd get all of the special cases for free without having to rewrite it. Fair warning, nothing is ever simple.
User avatar
salahmander2
Posts: 140
Joined: Wed Nov 19, 2014 7:20 pm

Re: Changing thing spawns based on player class?

Post by salahmander2 »

Oh, I dunno what I did wrong when it came to self.angle, but it's working now! Cheers man.

Return to “Scripting”