yum13241 wrote: ↑Thu Sep 05, 2024 9:13 am
Try this:
Thanks very much

Sorry for the late reply, had to stop working on my project for a while; the following is the end result.
Unlike the game itself, it doesn't select the weapon immediately if given at the console; however, I personally prefer it not to and cheat codes are only meant for testing purposes anyway.
Note that for the purposes of starting the game, the pistol must be checked after the fist; otherwise, the fist gets selected. I can find no reason for this, but when one is coding this deep inside the engine, one must expect timing sequence dependencies under the hood to get in the way sometimes.
Code: Select all
// --- STOCK WEAPONS REPLACER --------------------------------------------------
// This event handler replaces the stock weapons in Doom with their enhanced
// replacements from the pack.
// To use it, cite it in the Gameinfo section of a Mapinfo script; for example:
//
// gameinfo
// {
// AddEventHandlers = "M426_StockWeapons_Replacer"
// }
// Credit: Nash Muhandes (ZDoom forums) for the original
// Credit: yum13241 (ZDoom forums) for initial generalsisation work
class M426_StockWeapons_Replacer : EventHandler
{
// Replace when spawned in the world
override void CheckReplacement(ReplaceEvent e)
{
e.IsFinal = false;
if (e.Replacee == "Fist" ) { e.Replacement = "Fistt"; return; }
if (e.Replacee == "Chainsaw") { e.Replacement = "Chainsaww"; return; }
if (e.Replacee == "Pistol" ) { e.Replacement = "Pistoll"; return; }
if (e.Replacee == "Shotgun" ) { e.Replacement = "Shotgunn"; return; }
if (e.Replacee == "SuperShotgun" ) { e.Replacement = "Coachgun"; return; }
if (e.Replacee == "Chaingun" ) { e.Replacement = "Chaingunn"; return; }
if (e.Replacee == "RocketLauncher" ) { e.Replacement = "RocketLauncherr"; return; }
if (e.Replacee == "PlasmaRifle" ) { e.Replacement = "PlasmaRiflle"; return; }
if (e.Replacee == "BFG9000" ) { e.Replacement = "BFGG9000"; return; }
}
// Replace after player enters the game
override void PlayerEntered(PlayerEvent e)
{
PlayerPawn pmo = players[e.PlayerNumber].mo;
if (!pmo) return;
SwapWeapons(pmo);
}
// Replace after player respawns in the map
override void PlayerRespawned(PlayerEvent e)
{
PlayerPawn pmo = players[e.PlayerNumber].mo;
if (!pmo) return;
SwapWeapons(pmo);
}
// Replace when given to the player
override void WorldTick(void)
{
for (int i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i])
{
let pmo = players[i].mo;
if (pmo && pmo.Health > 0)
{
SwapWeapons(pmo);
}
}
}
}
// ==========================================================================
void SwapWeapon(
PlayerPawn pmo,
class<Weapon> replacee,
class<Weapon> replacement,
class<Ammo> ammoType = null,
int ammoCount = 0)
{
// If not found then nothing to do
if (!pmo.FindInventory(replacee))
return;
// Remember which weapon is
// currently being wielded.
let oldWeapon = pmo.player.ReadyWeapon;
// Replace the weapon and any ammo it gives
pmo.TakeInventory(replacee, MAX_INT);
if (ammoType)
{
pmo.TakeInventory(ammoType, ammoCount);
}
pmo.GiveInventory(replacement, 1);
// If no weapon was being wielded
// then select the new weapon now.
if (oldWeapon == null)
{
// We want the Weapon actor flags
let defaults = GetDefaultByType(replacement);
// If no auto switch then do nothing
if (defaults.bNO_AUTO_SWITCH)
return;
// If out of ammo and no auto switch
// on acquiring some then do nothing.
let ammoCount = pmo.CountInv(defaults.AmmoType1) - defaults.AmmoGive1;
if (ammoCount <= 0 && defaults.bNOAUTOSWITCHTO)
return;
// OK to proceed with selection
pmo.A_SelectWeapon(replacement);
return;
}
// If the old weapon was replaced
// then select the new one instead;
// otherwise, reselect the old one.
if (oldWeapon == null || replacee == oldWeapon.GetClass())
{
pmo.A_SelectWeapon(replacement);
}
else // (replacee != oldWeapon.GetClass())
{
pmo.A_SelectWeapon(oldWeapon.GetClass());
}
}
// =========================================================================
void SwapWeapons(PlayerPawn pmo)
{
SwapWeapon(pmo, "Fist", "Fistt");
SwapWeapon(pmo, "Chainsaw", "Chainsaww");
SwapWeapon(pmo, "Pistol", "Pistoll", "Clip", 20);
SwapWeapon(pmo, "SuperShotgun", "Coachgun", "Shell", 8);
SwapWeapon(pmo, "Chaingun", "Chaingunn", "Clip", 20);
SwapWeapon(pmo, "RocketLauncher", "RocketLauncherr", "RocketAmmo", 2);
SwapWeapon(pmo, "PlasmaRifle", "PlasmaRiflle", "Cell", 40);
SwapWeapon(pmo, "BFG9000", "BFGG9000", "Cell", 40);
}
// =========================================================================
}