Universal Shotgun Start [Update 1-4-22]

Post your example zscripts/ACS scripts/etc here.

Universal Shotgun Start [Update 1-4-22]

Postby Hey Doomer » Sat Jan 01, 2022 7:05 am

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 allExpand view
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)
Last edited by Hey Doomer on Tue Jan 04, 2022 1:14 pm, edited 1 time in total.
Hey Doomer
 
Joined: 25 Sep 2021

Re: Universal Shotgun Start

Postby Xim » Sat Jan 01, 2022 4:19 pm

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!
User avatar
Xim
 
Joined: 20 Feb 2009
Location: Somewhere with trees

Re: Universal Shotgun Start

Postby Hey Doomer » Sat Jan 01, 2022 5:18 pm

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
Hey Doomer
 
Joined: 25 Sep 2021


Return to Script Library

Who is online

Users browsing this forum: No registered users and 0 guests