Adding Monster group & OnHit scripts

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

I think they can be improved upon as well.

Have a blast. :)
Scott
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Sorry to bring up this old post, but I'm finally getting around to implementing it.

I took Giwos script and added it to the global.js.

Code: Select all


function onAttack( mAttacker, mDefender ) 
{ 
   CItem *mWeapon = GetWeapon( mAttacker ); 
   if( mWeapon.type == 40 && RandomNum( 0, 100 ) > 50 ) // The entire 40's type range is unused 
   { 
      mDefender.MagicEffect( 43 ); 
      mDefender.PlaySound( 0x0207 ); 
      mDefender.Damage( RollDice( 2, 8, 0 ), mAttacker ); 
   } 
} 

function GetWeapon( mAttacker ) 
{ 
   CItem *rHand = mAttacker.FindItemLayer( 1 ); 
   if( ValidateObject( rHand ) ) 
   { 
      if( rHand.type != 9 ) // Spellbook 
         return rHand; 
      else 
         return null; 
   } 

   CItem *lHand = mAttacker.FindItemLayer( 2 ); 
   if( ValidateObject( lHand ) ) 
      return lHand; 

   return null; 
}  
It gives me a compile error in UOx3 when JS scripts are loaded. Something about an invalid expression on the "left side" of this argument:

CItem *mWeapon = GetWeapon( mAttacker );


and it says, "token pointer: CItem *mWeapon = GetWeapon( mAttacker ); "

I'm not sure how the CItem function works, nor how pointers work in the JS engine. I've tried everything with my limited skills to get this to work and can't seem to make it.

Grimson, Maarc, Giwo, Xuri? Anyone have any ideas? Once it gets working we can have a new batch of custom weapons to implement.

Thanks again,

stranf
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

He's mixing his JS and C++ :)

Change this

Code: Select all

CItem *mWeapon = GetWeapon( mAttacker );
to

Code: Select all

var mWeapon = GetWeapon( mAttacker );
You'll need to do something similar for the GetWeapon function

Change

Code: Select all

CItem *rHand = mAttacker.FindItemLayer( 1 );
CItem *lHand = mAttacker.FindItemLayer( 2 );
to

Code: Select all

var rHand = mAttacker.FindItemLayer( 1 );
var lHand = mAttacker.FindItemLayer( 2 );
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

lol
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Thanks everyone!

Got it running well. Except, occasionally I get an error.

It says:

"Type Error: mWeapon has no properties.
Error: Erroneous Line: <null>
Token Ptr: <null>

It seems to fire after I re-load the script and use my weapon without re-equipping it. I'm going to see if I can reproduce it. Any thoughts appreciated.
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

Actually, yeah, I can see why that might happen. Easy enough fix, sort of. Change onAttack to this:

Code: Select all

function onAttack( mAttacker, mDefender ) 
{ 
   var mWeapon = GetWeapon( mAttacker ); 
   if( mWeapon != null )
   {
     if( mWeapon.type == 40 && RandomNum( 0, 100 ) > 50 ) // The entire 40's type range is unused 
     { 
        mDefender.MagicEffect( 43 ); 
        mDefender.PlaySound( 0x0207 ); 
        mDefender.Damage( RollDice( 2, 8, 0 ), mAttacker ); 
     } 
   }
} 
That'll mean it does nothing when you don't have a weapon equipped (aka fisticuffs!)
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Yup, I got it to repeat again. Apperently I can get one or two "good" fires of the script, and then it fails with the "mWeapon has no properties" error. I wonder if the error is introduced in the way the JS scripts re-call scripts?

This one could be hard to debug. Too bad too, it is an awesome script.

This is my global.js how it is now. Hopefully some of you can see something:

Code: Select all



function onDeathBlow( pKilled, pKiller ) 
{ 
   var oldNumToKill = pKiller.GetTag( "KT_NUMTOKILL" ); 
   if( oldNumToKill && pKiller.GetTag( "KT_IDTOKILL" ) == pKilled.id ) 
   { 
      var newNumToKill = (oldNumToKill-1); 
      pKiller.SetTag( "KT_NUMTOKILL", newNumToKill ); 
      if( newNumToKill ) 
         pKiller.SysMessage( "You have "+NumToString( newNumToKill )+" more creatures to kill." ); 
      else 
         pKiller.SysMessage( "You have completed your task, return to the taskmaster for your reward." ); 
   } 
} 

function onAttack( mAttacker, mDefender ) 
{ 
   var mWeapon = GetWeapon( mAttacker ); 
   if( mWeapon.type == 40 && RandomNumber( 0, 100 ) > 65 ) // The entire 
   { 
      mDefender.MagicEffect( 43 ); 
      mDefender.SoundEffect( 0x0207, true ); 
      mDefender.Damage( RollDice( 3, 8, 0 ), mAttacker ); 
   } 
} 

function GetWeapon( mAttacker ) 
{ 
   var rHand = mAttacker.FindItemLayer( 1 ); 
   if( ValidateObject( rHand ) ) 
   { 
      if( rHand.type != 9 ) // Spellbook 
         return rHand; 
      else 
         return null; 
   } 

  var lHand = mAttacker.FindItemLayer( 2 ); 
   if( ValidateObject( lHand ) ) 
      return lHand; 

   return null; 
}  

Here is the .dfn entry for the weapon I am using:

Code: Select all



[drag_swd]
{get=0x0f60 
 id=0x0f60 
 name=Glowing Sword
 name2=Theleron
 weight=780
 spd=28
 str=90
 hp=175
 restock=10
 movable=1
 decay=0
 lodamage=20
 hidamage=24
 stradd= +4
 intadd= +6
 dexadd= +3
 type=40
}

Thanks everyone!
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Thanks Maarc, I'll try that.

However, I was using the equipped weapon when it fired....unless it was the swinging of the orc that did it! hahaha
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

It could be the orc, yes, given that it's in a global script :)
Post Reply