Modding:Missile Weapons: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
imported>CaptainTechnicality54384
(Created page with "Category:Modding =Custom Ammo Types= Custom moddable ammo types are supported without adding a new Ammo class to the game via AmmoGeneric, check out the "12 Gauge Shotgun...")
 
m (Egocarib moved page Modding:Ranged Weapons to Modding:Missile Weapons: Match the name used in game for this type of thing)
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Modding]]
[[Category:Modding]]{{Modding Info}}
=Custom Ammo Types=
=Custom Ammo Types=


Custom moddable ammo types are supported without adding a new Ammo class to the game via AmmoGeneric, check out the "12 Gauge Shotgun" for an example of use.
Custom moddable ammo types are supported without adding a new Ammo class to the game via AmmoGeneric, check out the "12 Gauge Shotgun" for an example of use.


<syntaxhighlight lang="xml">
   <object Name="12 Gauge Shotgun" Inherits="BaseMagazineRifle">
   <object Name="12 Gauge Shotgun" Inherits="BaseMagazineRifle">
     <part Name="Render" DisplayName="12 gauge shotgun" RenderString=")"></part>
     <part Name="Render" DisplayName="12 gauge shotgun" RenderString=")"></part>
Line 10: Line 11:
     <part Name="MissileWeapon" Skill="Rifle" NoWildfire="true" NoAmmoProjectile="Ammo12Gauge" ShotsPerAction="8" AmmoPerAction="1" ShotsPerAnimation="8" WeaponAccuracy="35" RangeIncrement="6"></part>
     <part Name="MissileWeapon" Skill="Rifle" NoWildfire="true" NoAmmoProjectile="Ammo12Gauge" ShotsPerAction="8" AmmoPerAction="1" ShotsPerAnimation="8" WeaponAccuracy="35" RangeIncrement="6"></part>
   
   
<!-- heres the important bit that links the loader to AmmoPart="Ammo12Gauge", but we're going to use "AmmoGeneric" instead of an actual in game class part called "Ammo12Gauge"-->
<!-- heres the important bit that links the loader to AmmoPart="Ammo12Gauge", but we're going to use "AmmoGeneric" instead of an actual in game class part called "Ammo12Gauge"-->
     <part Name="MagazineAmmoLoader" ProjectileObject="" AmmoPart="Ammo12Gauge" MaxAmmo="6"></part>
     <part Name="MagazineAmmoLoader" ProjectileObject="" AmmoPart="Ammo12Gauge" MaxAmmo="6"></part>
<!-- -->
<!-- -->
     <part Name="Description" Short="A stockless, pump-action shotgun of jet black."></part>
     <part Name="Description" Short="A stockless, pump-action shotgun of jet black."></part>
     <part Name="Metal"></part>
     <part Name="Metal"></part>
Line 28: Line 29:
   
   
   
   
<!-- heres the important bit that links it to AmmoPart="Ammo12Gauge" in the 12 Gauge Shotgun definition, give it an AmmoGeneric component and two tags, AmmoPartType with the value set to Ammo12Gauge, and a tag with just the name of the ammo part name itself -->
<!-- heres the important bit that links it to AmmoPart="Ammo12Gauge" in the 12 Gauge Shotgun definition, give it an AmmoGeneric component and two tags, AmmoPartType with the value set to Ammo12Gauge, and a tag with just the name of the ammo part name itself -->
     <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge"></part>
     <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge"></part>
     <tag Name="AmmoPartType" Value="Ammo12Gauge"></tag>
     <tag Name="AmmoPartType" Value="Ammo12Gauge"></tag>
     <tag Name="Ammo12Gauge"></tag>
     <tag Name="Ammo12Gauge"></tag>
<!-- -->
<!-- -->
   
   
     <part Name="Physics" Category="Ammo"></part>
     <part Name="Physics" Category="Ammo"></part>
Line 39: Line 40:
     <part Name="Commerce" Value="0.04"></part>
     <part Name="Commerce" Value="0.04"></part>
   </object>
   </object>
</syntaxhighlight>


AmmoSlug's code, if you want a template to create a new Ammo part: https://pastebin.com/gcYJpAh3
AmmoSlug's code, if you want a template to create a new Ammo part: https://pastebin.com/gcYJpAh3
Line 44: Line 46:
=Ammo Generic With Multiple Specialized Ammo Types=
=Ammo Generic With Multiple Specialized Ammo Types=


<object Name="Explosive 12 Gauge Shell" Inherits="TemporaryProjectile">
<syntaxhighlight lang="xml">
  <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge" SpecializedProjectileObject="Explosive_Projectile12Gauge"></part>
<object Name="Explosive 12 Gauge Shell" Inherits="TemporaryProjectile">
</object>
  <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge" SpecializedProjectileObject="Explosive_Projectile12Gauge"></part>
</object>
   
   
<object Name="AP 12 Gauge Shell" Inherits="TemporaryProjectile">
<object Name="AP 12 Gauge Shell" Inherits="TemporaryProjectile">
  <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge" SpecializedProjectileObject="AP_Projectile12Gauge"></part>
  <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge" SpecializedProjectileObject="AP_Projectile12Gauge"></part>
</object>
</object>
   
   
   
   
<object Name="Explosive_Projectile12Gauge" Inherits="TemporaryProjectile">
<object Name="Explosive_Projectile12Gauge" Inherits="TemporaryProjectile">
...
...
</object>
</object>
   
   
   
   
<object Name="AP_Projectile12Gauge" Inherits="TemporaryProjectile">
<object Name="AP_Projectile12Gauge" Inherits="TemporaryProjectile">
...
...
</object>
</object>
</syntaxhighlight>


=Scripting Impact Ammo Effects=
=Scripting Impact Ammo Effects=


Here's an example ammo part you can put on the projectile object that poisons on hit.
Here's an example ammo part you can put on the projectile object that poisons on hit.
<syntaxhighlight lang="csharp">
using System;
using System;
    
    
namespace XRL.World.Parts
namespace XRL.World.Parts
{
{
     [Serializable]
     [Serializable]
     public class Example_MissilePoisonOnHit : IPart
     public class Example_MissilePoisonOnHit : IPart
Line 104: Line 109:
         }
         }
     }  
     }  
}
}
</syntaxhighlight>
 
{{Modding Navbox}}

Latest revision as of 15:51, 2 October 2020

This page is about modding. See the modding overview for an abstract on modding.
This page is about modding. See the modding overview for an abstract on modding.

Custom Ammo Types

Custom moddable ammo types are supported without adding a new Ammo class to the game via AmmoGeneric, check out the "12 Gauge Shotgun" for an example of use.

  <object Name="12 Gauge Shotgun" Inherits="BaseMagazineRifle">
    <part Name="Render" DisplayName="12 gauge shotgun" RenderString=")"></part>
    <part Name="Physics" bUsesTwoSlots="true" Weight="16"></part>
    <part Name="Commerce" Value="100"></part>
    <part Name="MissileWeapon" Skill="Rifle" NoWildfire="true" NoAmmoProjectile="Ammo12Gauge" ShotsPerAction="8" AmmoPerAction="1" ShotsPerAnimation="8" WeaponAccuracy="35" RangeIncrement="6"></part>
 
<!-- heres the important bit that links the loader to AmmoPart="Ammo12Gauge", but we're going to use "AmmoGeneric" instead of an actual in game class part called "Ammo12Gauge"-->
    <part Name="MagazineAmmoLoader" ProjectileObject="" AmmoPart="Ammo12Gauge" MaxAmmo="6"></part>
<!-- -->
    <part Name="Description" Short="A stockless, pump-action shotgun of jet black."></part>
    <part Name="Metal"></part>
    <tag Name="Tier" Value="3"></tag>
    <part Name="Examiner" AlternateDisplayName="rifle" Complexity="3" Difficulty="0"></part>
  </object>
   
  <object Name="Projectile12Gauge" Inherits="TemporaryProjectile">
    <part Name="Projectile" BasePenetration="4" BaseDamage="1d10" ColorString="&amp;y"></part>
    <part Name="Physics" IsReal="false"></part>
  </object>
     
  <object Name="12 Gauge Shell" Inherits="TemporaryProjectile">
    <part Name="Render" DisplayName="12 gauge 00 buckshot" ColorString="&amp;y"></part>
 
 
<!-- heres the important bit that links it to AmmoPart="Ammo12Gauge" in the 12 Gauge Shotgun definition, give it an AmmoGeneric component and two tags, AmmoPartType with the value set to Ammo12Gauge, and a tag with just the name of the ammo part name itself -->
    <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge"></part>
    <tag Name="AmmoPartType" Value="Ammo12Gauge"></tag>
    <tag Name="Ammo12Gauge"></tag>
<!-- -->
 
    <part Name="Physics" Category="Ammo"></part>
    <part Name="Description" Short="A brass-cased cartridge of round lead balls."></part>
    <part Name="TinkerItem" Bits="C" CanBuild="true" CanRepair="false" CanDisassemble="false" NumberMade="4"></part>
    <part Name="Commerce" Value="0.04"></part>
  </object>

AmmoSlug's code, if you want a template to create a new Ammo part: https://pastebin.com/gcYJpAh3

Ammo Generic With Multiple Specialized Ammo Types

<object Name="Explosive 12 Gauge Shell" Inherits="TemporaryProjectile">
  <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge" SpecializedProjectileObject="Explosive_Projectile12Gauge"></part>
</object>
 
<object Name="AP 12 Gauge Shell" Inherits="TemporaryProjectile">
  <part Name="AmmoGeneric" ProjectileObject="Projectile12Gauge" SpecializedProjectileObject="AP_Projectile12Gauge"></part>
</object>
 
 
<object Name="Explosive_Projectile12Gauge" Inherits="TemporaryProjectile">
...
</object>
 
 
<object Name="AP_Projectile12Gauge" Inherits="TemporaryProjectile">
...
</object>

Scripting Impact Ammo Effects

Here's an example ammo part you can put on the projectile object that poisons on hit.

using System;
  
namespace XRL.World.Parts
{
    [Serializable]
    public class Example_MissilePoisonOnHit : IPart
    {
        public int Chance = 0;
        int Strength = 15;
        string DamageIncrement = "3d3";
        string  Duration = "6-9";
        public Example_MissilePoisonOnHit()
        {
            Name = "Example_MissilePoisonOnHit";
        }
  
        public override void Register(GameObject Object)
        {
            Object.RegisterPartEvent(this, "ProjectileHit");           
        }
  
        public override bool FireEvent(Event E)
        {
            if (E.ID == "ProjectileHit")
            {
                if (Rules.Stat.Random(1, 100) <= Chance)
                {
                    GameObject Defender = E.GetParameter("Defender") as GameObject;
                    if (Defender == null) return true;
                    if( !Defender.Statistics.ContainsKey("Toughness") || Rules.Stat.Roll("1d20")+Defender.Statistics["Toughness"].Modifier <= 10+Strength )
                    {
                        Defender.ApplyEffect( new Effects.Poisoned( Rules.Stat.Roll(Duration), DamageIncrement, Strength, ParentObject.pPhysics.Equipped ) );
                    }
                }
            }
  
            return base.FireEvent(E);
        }
    } 
}