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);
}
}