Lord Leo
Member
- ServUO Version
- Publish 57
- Ultima Expansion
- Endless Journey
I made this with ChatGPT and it's supposed to create an NPC that randomly casts the Bless spell on players. But it doesn't.
Bless casting NPC:
// File: FancyBlessingNPC.cs
using System;
using System.Linq;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Spells;
using Server.Spells.Third; // Required for the Bless spell
using Server.Network;
using Server.Targeting;
namespace Server.Custom
{
public class FancyBlessingNPC : BaseCreature
{
private static string[] FemaleNames = new string[]
{
"Althea", "Bianca", "Celeste", "Diana", "Elise", "Fiona", "Gwendolyn", "Helena", "Isolde", "Jasmine",
"Katarina", "Liana", "Melisande", "Nadia", "Olivia", "Penelope", "Quinn", "Rosalind", "Seraphina", "Talia",
"Ursula", "Valeria", "Willa", "Xanthe", "Yvonne", "Zara"
};
[Constructable]
public FancyBlessingNPC() : base(AIType.AI_Mage, FightMode.None, 10, 1, 0.1, 0.2)
{
Name = FemaleNames[Utility.Random(FemaleNames.Length)];
Body = 0x191; // Female human
Hue = Utility.RandomSkinHue();
HairItemID = 0x203C; // Long hair
HairHue = Utility.RandomHairHue();
FancyDress dress = new FancyDress();
dress.Hue = Utility.RandomNeutralHue();
AddItem(dress);
Sandals sandals = new Sandals();
sandals.Hue = Utility.RandomNeutralHue();
AddItem(sandals);
Blessed = true;
Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(10.0), MoveAndBless);
}
public void MoveAndBless()
{
if (Deleted || !Alive) return;
// Move randomly
if (Utility.RandomDouble() < 0.5)
{
Map map = this.Map;
if (map != null)
{
int x = X + Utility.RandomMinMax(-5, 5);
int y = Y + Utility.RandomMinMax(-5, 5);
int z = map.GetAverageZ(x, y);
if (map.CanSpawnMobile(new Point3D(x, y, z)))
{
SetLocation(new Point3D(x, y, z), true);
}
}
}
// Find nearby players and bless them
IPooledEnumerable eable = this.GetMobilesInRange(3);
foreach (Mobile m in eable)
{
Spell spell = new BlessSpell(this, null);
spell.Cast();
m.SendMessage("Blessed Be!");
break; // Cast only on one player per iteration
}
eable.Free();
}
public FancyBlessingNPC(Serial serial) : base(serial) { }
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)0); // version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
}
}