RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

make an npc cast a spell on me, on command

barakko

Wanderer
make an npc cast a spell on me, on command

I want a NPC bless me when I tell him.
how can i do that?

the only useful code that i've found out is this:
new BlessSpell( m_caster, null ).Cast();
but how do i set the victim?

edit: i tried this
Target targ = m_caster.Target;
Spell spell = new BlessSpell( m_caster, null );
spell.Cast();
targ.Invoke( m_caster, (object)m_from );
but the server crashes because "Object reference not set to an instance of an object."
(m_from and m_caster are set, he's lying.)
 

barakko

Wanderer
[code:1]BlessSpell spell = new BlessSpell( m_chiromante, null );
spell.Target(m_from);
spell.Cast();[/code:1]
the spell is launched but the caster (m_chiromante) launches it at himself.
even using targets and targ.Invoke( m_from, (object)m_from ) leads to nothing...
if you change "BlessSpell" to "FireballSpell" it does not even cast it!
 

blobby

Wanderer
I think it could be done by creating a new command (like ".npcCastHealOnMe") then, u call a copy of the OnTarget fonction for the skill (like Heal) with (Mobile)from being the NPC and (object)o being you.

Step by step:

1- Create a new command
2- Copy the OnTarget command (and the Target command in the case of Heal) then rename it to something else. (like NPCHeal)
3- In your command, call the newly made NPCHeal fonction using (Mobile)from being the NPC and (object)o being you.

At that point, you can remove a lot of restrictions in the fonction. Using Heal as an exemple, you don't have to verify if the mobile is a golem. You should change the Caster.SendLocalizedMessage to m.SendLocalizedMessage, because the NPC doesn't want a localized message. Change:
Caster.LocalOverheadMessage( MessageType.Regular, 0x22, (Caster == m) ? 1005000 : 1010398 );
to:
m.LocalOverheadMessage( MessageType.Regular, 0x22, 1010398 );
Then you should give a value to the toHeal variable that doesn't depend on Magery skill.

When all that as been done, it should be working, if it's possible to make an NPC cast a spell, which i'm not sure.
 

barakko

Wanderer
TheOutkastDev said:
m_caster.Target = new BlessSpell( m_caster, null ).Cast();
but Cast() returns a bool, not a Target
anyway, i've also tried to do this:
[code:1]Target targ = m_chiromante.Target;
if (targ != null) {
return;
}
BlessSpell spell = new BlessSpell( m_chiromante, null );
targ = new InternalTarget( spell );
targ.Invoke( m_chiromante, (object)m_from );
.....
private class InternalTarget : Target { // 4 bless
BlessSpell m_spell;
public InternalTarget( BlessSpell spell ) : base( -1, false, TargetFlags.None ) {
m_spell = spell;
}
protected override void OnTarget( Mobile from, object to ) {
m_spell.Target( (Mobile)to );
}
}[/code:1]
no, it didn't work.
blobby said:
but that wouldn't actually cast the spell, it will be *looking* like the spell has been casted, but the amount of healed hits does not depend on magery, and so on ... this isn't good. or I misunderstood something.
 
[code:1]
new BlessSpell( m_caster, null ).Cast();
if( m_caster.Target != null )
m_caster.Target.Invoke( m_caster, mobile_to_invoke_on );
[/code:1]
 

CraZy_NooB

Wanderer
whats the point....but it looks like you have the m_caster things messed up, you are going to need m_target, which will be you, so it will be something like m_target = new target
then have him cast on target
 

barakko

Wanderer
this is what I am trying to do.
btw; Target ctor does not take any useful parameters, the only useful function in Target is Invoke which is:
void Invoke( Mobile from, object targeted )
i know from=caster and targeted=victim, but the spell is still going on the caster.
 

barakko

Wanderer
well, i've found a few ways (not without effort).
the fastest way:
[code:1]BlessSpell spell = new BlessSpell( m_caster, null );
spell.Cast();
spell.State = SpellState.Sequencing;
spell.Target(m_target);[/code:1]
but the spell isn't delayed, and the character does not perform the animation, i think it also overrides the region rules.

the other way will need a little of stock script editing. I hate doing it but I found it is the only way.
in our example, Bless.cs has a piece that looks like this:
[code:1]public BlessSpell( Mobile caster, Item scroll ) : base( caster, scroll, m_Info ) {
}
public override void OnCast()
{
Caster.Target = new InternalTarget( this );
}[/code:1]
change it to this:
[code:1]private Mobile m_autotarget;
public BlessSpell( Mobile caster, Item scroll, Mobile autotarget ) : this( caster, scroll ) {
m_autotarget = autotarget;
}
public BlessSpell( Mobile caster, Item scroll ) : base( caster, scroll, m_Info ) {
m_autotarget = null;
}
public override void OnCast() {
if ( m_autotarget != null )
Target( m_autotarget );
else
Caster.Target = new InternalTarget( this );
}[/code:1]
and then you can do simply:
[code:1]BlessSpell spell = new BlessSpell( m_caster, null, m_target );
spell.Cast();
[/code:1]
as you probably have seen, i've added a new constructor to BlessSpell, which lets you choose a target before actually casting the spell, and so without popping out the target.
For now I can't think of a best way to do it. I think it would be nice to see this piece of code in the next beta ......
 
*sigh* all that extra work just because you couldn't post the script you were making so we could show u how to do it the much faster, easier, and simpler way...
 

CraZy_NooB

Wanderer
TheOutkastDev said:
the whole script. bits and pieces are useless.

unless your just trying to help out, if he wants it that way he can have it that way, he figured it out pretty much on his own, you can pretty much assume the script that he is making though.

he is finding methods to get an npc to cast certain spells on him, so taht he can make cast whatever he wants on him, whenever he wants it.

only problem, lik ehe said was that he had problems with the animation of the spell, and that happens sometimes when you cast spells, you will not get the full anim if the spell casts faster than the animataion timer is set for.
 
Top