Firing multiple projectiles from weapons?

Started by ZestyLemons, August 01, 2014, 05:16:08 AM

Previous topic - Next topic

ZestyLemons

Hi, just started to get into a little modding. I thought a fun and easy first project would be a modding the shotgun to actually fire several projectiles, instead of one giant one. I tried for a while, but I couldn't find any modding material on getting a weapon to fire 2+ projectiles in the same tick.


Here's what I tried (damage/warmup/etc values are no where near balanced, was just messing around):


<ThingDef ParentName="BaseGun">
<defName>Gun_12GShotgun</defName>
<label>12G Shotgun</label>
<description>A 12 gauge shotgun, perfect for putting several nasty holes through its target.
</description>
<texturePath>Things/Item/Equipment/Shotgun</texturePath>
<soundInteract>InteractShotgun</soundInteract>
<tradersCarry>True</tradersCarry>
<basePrice>60</basePrice>
<verb>
<projectileDef>Bullet_Pistol</projectileDef>
<warmupTicks>120</warmupTicks>
<range>40</range>
      <accuracyTouch>1</accuracyTouch>
      <accuracyShort>0.95</accuracyShort>
      <accuracyMedium>0.80</accuracyMedium>
      <accuracyLong>0.70</accuracyLong>
        <ticksBetweenBurstShots>0</ticksBetweenBurstShots>
<burstShotCount>9</burstShotCount>
<fireSound>ShotShotgun</fireSound>
</verb>
</ThingDef>


I thought using burstshots tag with 0 ticks would give me a cheaty way to fire many projectiles at once, but it seems to clamp it to one tick/not work the way I want. Burst shots also makes the shotgun sound play several times in a row, which makes the gun sound really odd when it fires.

Is there a way to get weapons that fire multiple projectiles?
Help out with the wiki!

Steam: http://steamcommunity.com/id/Divaya/
Wiki: http://rimworldwiki.com/wiki/User:Zesty

Feel free to contact me about wiki questions or wiki admin stuff.

RawCode

Not possible without custom assembly.

Sample mod attached to message.
Source

   public class ProjectileHook
    {
        public Projectile target2;
        public ThingDef type;
        private IntVec3 source;
        public bool canFreeIntercept = false;

        public ProjectileHook(ThingDef type, IntVec3 source)
        {
            this.type = type;
            this.source = source;
        }

        internal void Launch(Thing thing, Vector3 drawPos, TargetPack targetPack)
        {

        for (int i = 0; i < 30; i++)
{
                target2 = (Projectile)ThingMaker.MakeThing(type);
                GenSpawn.Spawn((Thing)target2, source);
                target2.canFreeIntercept = canFreeIntercept;
                target2.Launch(thing, drawPos, targetPack);
}
        }
    }

    public class Caerbannog_Gun : Verb_Shoot
    {
        protected override bool TryShotSpecialEffect()
        {
            ShootLine shootLine;
            if (!this.TryFindShootLineFromTo(this.owner.Position, this.currentTarget, out shootLine))
                return false;
            Vector3 drawPos = this.owner.DrawPos;
            ProjectileHook projectile = new ProjectileHook(this.verbProps.projectileDef,shootLine.source);
            float num = this.verbProps.forcedMissRadius;
            float horizontalSquared = (this.currentTarget.Loc - this.owner.Position).LengthHorizontalSquared;
            if ((double)horizontalSquared < 9.0)
                num = 0.0f;
            else if ((double)horizontalSquared < 25.0)
                num *= 0.5f;
            else if ((double)horizontalSquared < 49.0)
                num *= 0.8f;
            if ((double)num > 0.5)
            {
                int index = UnityEngine.Random.Range(0, GenRadial.NumCellsInRadius(this.verbProps.forcedMissRadius));
                if (index > 0)
                {
                    IntVec3 intVec3 = this.currentTarget.Loc + GenRadial.RadialPattern[index];
                    projectile.canFreeIntercept = true;
                    projectile.Launch(this.owner, drawPos, (TargetPack)intVec3);
                    return true;
                }
            }
            HitReport hitReport = this.HitReportFor(this.currentTarget);
            if ((double)UnityEngine.Random.value > (double)hitReport.TotalNonWildShotChance)
            {
                shootLine.ChangeDestToMissWild();
                projectile.canFreeIntercept = true;
                projectile.Launch(this.owner, drawPos, (TargetPack)shootLine.dest);
                return true;
            }
            else if ((double)UnityEngine.Random.value > (double)hitReport.HitChanceThroughCover && this.currentTarget.Thing != null && this.currentTarget.Thing.def.eType == EntityType.Pawn)
            {
                Thing thing = hitReport.covers.RandomBlockingCoverWeighted();
                projectile.canFreeIntercept = true;
                projectile.Launch(this.owner, drawPos, new TargetPack(thing));
                return true;
            }
            else
            {
                if (this.currentTarget.Thing != null)
                    projectile.Launch(this.owner, drawPos, new TargetPack(this.currentTarget.Thing));
                else
                    projectile.Launch(this.owner, drawPos, new TargetPack(shootLine.dest));
                return true;
            }
        }
    }


Special Caerbannog Pistol can be spawned with creative tools, that gun will shot 30 projectiles in narrow cone.

[attachment deleted by admin: too old]

ZestyLemons

#2
Thanks! Luckily I know a little C#, hopefully I can learn a little about the Rimworld assembly too.

Edit:

Results! Thanks so much for the example code.
Here's a screenie with low bullet speed/low warm up to demonstrate the shotgun spread:



Took a little messing around to get shotgun spread working, but it works pretty well.
Thanks again.
Help out with the wiki!

Steam: http://steamcommunity.com/id/Divaya/
Wiki: http://rimworldwiki.com/wiki/User:Zesty

Feel free to contact me about wiki questions or wiki admin stuff.

Somz

I was just about to ask for the same kind of help, but hearing of this C# is kinda destroyed the mood, I know nothing of it, I can hardly mod an xml. (ಥ﹏ಥ)
This mod thing, "Special Caerbannog Pistol can be spawned with creative tools, that gun will shot 30 projectiles in narrow cone.", where could I find it?
To beer or not to beer.
That is a laughable question.

RawCode



modding is not for everyone, it's ok if you dont understand c# or dont know where is creative tools

Bog

Quote from: Cyst on August 01, 2014, 06:14:08 PM
I was just about to ask for the same kind of help, but hearing of this C# is kinda destroyed the mood, I know nothing of it, I can hardly mod an xml. (ಥ﹏ಥ)
This mod thing, "Special Caerbannog Pistol can be spawned with creative tools, that gun will shot 30 projectiles in narrow cone.", where could I find it?
It's at the very bottom of RawCode's first post. It's called URT.zip.
Divergence of Civilization Lead Developer (in this case that's the fancy way of saying "Only Developer")

Project Armoury Developer (New huge 2.13 Release now live!)

ZestyLemons

Quote from: Cyst on August 01, 2014, 06:14:08 PM
I was just about to ask for the same kind of help, but hearing of this C# is kinda destroyed the mood, I know nothing of it, I can hardly mod an xml. (ಥ﹏ಥ)
This mod thing, "Special Caerbannog Pistol can be spawned with creative tools, that gun will shot 30 projectiles in narrow cone.", where could I find it?

Yeah, I was also kinda bummed that the .xml isn't very powerful modding wise. It's kind of annoying having to relaunch/reload Rimworld everytime I wanna tweak some assembly.
Help out with the wiki!

Steam: http://steamcommunity.com/id/Divaya/
Wiki: http://rimworldwiki.com/wiki/User:Zesty

Feel free to contact me about wiki questions or wiki admin stuff.

RawCode

XML allows to change only things specially defined by developer as "changeable".

same with assembly - you can define methods and ever entire classes as dynamic and change them at runtime, but this is not easy and fun.

Somz

Quote from: Bog on August 01, 2014, 07:33:42 PM

It's at the very bottom of RawCode's first post. It's called URT.zip.


...It just didn't poke out my eyes... (;一_一)
Thanks!
To beer or not to beer.
That is a laughable question.