Necro potion problem

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Necro potion problem

Post by dragon slayer »

Okay so i came up with this idea creating necor potions based on a old script from old uox days. But i have one problem I'm not sure how to get this all function to just check for more then on item

like if i double click it and click they dragons blood it uses it and a empty bottle up. creates potion so i thought to my self awesome script well then i realized i had like 6 more to make and I'm not sure how to get the a necromantic mortar and pestle work on other reagents

Code: Select all

function onUseChecked ( pUser, iUsed ) 
{
	// get users socket
	var srcSock = pUser.socket;

	// is it in users pack?
	if( iUsed.container != null )
	{
		var iPackOwner = GetPackOwner( iUsed, 0 );
		if( iPackOwner.serial != pUser.serial )
		{
			pUser.SysMessage( "This has to be in your backpack!" );
		}
		else
			// let the user target the heat source
			srcSock.CustomTarget( 0, "What do you want to use the necromantic mortar and pestle with?" );
	}
	else
		pUser.SysMessage( "This has to be in your backpack!" );

	return false;
}

function onCallback0( tSock, targSerial )
{
	var pUser = tSock.currentChar;
        var pName = pUser.name;
	var StrangeByte   = tSock.GetWord( 1 );
	var targX	= tSock.GetWord( 11 );
	var targY	= tSock.GetWord( 13 );
	var targZ	= tSock.GetSByte( 16 );
	var tileID	= tSock.GetWord( 17 );
	if( tileID == 0 )
	{ //Target is a Maptile
		pUser.SysMessage("You cannot use necromantic mortar and pestle on that.");
	}
	else if( StrangeByte == 0 && targSerial.isChar )
	{ //Target is a Character
		pUser.SysMessage("You cannot use necromantic mortar and pestle on that.");
	}
	// Target is a Dynamic or Static Item
	if( tileID = 0x0f82 )
	{
		// remove one Dragon Blood
		var iMakeResource = pUser.ResourceCount( 0x0f82 );	// is there enough resources to use up to make it
                var iMakeResource2 = pUser.ResourceCount( 0x0E25 );
		if( iMakeResource < 1 )
		{
			pUser.SysMessage( "You don't seem to have any dragon blood!" );
			return;
		}
		else if( iMakeResource2 < 1)
		{
			pUser.SysMessage( "You don't seem to have any empty dragon blood bottles!" );
			return;
		}
		pUser.UseResource( 1, 0x0f82 ); // uses up a resource (amount, item ID, item colour)
                pUser.UseResource( 1, 0x0E25 );
		pUser.SoundEffect( 0x0246, true );
                pUser.DoAction( 0x22 );
		// check the skill
		if( !pUser.CheckSkill( 13, 0, 300 ) )	// character to check, skill #, minimum skill, and maximum skill
		{
			pUser.SysMessage( "You are too afraid and spill the liquid all over you." );
			return;
		}
		var itemMade = CreateDFNItem( pUser.socket, pUser, "dragonsbloodpotion", 1, "ITEM", true ); // makes dragons blood potion
                pUser.SysMessage( "A bottle materializes to form around the liquid." );
		pUser.EmoteMessage( pName+ " Grinds the Dragon's Blood successfully into a potion." );
	}
}
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 »

My suggestion:

Code: Select all

function onUseChecked ( pUser, iUsed ) 
 { 
    // get users socket 
    var srcSock = pUser.socket; 

    // is it in users pack? 
    if( iUsed.container != null ) 
    { 
       var iPackOwner = GetPackOwner( iUsed, 0 ); 
       if( iPackOwner.serial != pUser.serial ) 
       { 
          pUser.SysMessage( "This has to be in your backpack!" ); 
       } 
       else 
          // let the user target the heat source 
          srcSock.CustomTarget( 0, "What do you want to use the necromantic mortar and pestle with?" ); 
    } 
    else 
       pUser.SysMessage( "This has to be in your backpack!" ); 

    return false; 
 } 

 function onCallback0( tSock, targSerial ) 
 { 
    var pUser = tSock.currentChar; 
    var pName = pUser.name; 
    var StrangeByte   = tSock.GetWord( 1 ); 
    var targX   = tSock.GetWord( 11 ); 
    var targY   = tSock.GetWord( 13 ); 
    var targZ   = tSock.GetSByte( 16 ); 
    var tileID   = tSock.GetWord( 17 ); 
    
    if( tileID == 0 ) 
    { //Target is a Maptile 
       pUser.SysMessage("You cannot use necromantic mortar and pestle on that."); 
    } 
    else if( StrangeByte == 0 && targSerial.isChar ) 
    { //Target is a Character 
       pUser.SysMessage("You cannot use necromantic mortar and pestle on that."); 
    } 
    else
    {
	    var resourceType = 0;
	    var resourceName = "";
	    var bottleType = 0;
	    var bottleName = "";
	    var potionName = "";
	    
    	// Target is a Dynamic or Static Item 
    	if( tileID == 0x0f82 ) 
    	{ 
		    resourceType = 0x0f82;
	    	resourceName = "Dragon's Blood";
	    	bottleType = 0x0e25;
	    	bottleName = "Dragon's Blood bottle";
	    	potionName = "dragonsbloodpotion";
    	}
    	else if( tileID == 0x0f83 )
    	{
		    resourceType = 0x0f83;
	    	resourceName = "Mongbat Droppings";
	    	bottleType = 0x0e25;
	    	bottleName = "Mongbat Droppings bottle";
	    	potionName = "mongbatdroppingpotion";
    	}
    	else if( tileID == 0x#### )
    	{
	    	stuff
    	}
    
    	// Common stuff shared between all resourcetypes
    	var iMakeResource = pUser.ResourceCount( bottleType ); // is there enough bottles to use up to make it 
    	if( iMakeResource > 0 )
    	{
		    if( resourceType )
	    	{
			    var iMakeResource2 = pUser.ResourceCount( resourceType ); // is there enough resources to use up to make it 
		    	if( iMakeResource2 > 0 )
		    	{
				    pUser.UseResource( 1, resourceType ); // uses up a resource (amount, item ID, item colour)
			    	pUser.UseResource( 1, bottleType );
		       		pUser.SoundEffect( 0x0246, true ); 
       				pUser.DoAction( 0x22 ); 
       				// check the skill 
	       			if( !pUser.CheckSkill( 13, 0, 300 ) )   // character to check, skill #, minimum skill, and maximum skill 
       				{ 
	          			pUser.SysMessage( "You are too afraid and spill the liquid all over you." ); 
          				return; 
       				} 
       				var itemMade = CreateDFNItem( pUser.socket, pUser, potionName, 1, "ITEM", true ); // makes dragons blood potion 
                 	pUser.SysMessage( "A bottle materializes to form around the liquid." ); 
       				pUser.EmoteMessage( pName+ " grinds the " +resourceName +" successfully into a potion." ); 
		    	}
		    	else
			    	pUser.SysMessage( "You don't seem to have any " +resourceName+ "!" );
	    	}
    	}
    	else
	    	pUser.SysMessage( "You don't seem to have an empty "+bottleName+"!" );
    }
}
-= Ho Eyo He Hum =-
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

wow the way you used all that script and changed it all around.. make sme dream some day i might be as good as you :)
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 »

Hehe thanks. But what I did wasn't really all that difficult. All you need is the correct mindset; minimize, re-use, share resources.

Every time I work on a script I try to consider if there are ways I can minimize having to duplicate parts of the script several times, either by doing what I did in my suggestion above, and shove all the shared code to the very end, or even by separating those parts of the script into new stand-alone custom functions that could've been called from anywhere else in the script.
-= Ho Eyo He Hum =-
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

i was thinking that way and i wasnt sure how to go about it all hehe. my first atemp was to get all the functions under one target curser LOL. but failed so bad. But thats what like about this hole thing i learn something new every day at scripting and posting my scripts are helping me become better learn more about java and scripting uox3
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 »

Practice makes perfect :)
-= Ho Eyo He Hum =-
Post Reply