Page 1 of 1

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

Posted: Sat Feb 21, 2009 4:17 am
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!

Posted: Sat Feb 21, 2009 5:02 am
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?

Posted: Sat Feb 21, 2009 5:31 am
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.

Posted: Sat Feb 21, 2009 9:34 am
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.