Line 0 script error

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
Galbuu
UOX3 Neophyte
Posts: 45
Joined: Mon Jul 05, 2004 9:20 am
Location: Orlando, FL
Has thanked: 0
Been thanked: 0
Contact:

Line 0 script error

Post by Galbuu »

(TypeError: undefined is not a function)

Line Number: 0

Code: Select all

function onUse(pUser, iUsed)
{
	if(pUser.skills.magery >= 662)
	{
	pUser.DoAction(0x11);
	pUser.TextMessage("Kel Nam Seii");
	pUser.StartTimer(1400, 0, true);
	}
	else
	{
	pUser.SysMessage("You do not have the required magery skill.");
	}

return false;
}

function onTimer(pUser, timerID)
{
	if(timerID == 0)
	{
	pUser.CustomTarget("Select a target.");
	} 
}

function onCallback0(pUser, myTarget)
{
var vDmg = RandomNumber(1, 40, 20);
myTarget.StaticEffect(0x3709, 9, 30);
myTarget.SoundEffect(552, true);
myTarget.DoAction(0x14);
myTarget.health -= vDmg;
}
Any ideas as to what causes the error?
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 »

Yup, magery's not an object.

Two things

1) There's a code error, improperly settings skills as a non-indexable object

2) Once that's fixed

Code: Select all

if( pUser.skills[25] >= 662 )
It's indexed by number, not by name... though I do wonder if it's possible to have a string based check... I wonder, something to think about, at least.

Until that fix is in general population, though, you could try

Code: Select all

if( pUser.CheckSkill( 25, 662, 1000) )
This check also accounts for skill growth. Basically, you've "used" the skill, and any skill gain is calculated, as well as returning true if the skill check passed. Having 66.2 isn't a guarantee (it's random, like other skill checks), but if you have 100.0, you won't gain any more (you can make it lower if you wish).
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 »

Hmmm, looks like I was wrong, someone must have changed the behaviour. As far as I can see, that code should work, going to debug it now. See why it's not working. But it should be just dandy.
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 »

Here's the script I used, and it passed fine.

Code: Select all

function onUse( pUser, iUsed ) 
{ 
	if( pUser.skills.magery >= 662 ) 
	{ 
		pUser.DoAction( 0x11 ); 
		pUser.TextMessage( "Kel Nam Seii" ); 
		pUser.StartTimer( 1400, 0, true ); 
	} 
	else 
	{ 
		pUser.SysMessage( "You do not have the required magery skill." ); 
	} 

	return false; 
} 

function onTimer( pUser, timerID ) 
{ 
	if( timerID == 0 ) 
	{ 
		pUser.CustomTarget("Select a target."); 
	} 
} 

function onCallback0( pUser, myTarget ) 
{ 
	var vDmg = RandomNumber( 20, 40 ); 
	myTarget.StaticEffect( 0x3709, 9, 30 ); 
	myTarget.SoundEffect( 552, true ); 
	myTarget.DoAction( 0x14 ); 
	myTarget.health -= vDmg; 
}
Galbuu
UOX3 Neophyte
Posts: 45
Joined: Mon Jul 05, 2004 9:20 am
Location: Orlando, FL
Has thanked: 0
Been thanked: 0
Contact:

Post by Galbuu »

Maarc wrote:Here's the script I used, and it passed fine.
I tried that and I still get the line 0 error. I also tried the first suggestion posted and I get the same error.... wtf?

Edit: I fixed this line and it worked.

Code: Select all

pUser.CustomTarget("Select a target.");
to

Code: Select all

pUser.CustomTarget(0, "Select a target.");
Thanks guys.
Galbuu
UOX3 Neophyte
Posts: 45
Joined: Mon Jul 05, 2004 9:20 am
Location: Orlando, FL
Has thanked: 0
Been thanked: 0
Contact:

Post by Galbuu »

I'm having more problems. I'm trying to make a check at the end if the target is a creature and if it is vulnerable, but the script fires even if I click for example the grass or an invulnerable creature.

Code: Select all

function onUse( pUser, iUsed )
{
	if( pUser.skills.magery >= 662 )
	{
	pUser.DoAction( 0x11 );
	pUser.TextMessage( "Kel Nam Seii" );
	pUser.StartTimer( 1400, 0, true );
	pUser.Freeze();
	}
	else
	{
	pUser.SysMessage( "You do not have the required magery skill." );
	}

	return false;
}

function onTimer( pUser, timerID )
{
	if( timerID == 0 )
	{
	pUser.CustomTarget(0, "Select a target.");
	pUser.Unfreeze();
	}
}

function onCallback0( pUser, myTarget )
{
	if(myTarget.vulnerable == true && myTarget.isChar == true);
	{
	var vDmg = RandomNumber( 20, 40 );
	myTarget.StaticEffect( 0x3709, 9, 30 );
	myTarget.SoundEffect( 552, true );
	myTarget.DoAction( 0x14 );
	myTarget.health -= vDmg;
	}

return false;
}
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 »

Correct, it'll fire regardless of what you click, as a target was selected :)

I could have sworn there was a way to determine if the target was a valid object or not, but it looks like it's not there. I'll add something so that if it didn't click something valid, myTarget will be null. I could have sworn there was some way of doing it though.... XUri may be able to chime in here, I remember him doing such a script.

You could try something like:

Code: Select all

function onCallback0( pUser, myTarget ) 
{
	if( pUser.GetByte( 7 ) != 0xFF )	// this byte is 0xFF if it was not an item or character selected
	{
		if( myTarget.vulnerable == true && myTarget.isChar == true );
		{ 
			var vDmg = RandomNumber( 20, 40 ); 
			myTarget.StaticEffect( 0x3709, 9, 30 ); 
			myTarget.SoundEffect( 552, true ); 
			myTarget.DoAction( 0x14 ); 
			myTarget.health -= vDmg; 
		} 
	}
	return false; 
}
I know that GetByte call is a *tad* archaic, and should be handled better, but it should work for the here and now.
Galbuu
UOX3 Neophyte
Posts: 45
Joined: Mon Jul 05, 2004 9:20 am
Location: Orlando, FL
Has thanked: 0
Been thanked: 0
Contact:

Post by Galbuu »

I think I would prefer to just wait for an updated version of UOX. Thanks.
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 »

You want to do the following in the callback function to check for the various possible targets. Looks weird, looks ugly - but it works :)

Code: Select all

	var StrangeByte   = pSock.GetWord( 1 );
	var targX	= pSock.GetWord( 11 );
	var targY	= pSock.GetWord( 13 );
	var targZ	= pSock.GetByte( 16 );
	var tileID	= pSock.GetWord( 17 );

	[color=yellow]// It's not a dynamic object, nor a static object - but a MAP TILE.[/color]
	if( tileID == 0 )
	{
		tileID = GetTileIDAtMapCoord( targX, targY, pSock.currentChar.worldnumber );
		pSock.SysMessage( "You targeted a tile with the following ID: "+tileID );
	}

	[color=yellow]// It's a dynamic object, and it's a character![/color]
	else if( StrangeByte == 0 && myTarget.isChar )
	{
		pUser.SysMessage( "You targeted "+myTarget.name );
	{

	[color=yellow]// It's a dynamic object, and it's not a character(i.e. an item![/color]
  	else if( StrangeByte == 0 && !myTarget.isChar  )
	{
		pUser.SysMessage( "You targeted the item with id: "+myTarget.id );
	}

	[color=yellow]// It's a static item![/color]
	else
	{
		pUser.SysMessage( "You targeted the item with id: "+tileID );
	}
-= Ho Eyo He Hum =-
Post Reply