Shotgun help

K.V.

Hello.

I'm playing around with Pixie's Zombie Apocalypse game, and I want a shotgun.

I want it to definitely hit the target, and I'd like there to be a random chance that it slightly damages any other enemies in the room.

Here's the current code (which in no way involves a shotgun):

  <function name="DoAttack" parameters="attacker, weapon, target, firearm"><![CDATA[
    if (firearm) {
      damageatt = "firearmdamage"
      attackatt = "firearmattack"
      weapon.ammo = weapon.ammo - 1
    }
    else {
      damageatt = "damage"
      attackatt = "attack"
    }
    roll = GetRandomInt(1, 20) + weapon.attack - target.defence
    damage = DiceRoll(weapon.damage) * (100 - target.armour) / 100
    if (damage < 1) {
      damage = 1
    }
    if (roll > 15) {
      damage = damage * 3
      AttackReport (weapon.critdesc, attacker, target, damage)
      target.hitpoints = target.hitpoints - damage
    }
    else if (roll > 10) {
      AttackReport (weapon.attackdesc, attacker, target, damage)
      target.hitpoints = target.hitpoints - damage
    }
    else {
      AttackReport (weapon.missdesc, attacker, target, 0)
    }
    WeaponUpdate
  ]]></function>
      <object name="pistol">
        <inherit name="editor_object" />
        <look>Good for shooting zombies. Shots: {pistol.ammo}/{pistol.ammomax}</look>
        <take />
        <alias>Pistol</alias>
        <inventoryverbs type="stringlist">
          <value>Look at</value>
          <value>Drop</value>
          <value>Equip</value>
          <value>Reload</value>
        </inventoryverbs>
        <feature_startscript />
        <ammotype>cartridge</ammotype>
        <attr name="_initialise_" type="script">
          //Log ("Running pistol initialise script")
          this.damage = "2"
          this.attack = 0
          this.firearmdamage = "2d8"
          this.firearmattack = 3
          this.ammo = 3
          this.ammomax = 6
          this.critdesc = "A well placed shot with the pistol on #target# (#hits# hits)."
          this.attackdesc = "You shoot at #target# (#hits# hits)."
          this.missdesc = "You shoot wildly and entirely miss #target#."
        </attr>
      </object>

K.V.

bump


Try this (untested):

if (firearm) {
  damageatt = "firearmdamage"
  attackatt = "firearmattack"
  weapon.ammo = weapon.ammo - 1
}
else {
  damageatt = "damage"
  attackatt = "attack"
}
roll = GetRandomInt(1, 20) + weapon.attack - target.defence
damage = DiceRoll(weapon.damage) * (100 - target.armour) / 100
if (damage < 1) {
  damage = 1
}
if (roll > 15) {
  damage = damage * 3
  AttackReport (weapon.critdesc, attacker, target, damage)
  target.hitpoints = target.hitpoints - damage
}
else if (roll > 10 or GetBoolean(weapon.autohits)) {
  AttackReport (weapon.attackdesc, attacker, target, damage)
  target.hitpoints = target.hitpoints - damage
}
else {
  AttackReport (weapon.missdesc, attacker, target, 0)
}
if (HasInt(weapon, splatterchance)) {
  foreach (obj, GetDirectChildren(game.pov.parent)) {
    if (HasBoolean(obj, "dead")) {
	  if (not obj.dead and RandomChance(weapon, splatterchance)) {
	    damage = DiceRoll(weapon.splatterdamage)
        AttackReport (weapon.splatterdesc, obj, target, damage)
        obj.hitpoints = obj.hitpoints - damage
	  }
	}
  }
}
WeaponUpdate

You will need to give your shotgun these attributes:

autohits - set to true to have it hit automatically
splatterchance - percentage probability of something else getting hit
splatterdamage - the damage when something else is hit (eg, "2d4")
splatterdesc - the description when something else is hit


K.V.

Thanks, Pix!

I'll test it out soon. (It appears you've added the quite a few useful options I wouldn't have thought of, too! Awesome!)


I was going to say you could do something like this; but it does mean that for every weapon that does something other than "do damage to one target", you're adding extra code to the attack function.

If you've got multiple types of unusual weapon resolution (a grenade that goes off next turn unless the enemy throws it back? Caltrops? Anything else?) it might end up neater to have the attack function test if the weapon has certain scripts and run them, allowing it to modify the target/damage/etc. So if a weapon has some unique property, the code is encapsulated within the weapon itself.

(of course, if there's multiple weapons that do splash damage, it makes sense for it to be in the core function)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums