You can't think of a way to use that item.

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

You can't think of a way to use that item.

Post by Mindless Automaton »

Here is my item thus far. I doubleclick it to activate it. I works fine except for displaying the above message.

Code: Select all

//Amulet of the Gourmand

function onUseChecked( pUser )
{
	var pSock = pUser.socket;

	pSock.CustomTarget( 0, "What do you wish to eat?" );
	
}

//pick targeting
function onCallback0( pSock, myTarget )
{

	var pUser = pSock.currentChar; 

	var isInRange = pUser.InRange( myTarget, 3 );
	
	if( !isInRange )
 	{
		pUser.SysMessage( "You are too far away to reach that." );
		return false;
	}
	if( !myTarget.corpse )
	{
		pSock.SysMessage( "Not a valid target." );
		return false;
	}

	pSock.SysMessage( "You devour the " + myTarget.name + ".");
	pSock.SoundEffect( (0x003A + RandomNumber( 0, 2 )), true );
	myTarget.Delete();

}

Also, it appears to crash the server if I target a npc a few times.. maybe other items.. :)

Also, is there a way to delete the corpse without deleting any loot also?

Thanks!
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
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 »

Add return false; to the end of your onUseChecked script to stop the message. Or return true if you want the item to also run the hardcoded functionality for it.

Also, if there's a random crash, it could be related to the RandomNumber thing? What values are accepted by SoundEffect, and does it stay within those limits?
-= Ho Eyo He Hum =-
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Mindless Automaton »

Xuri wrote: Also, if there's a random crash, it could be related to the RandomNumber thing? What values are accepted by SoundEffect, and does it stay within those limits?
Actually, its not very random, its when I missed the target and just click on nothing. Well, grass tile anyways.

So mytarget.delete(); tends to delete the running server. :) Oops.
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
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 »

Always double-check to see that your objects actually exist before you try doing drastic changes to them ;)

Try this, though:

Code: Select all

//pick targeting 
function onCallback0( pSock, myTarget ) 
{ 
	var pUser = pSock.currentChar; 
	
	if( !pSock.GetWord( 1 ) && myTarget.isItem )
	{
		var isInRange = pUser.InRange( myTarget, 3 ); 
    
   		if( !isInRange ) 
    	{ 
      		pUser.SysMessage( "You are too far away to reach that." ); 
      		return false; 
   		} 
		if( !myTarget.corpse ) 
   		{ 
      		pSock.SysMessage( "Not a valid target." ); 
      		return false; 
   		} 

   		pSock.SysMessage( "You devour the " + myTarget.name + "."); 
   		pSock.SoundEffect( (0x003A + RandomNumber( 0, 2 )), true ); 
   		myTarget.Delete(); 
	}
}
If pSock.GetWord( 1 ) is true, you haven't targeted a dynamic item or a character, I believe.
-= Ho Eyo He Hum =-
Post Reply