Page 1 of 1

problem with my seed script

Posted: Sun Dec 04, 2011 7:05 pm
by dragon slayer

Code: Select all

function onUseChecked( pUser, iUsed )
{
	var socket = pUser.socket;
	if( socket && iUsed && iUsed.isItem )
	{
		var itemOwner = GetPackOwner( iUsed, 0 );
		if( itemOwner == null || itemOwner.serial != pUser.serial )
		{
			pUser.SysMessage( "This must be in your backpack." );
			return false;
		}
		else if( iUsed.type != 15 )
		{
			var targMsg = GetDictionaryEntry( 443, socket.Language );
			socket.CustomTarget( 1, targMsg );
		}
		else
			return true;		
	}
	return false;
}

function onCallback1( socket, ourObj)
{
	var mChar = socket.currentChar;

	if( mChar && mChar.isChar )
	{
		var tileID = 0;
		if( socket.GetByte( 1 ) )
		{
			tileID = socket.GetWord( 17 );
			if( !tileID )
				tileID = GetTileIDAtMapCoord( socket.GetWord( 11 ), socket.GetWord( 13 ), mChar.worldNumber );
		}
		else if( ourObj && ourObj.isItem )
			tileID = ourObj.id;
			

		if( tileID != 0 )
		{
			if(tileID == 0x0009 || tileID == 0x0010 || tileID == 0x0011 || tileID == 0x0012 || tileID == 0x0013 || 
			   tileID == 0x0014 || tileID == 0x0015 ) // fields
			{	
		           // remove one seed
		           var iMakeResource = mChar.ResourceCount( 0x0f23 );	// is there enough resources to use up to make it
		           if( iMakeResource < 1 )
		           {
				mChar.SysMessage( "You don't seem to have any garlic seeds" );
				return;
		           }
		           if( mChar.skills[13] < 200 ) 
		           {
				mChar.SysMessage( "You are not skilled enough to do that." );
				return;
		           }
		           mChar.UseResource( 1, 0x0f23 ); // uses up a resource (amount, item ID, item colour)
		           mChar.SoundEffect( 0x0021, true );
		           // check the skill
		           if( !mChar.CheckSkill( 13, 100, 500 ) )	// character to check, skill #, minimum skill, and maximum skill
		           {
				mChar.SysMessage( "You dropped the seed" );
				return;
		           }
		           var itemMade = CreateDFNItem( mChar.socket, mChar, "garlicspawner", 1, "ITEM", false ); // places a garlic spawner.		           mChar.SysMessage( "You plant the seed." );
		           return;

			}
			else
		           socket.SysMessage( "You cannot plant seeds here." );
		}
		else
			socket.SysMessage( "You cannot plant seeds here." );
	}
}
problem I'm having is when my spawner is placed. the spawner doesn't spawn anything and sends the client tag errors saying tag 285 or 185 something something

its like the spawner broke seen as it was placed

One other problem I'm having is getting the item to be created where i point my target curser. instead just creates the item at my feet.

And on more thing is how do i get it to check for a nother spawner in that spot so doesn't place a spawner on top of one.

Posted: Sun Dec 04, 2011 9:29 pm
by Xuri
The item you create in the script through CreateDFNItem needs to be of type "SPAWNER" instead of type "ITEM", or the spawner-properties won't work.

As for the location of the item, you need to move it to the correct location after creating it. You can do that through (as long as the target wasn't a character, in which case socket.GetWord( 1 ) would be true):

Code: Select all

targX = socket.GetWord( 11 );
targY = socket.GetWord( 13 );
targZ = socket.GetSByte( 16 ) + GetTileHeight( socket.GetWord( 17 ) );
itemMade.Teleport( targX, targY, targZ );
To check if there's an existing item of the same ID in the target location, you could use something like this:

Code: Select all

targX = socket.GetWord( 11 ); 
targY = socket.GetWord( 13 ); 
targZ = socket.GetSByte( 16 ) + GetTileHeight( socket.GetWord( 17 ) );
var itemFound = FindItem( targX, targY, targZ, pUser.worldnumber, 0x04a9 ); //replace 0x04a9 with ID of your seed I guess
if( itemFound && itemFound.x == targX && itemFound.y == targY )
	pUser.SysMessage( "There is already a seed at that location." );
else
{
	<plant seed stuff here>
}
(Obviously you would only have to load the target location into targX and targY once, but I included it in both examples just to make it clearer)

Posted: Sun Dec 04, 2011 11:28 pm
by dragon slayer
thanks xuri that has worked like a charm.