as I've posted about before, I'm in the process of creating a compatibility layer mod for doom and chex quest. in that mod, I have set up a cvar called ChexWeapReplace, which is used to determine whether to force spawned weapons to be the doom classes or the chex classes. the values are 0 (off, weapons are left alone), 1 (doom, weapons are forced to be doom), and 2 (chex, weapons are forced to be chex quest).
I also have implemented a custom playerclass which can use both the doom and chex quest weapons. I've already set up lump filtering for it to determine which game's weapons it should start with by default, but I want to be able to change that (i.e. swap the starting pistol for a minizorcher or vice versa) depending on what ChexWeapReplace is set to.
ideally, this switch happens only when starting a new game. I don't want this to modify the player's inventory between maploads in a campaign.
is this possible? how would it be done?
is it possible to change playerclass starting weapons with a cvar?
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!)
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!)
-
aeonlight
- Posts: 29
- Joined: Sat May 20, 2023 6:43 pm
- Preferred Pronouns: They/Them
-
m8f
-

- Posts: 1522
- Joined: Fri Dec 29, 2017 4:15 am
- Preferred Pronouns: He/Him
- Location: Siberia (UTC+7)
Re: is it possible to change playerclass starting weapons with a cvar?
It may be possible to create a custom class for a ListMenu (see here: https://zdoom.org/w/index.php?title=MEN ... structions ).
But it seems it would be much simpler to create three derived player classes from your custom playerclass, and make those three new player classes behave as if ChexWeapReplace was set correspondingly. Then, instead of setting an option before starting a game, a player will select a player class.
But it seems it would be much simpler to create three derived player classes from your custom playerclass, and make those three new player classes behave as if ChexWeapReplace was set correspondingly. Then, instead of setting an option before starting a game, a player will select a player class.
-
aeonlight
- Posts: 29
- Joined: Sat May 20, 2023 6:43 pm
- Preferred Pronouns: They/Them
Re: is it possible to change playerclass starting weapons with a cvar?
a player class selection menu is exactly what I'm trying to avoid, in order to keep the player-facing aspects of my mod as simple and unobtrusive as possible. it would be much easier for me to code player class variations and have the player select them manually, yes, but my intention with the custom player class to begin with is to simply replace the default player class with one that can use weapons from both doom and chex quest. adding class selection only serves to unnecessarily complicate the player experience, especially when all the classes do effectively the same thing.
I'd be happy to complicate the code behind the scenes to achieve this player-facing simplification, though - if switching a single player class's weapons via cvar is impossible, switching between duplicate player classes depending on the cvar's setting is a good solution as well, so long as I can prevent the class menu on new game from showing up in my mod but not prevent it for any mods loaded after mine.
I'd be happy to complicate the code behind the scenes to achieve this player-facing simplification, though - if switching a single player class's weapons via cvar is impossible, switching between duplicate player classes depending on the cvar's setting is a good solution as well, so long as I can prevent the class menu on new game from showing up in my mod but not prevent it for any mods loaded after mine.
-
jpalomo
- Posts: 776
- Joined: Mon May 17, 2010 9:45 am
- Operating System Version (Optional): Nobara Linux 43 KDE
- Graphics Processor: nVidia with Vulkan support
Re: is it possible to change playerclass starting weapons with a cvar?
In that case, you may want to look into the GiveDefaultInventory function for playerpawns.
-
aeonlight
- Posts: 29
- Joined: Sat May 20, 2023 6:43 pm
- Preferred Pronouns: They/Them
Re: is it possible to change playerclass starting weapons with a cvar?
the name certainly sounds promising - I'll give that a look as soon as possible, thank you
-
aeonlight
- Posts: 29
- Joined: Sat May 20, 2023 6:43 pm
- Preferred Pronouns: They/Them
Re: is it possible to change playerclass starting weapons with a cvar?
after experimenting some, I can't say for certain whether this will work for me or not. it certainly looks promising, but I lack the technical knowledge to understand and implement it within my zscript code. I'll keep trying, and any additional resources or functional explanations would be appreciated, but for the purposes of the mod I want to use this in, I'm marking this inclusion as low priority and will push for initial release with just lump filtering. thank you for your help!jpalomo wrote: Sat Apr 25, 2026 7:13 am In that case, you may want to look into the GiveDefaultInventory function for playerpawns.
-
jpalomo
- Posts: 776
- Joined: Mon May 17, 2010 9:45 am
- Operating System Version (Optional): Nobara Linux 43 KDE
- Graphics Processor: nVidia with Vulkan support
Re: is it possible to change playerclass starting weapons with a cvar?
As an example of how I've used it in a personal mod.
In the player class:
In the thinker class:
This allows the player to manually set the starting weapon and ammo type, or let it pick a random one. I had tried using RandomSpawners initially but found they don't really work with the Player.StartItem property.
In the player class:
Code: Select all
Override void GiveDefaultInventory ()
{
let player = self.player;
if (player == NULL) return;
Super.GiveDefaultInventory ();
// Give us a starter weapon
JPWeapons_Thinker weap;
weap = JPWeapons_Thinker.Get();
if (weap)
{
Class<Weapon> weap0n = weap.JP_GetReplacementWeapon(0); // Get the weapon class name
GiveInventory (weap0n, 1, false); // Give us the weapon
let swapWeapon = Weapon(FindInventory(weap0n)); // Find the weapon we just got
player.PendingWeapon = swapWeapon; // swap to it
}
}Code: Select all
class JPWeapons_Thinker : Thinker
{
Name StarterSlot;
JPWeapons_Thinker Init()
{
CVar spawnerbehavior = CVar.FindCVar('jp_weapons_spawners');
...
StarterSlot = StarterClasses[jp_weapons_weapon_starterweapon.GetInt()];
...
}
static JPWeapons_Thinker Get()
{
ThinkerIterator it = ThinkerIterator.Create("JPWeapons_Thinker",STAT_STATIC);
let p = JPWeapons_Thinker(it.Next());
if (p == null)
{
p = new("JPWeapons_Thinker").Init();
}
return p;
}
static Name JP_GetReplacementWeapon(int slot)
{
let weaponslot = JPWeapons_Thinker.Get();
if (weaponslot)
{
Switch (slot)
{
Case 0:
return weaponslot.StarterSlot;
...
}
}
return 'None';
}
}