harvest reagent script 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

harvest reagent script problem

Post by dragon slayer »

I know i ask a lot of you xuri but i think i found a bug in harvesting,
I used they idea you guys had on picking apples and what not on my reagent harvesting script. and ran into one problem.

When you get done picking all the resources off the plant it chnages its ID but timer doesn't never start back up. even knowing we have them set to start again

Code: Select all

var resourceGrowthDelay = 10000; //Delay in milliseconds before resources respawns 
var maxResource =6; 

function onUseChecked( pUser, iUsed ) 
{ 
   var isInRange = pUser.InRange( iUsed, 3 ); 
   if( !isInRange ) 
    { 
      pUser.SysMessage( "You are too far away to reach that." ); 
      return false; 
   } 

   if( !iUsed.GetTag("initialized")) // Unless Mandrake have been picked before, initialize settings 
   { 
      iUsed.SetTag("initialized", 1);    // Marks what as initialized 
      iUsed.SetTag("Mandrake",1);       // If set to 1, there is Mandrake to be picked, if 0 there is no mandrake left 
      iUsed.SetTag("MandrakeCounter", maxResource);    // Add 6 Mandrakes to the tile 
   } 
    
   var Mandrake = iUsed.GetTag("Mandrake"); 
   var MandrakeCount = iUsed.GetTag("MandrakeCounter"); 
   if (Mandrake == 0) 
   {    
      pUser.SysMessage( "These Mandrakes are not ready for harvesting." );
   } 
   if( Mandrake == 1 ) 
   { 
      iUsed.SoundEffect( 0x0050, true ); 
      var loot = RollDice( 1, 3, 0 ); 
      if( loot == 2 ) 
         pUser.SysMessage( "You fail to pick any Mandrake." ); 
      if( loot == 3 || loot == 1 ) 
       { 
         pUser.SysMessage( "You pick some Mandrake." ); 
         var itemMade = CreateDFNItem( pUser.socket, pUser, "0x18DD", 1, "ITEM", true ); 
         MandrakeCount--; 
         iUsed.SetTag( "MandrakeCounter", MandrakeCount ); 
         if( MandrakeCount == 1) 
            pUser.SysMessage( "There is "+MandrakeCount+" Mandrake left." ); 
         else 
            pUser.SysMessage( "There are "+MandrakeCount+" ripe Mandrakes left." ); 
         if( MandrakeCount == 0 ) 
         { 
            iUsed.id = 0x0C7B;  
            iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time Mandrake respawn 
            iUsed.SetTag( "Mandrake", 0 );
         } 
      } 
      return false; 
   } 
   return false; 
} 

function onTimer( iUsed, timerID ) 
{ 
   if( timerID == 1 ) // Starts phase 1 of Mandrake growth 
   { 
      iUsed.id = 0x18DF; 
      iUsed.StartTimer( 10000, 2, true); 
   } 
   if( timerID == 2 ) // Starts phase 2 of Mandrake growth 
   { 
      iUsed.id = 0x18E0;     
      iUsed.StartTimer( 10000, 4, true ); 
   }
   if( timerID == 4 ) // Mandrake growth finished! 
   { 
      iUsed.id = 0x18E0; 
      iUsed.SetTag("MandrakeCounter", maxResource);    
      iUsed.SetTag("Mandrake", 1); 

   } 

} 
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 »

Tested your script just now, and it seemed to work fine?

What I did while testing
- Reduced the timers from 10000 to 2000 for easier testing
- 'ADD 0x18E0
- 'SETSCPTRIG # (the script id I assigned to the script)
- Doubleclicked the mandrake object like mad until it was out of resources
- Watched ID change over the various stages of your timers
- Harvested again. Rince & repeat.
-= 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 »

hmm might be me then hehe well if it worked for you I'm going to get all the farming reagent stuff together and post it :) its beautiful :) great for roleplaying shards
Post Reply