Page 1 of 1

Universal Shotgun Start [Update 1-4-22]

Posted: Sat Jan 01, 2022 7:05 am
by Hey Doomer
There's been so much done over the years it's hard to know where the new ideas are. For me it's been a matter of looking for something, not quite finding it, and then creating it. So, perhaps, a universal start with a shotgun or whatever replaces the shotgun has already been done. (I've seen starts but nothing that works with any mod.) If you want to start with a "shotgun" in hand, this does it.

Code: Select all

class shotgunstart_EventHandler : EventHandler
{
   override void WorldThingSpawned(WorldEvent e)
   {
      if (e.thing && e.thing is "PlayerPawn")
      {
         bool b;
         Actor ptr;
         [b, ptr] = e.thing.A_SpawnItemEx("Shotgun");

         if (ptr)
         {
            ptr.SetOrigin((0,0,0), false);
            string gun = ptr.GetSpecies();

            if (e.thing.CountInv(gun) == 0)
            {
               e.thing.A_GiveInventory(gun, 1);
               e.thing.A_SelectWeapon(gun);
            }
         }
      }
   }
}


If the shotgun hasn't been replaced, A_GiveInventory("Shotgun") works. The problem, it seems, comes in finding whatever the replacement is to make this mod compatible. I've tried using GetReplacement("Shotgun"), from which I get the class name "shotgunReplacer." Perhaps, there is a way to get the species name from this that's easier than my solution. What I've done is spawn a "Shotgun," move it to location 0,0,0 (A_Remove() can't be called from a static event handler) and get the name from there. This grabs and selects a shotgun or replacement at level start unless there is already one in the inventory.

I suppose using this approach it's possible to get the name of all replacements... just dunno if there's an easier way. :?

Update 1-4-22
Changed (0,0,0) to (-32767, 32767, 0)

Re: Universal Shotgun Start

Posted: Sat Jan 01, 2022 4:19 pm
by Xim
This is awesome. I did a quick test with my mod that has a random spawner replacing the shotgun and it did indeed make me start with one of the random weapons. Good work!

Re: Universal Shotgun Start

Posted: Sat Jan 01, 2022 5:18 pm
by Hey Doomer
Xim wrote:This is awesome. I did a quick test with my mod that has a random spawner replacing the shotgun and it did indeed make me start with one of the random weapons. Good work!


Thanks! That's great! :D

Re: Universal Shotgun Start [Update 1-4-22]

Posted: Tue Jul 19, 2022 1:39 am
by thugsta
Does anyone know what override makes it so it (re)spawns on every map start? Like even if i am now on map18 a shotgun will spawn again at start spawn.