Full Version : specify NPC spells
xmlspawner >>XMLSpawner Mods and Tips >>specify NPC spells


<< Prev | Next >>

malavon- 06-12-2006
Hi Arte!
Can I set with XMLspawner spells, which spawned NPC can cast? For example I can spawn ork, which can cast only Magic Arrow spell and no other.

ArteGordon- 06-13-2006
You can make a simple mod to the mageai.cs to restrict the spells cast by individual spawned mobs.

QUOTE

  public virtual Spell GetRandomDamageSpell()
  {

  // ARTEGORDONMOD
  // restrict the damage spells that can be cast by this mob
  // look for the xmldata attachment named "DamageSpells"
  // the Data string will contain a list of space-separated spells that can be cast
  XmlData x = (XmlData)XmlAttach.FindAttachment(m_Mobile, typeof(XmlData), "DamageSpells");
  if (x != null)
  {
    // get the spell list
    string[] spells = BaseXmlSpawner.ParseSpaceArgs(x.Data, 20);
    if (spells != null && spells.Length > 0)
    {
    // choose one at random
    int index = Utility.Random(spells.Length);

    return SpellRegistry.NewSpell(spells[index], m_Mobile, null);
    }
  }

  int maxCircle = (int)((m_Mobile.Skills[SkillName.Magery].Value + 20.0) / (100.0 / 7.0));

  if ( maxCircle < 1 )
    maxCircle = 1;

  switch ( Utility.Random( maxCircle*2 ) )
  {
    case  0: case  1: return new MagicArrowSpell( m_Mobile, null );
    case  2: case  3: return new HarmSpell( m_Mobile, null );
    case  4: case  5: return new FireballSpell( m_Mobile, null );
    case  6: case  7: return new LightningSpell( m_Mobile, null );
    case  8: case  9: return new MindBlastSpell( m_Mobile, null );
    case 10: return new EnergyBoltSpell( m_Mobile, null );
    case 11: return new ExplosionSpell( m_Mobile, null );
    default: return new FlameStrikeSpell( m_Mobile, null );
  }
  }


then when you spawn them, just give them the xmldata attachment named "DamageSpells" with the list of allowed spells separated by spaces, like this

orcishmage/ATTACH/xmldata,DamageSpells,MagicArrowSpell FireballSpell

Creatures that are spawned without the attachment will behave normally.

You will also need to add this to the beginning of mageai.cs

CODE

using Server.Engines.XmlSpawner2;