Page 1 of 1
Line 0 script error
Posted: Wed Jul 07, 2004 5:24 am
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?
Posted: Wed Jul 07, 2004 6:05 am
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
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).
Posted: Wed Jul 07, 2004 9:23 am
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.
Posted: Wed Jul 07, 2004 9:33 am
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;
}
Posted: Wed Jul 07, 2004 2:09 pm
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.
Posted: Wed Jul 07, 2004 2:24 pm
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;
}
Posted: Wed Jul 07, 2004 2:39 pm
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.
Posted: Wed Jul 07, 2004 2:51 pm
by Galbuu
I think I would prefer to just wait for an updated version of UOX. Thanks.
Posted: Wed Jul 07, 2004 4:11 pm
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 );
}