npc mage ai problems my mage ai script

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

npc mage ai problems my mage ai script

Post by dragon slayer »

Code: Select all

// DON'T CHANGE THIS VALUE: 
var i = 0; 

var manaCostHeal = 11;  
var healSelfEmote = "*heals self*"; 

// Gives the mage a chance to heal himself any time damage is done towards him 
function onDefense( pAttacker, pDefender ) 
{ 
   var iNum = RandomNumber( 0, 1000 ); 

   if ( !pDefender.InRange(pAttacker, 4))
   {

     switch( RandomNumber( 0, 4 ) ) 
     { 
         case 0: pDefender.CastSpell( 5 );
                 pDefender.EmoteMessage( "In Por Ylem" );       break; 
         case 1: pDefender.CastSpell( 11 );
                 pDefender.EmoteMessage( "An Nox" );       break; 
         case 2: pDefender.CastSpell( 33 );
                 pDefender.EmoteMessage( "In Jux Hur Ylem" );       break; 
         case 3: pDefender.CastSpell( 18 );
                 pDefender.EmoteMessage( "Vas Flam" );       break; 
         break;
     }
   }
   if( iNum > 700 ) 
   { 
      if( pDefender.health <pDefender> manaCostHeal ) 
         { 
            pDefender.health = pDefender.maxhp; 
            pDefender.mana-= manaCostHeal; 
            pDefender.StaticEffect( 0x376A, 0, 15 ); 
            pDefender.SoundEffect( 0x01f2, true ); 
            if( healSelfEmote ) 
               pDefender.EmoteMessage( healSelfEmote ); 
         } 
      } 
   } 
}
I'm working on this mage ai script but i can't seem to get him to cast the spells that in the switch box and I'm trying to make him check a range as well to not get close to attacker.
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

At work, so no time to test your script and see what's going on, but added some [ code ] [ /code ]-tags (minus the spaces) around your script to make it more easy to read.

Also note that onDefense triggers only when a character is hit in combat - so if pDefender isn't in range of pAttacker so pAttacker can actually hit him, the event should never trigger.

What you want to use, is probably something like
function onAISliver( tChar )
which runs on the character _every AI cycle_! So be careful when using it or you can bog down your entire server if the script is heavy enough. If using this, I would probably want to put something very early in the script to make sure it doesn't run through the entire script up to multiple times every second (depending on the CHECKNPCAI setting in UOX.INI, I think). :P

Even something simple as

Code: Select all

// If a random number between 0 and 30 isn't exactly 30, then exit script
if( RandomNumber( 0, 30 ) != 30 )
return;
Then adjusting the high-end of the RandomNumber function to tweak how often the script is actually triggered on average.
-= Ho Eyo He Hum =-
Post Reply