Weapon scripting help (zscript)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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!)

Weapon scripting help (zscript)

Postby JamesTheMaker » Tue May 24, 2022 11:50 am

Code: Select allExpand view
// --------------------------------------------------------------------------
//
// Grenade launcher
//
// --------------------------------------------------------------------------

class GrenadeLauncher : FranticWeapon 14167
{
   Default
   {
      Weapon.SelectionOrder 2500;
      Weapon.AmmoUse 1;
      Weapon.AmmoGive 2;
      Weapon.AmmoType "RocketAmmo";
      Weapon.SlotNumber 2;
      +WEAPON.NOAUTOFIRE
      Inventory.PickupMessage "$GOTLAUNCHER";
      Tag "$TAG_ROCKETLAUNCHER";
   }
   States
   {
   Ready:
      MISG A 1 A_WeaponReady;
      Loop;
   Deselect:
      MISG A 1 A_Lower;
      Loop;
   Select:
      MISG A 1 A_Raise;
      Loop;
   Fire:
      MISG B 8 A_GunFlash;
      MISG B 12 A_FireGrenade;
      MISG B 0 A_ReFire;
      Goto Ready;
   Flash:
      MISF A 3 Bright A_Light1;
      MISF B 4 Bright;
      MISF CD 4 Bright A_Light2;
      Goto LightDone;
   Spawn:
      LAUN A -1;
      Stop;
   }
}

class Grenade : Actor
{
   Default
   {
      Radius 11;
      Height 8;
      Speed 50;
      Damage 20;
      Projectile;
      -NOGRAVITY
      +RANDOMIZE
      +DEHEXPLOSION
      +ROCKETTRAIL
      +ZDOOMTRANS
      SeeSound "weapons/rocklf";
      DeathSound "weapons/rocklx";
      Obituary "$OB_MPROCKET";
   }
   States
   {
   Spawn:
      MISL A 1 Bright;
      Loop;
   Death:
      MISL B 8 Bright A_Explode;
      MISL C 6 Bright;
      MISL D 4 Bright;
      Stop;
   BrainExplode:
      MISL BC 10 Bright;
      MISL D 10 A_BrainExplode;
      Stop;
   }
}

//===========================================================================
//
// Code (must be attached to StateProvider)
//
//===========================================================================

extend class StateProvider
{

   //===========================================================================
   //
   // A_FireMissile
   //
   //===========================================================================

   action void A_FireGrenade()
   {
      if (player == null)
      {
         return;
      }
      Weapon weap = player.ReadyWeapon;
      if (weap != null && invoker == weap && stateinfo != null && stateinfo.mStateType == STATE_Psprite)
      {
         if (!weap.DepleteAmmo (weap.bAltFire, true, 1))
            return;
      }
      
      SpawnPlayerMissile ("Grenade");
   }
}


I've followed all the information I can find, yet it still won't work. It doesn't appear in map editors nor can I use the give command to spawn it in. I don't understand what I'm doing wrong.
JamesTheMaker
 
Joined: 24 May 2022
Discord: JamesTheMaker#1358
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Weapon scripting help (zscript)

Postby Ac!d » Tue May 24, 2022 1:22 pm

JamesTheMaker wrote:It doesn't appear in map editors nor can I use the give command to spawn it in.


Adding a editor number after the name of an actor is possible in Decorate. In ZScript however, the best way is to use the Editor number definition in MAPINFO like so :
Code: Select allExpand view
DoomEdNums
{
  14167 = GrenadeLauncher
}


Also,
- The actor "Grenade" is already in GZDoom.pk3, no need to copy it. Else, rename it, indicate that the parent is "Grenade" and remove the state "BrainExplode", which is used for the rocket.
- A_FireGrenade() is already used for the "StrifeGrenadeLauncher" from Strife : Quest for the Sigil. Rename that function.
User avatar
Ac!d
Perfection is a way, not an end. - Korean Proverb
 
Joined: 02 Apr 2019
Location: France
Discord: Ac!d#2732
Operating System: Windows 10/8.1/8 32-bit

Re: Weapon scripting help (zscript)

Postby Player701 » Fri Jun 03, 2022 6:06 am

Ac!d wrote:- A_FireGrenade() is already used for the "StrifeGrenadeLauncher" from Strife : Quest for the Sigil. Rename that function.

The function as defined shouldn't even compile, since extend class StateProvider is not valid in user-supplied ZScript code. It would only work in a modified gzdoom.pk3, but changing its contents is something I'd advise against. Aside from that, A_FireGrenade can be defined directly inside GrenadeLauncher and wouldn't conflict with A_FireGrenade from the Strife grenade launcher because neither of these two classes inherit from each other (directly or indirectly).
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests