Have a blast.
Adding Monster group & OnHit scripts
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.
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
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;
}
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:
He's mixing his JS and C++ 
Change this
to
You'll need to do something similar for the GetWeapon function
Change
to
Change this
Code: Select all
CItem *mWeapon = GetWeapon( mAttacker );
Code: Select all
var mWeapon = GetWeapon( mAttacker );
Change
Code: Select all
CItem *rHand = mAttacker.FindItemLayer( 1 );
CItem *lHand = mAttacker.FindItemLayer( 2 );
Code: Select all
var rHand = mAttacker.FindItemLayer( 1 );
var lHand = mAttacker.FindItemLayer( 2 );
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.
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:
Actually, yeah, I can see why that might happen. Easy enough fix, sort of. Change onAttack to this:
That'll mean it does nothing when you don't have a weapon equipped (aka fisticuffs!)
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 );
}
}
}
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:
Here is the .dfn entry for the weapon I am using:
Thanks everyone!
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;
}
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
}