Harvest Script V 1.3

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Harvest Script V 1.3

Post by stranf »

This is basically a hack-job of Xuri's plant scripts, but it works!

All plant statics are found in /dfndata/building/decs/plants/plants.dfn

They will need to be edited or overwritten.
Version 1.3
Able to harvest:

Corn
Onions
Carrots
yellow gourds and green gourds
watermelon
squash
pumpkins
turnips

Notable changes from version 1.2:
-Added pumpkins, watermelon, squash, and turnips.
-Fixed gourds so that they are actually vine growing plants instead of "grandmaster onions" oops...
-Fixed carrots so that they display as a CARROT instead of an ONION when fully grown. (I found a carrot static art that is not included in plants.def and used that id for the "carrot_plant" dfn. entry. Please update your plant.dfn and carrotpick.js. You do not need to erase your carrotOnions, just harvest the old carrots and they will grow back as new carrots! (the IDs are changed in the script)

Plans for v. 1.3: Add grapes and honeydew.
I ran out of time before school, but I was going to add both gourds. I also was planning on trying ot merge the apple script with the onion script. So that you don't pick all 6 onions at 1, but one at a time, and then the id for the onions growing dosen't begin until all 6 are picked.

If someone wants to merge the code, sweet! post the changes. If not, I will attempt it when I get free time again.
[/quote]
Last edited by stranf on Thu Mar 29, 2007 7:46 pm, edited 3 times in total.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

DFN changes.

Please create a new .dfn file (I used custom_plants.dfn) and import these entries (this will ensure that your custom content will not be over-written if updating to a new plants.dfn).
[0xc6f]
{
get=base_item
name=onions
id=0x0c6f
weight=5
decay=0
script=2014
}

[carrot_plant]
{
get=base_item
name=carrots
id=0x0c76
weight=5
decay=0
script=2015
}

[yellowgourd_left]
{
get=base_item
name=yellow gourd
id=0x0c65
weight=5
decay=0
script=2016
movable=3
}

[yellowgourd_right]
{
get=base_item
name=yellow gourd
id=0x0c64
weight=5
decay=0
script=2016
movable=3
}

[greengourd_left]
{
get=base_item
name=green gourd
id=0x0c66
weight=5
decay=0
script=2017
movable=3
}

[greengourd_right]
{
get=base_item
name=green gourd
id=0x0c67
weight=5
decay=0
script=2017
movable=3
}

[squash_right]
{
get=base_item
name=squash
id=0x0c73
weight=5
decay=0
script=2020
movable=3
}

[squash_left]
{
get=base_item
name=squash
id=0x0c72
weight=5
decay=0
script=2020
movable=3
}

[vine_end]
{
get=base_item
name=vine
id=0x0c60
weight=5
decay=0
}


[vine_middle]
{
get=base_item
name=vine
id=0x0c5e
weight=5
decay=0
}


[vine_top]
{
get=base_item
name=vine
id=0x0c5f
weight=5
decay=0
}

[watermelon_plant]
{
get=base_item
name=watermelon
id=0x0c5d
weight=5
decay=0
script=2018
movable =3
}

[pumpkin_plant]
{
get=base_item
name=pumpkin
id=0x0c6c
weight=5
decay=0
script=2019
movable=3
}

[turnip_plant]
{
get=base_item
name=turnips
id=0x0c63
weight=5
script=2021
decay=0
}

[0xc7d]
{
get=base_item
name=corn stalk
id=0x0c7d
weight=5
script=2013
decay=0
}

[grapevile_leftend]
{
get=base_item
name=grapevine
id=0x0c7d
weight=5
script=2013
decay=0
}

Please add the following lines to your jsfileassciations.txt:

2013=custom/cornpick.js
2014=custom/onionpick.js
2015=custom/carrotpick.js
2016=custom/yellowgourd.js
2017=custom/greengourd.js
2018=custom/watermelon.js
2019=custom/pumpkin.js
2020=custom/squash.js
2021=custom/turnippick.js
NOTE: IF 2013-21 are unavailable to use (due to future updates/and/or custom content, please adjust the "script=" tag in the above dfn file. PM if you need help
Last edited by stranf on Thu Mar 29, 2007 7:53 pm, edited 4 times in total.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Please save the following code as "onionpick.js"
// Onion picking script
// An edit of Xuri's Wheatpicking script
// by Stranf
// 20/02/2006 Xuri; xuri@sensewave.com
// When (dynamic)wheat is double-clicked, it's setup with
// wheat ripe for picking. When it is harvested it turns into "harvested wheat",
// and a "growth" process happens, where the wheat goes through various stages
// like "sprouts", short wheat and finally becomes harvestable tall wheat again.
var resourceGrowthDelay = 60000; //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 wheats have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1);     // Marks what as initialized
        iUsed.SetTag("Onion",1);        // If set to 1, there is Onion to be picked, if 0 there is no wheat left
        iUsed.SetTag("OnionCounter", maxResource);  // Add 6 Onions to the tile
    }
   
    var Onion = iUsed.GetTag("Onion");
    var OnionCount = iUsed.GetTag("OnionCounter");
    if (Onion == 0)
    {  
        pUser.SysMessage( "These Onions are not ready for harvesting." );
        return false;
    }
    if( Onion == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail to pick any Onions." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick some Onions." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c6d", 1, "ITEM", true );
            OnionCount--;
            iUsed.SetTag( "OnionCounter", OnionCount );
            if( OnionCount == 1)
                pUser.SysMessage( "There is "+OnionCount+" 1 Onion left." );
            else
                pUser.SysMessage( "There are "+OnionCount+" ripe Onions left." );
                if( OnionCount == 0 )
            {
               
                iUsed.id = 0xc68;
                iUsed.SetTag( "Onion", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time Onion respawn
            }

       
           
        }
        return false;
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 ) // Starts faze 1 of wheat growth
    {
        iUsed.id = 0xc68;
//      iUsed.KillTimers();
        iUsed.StartTimer( 60000, 2, true);
    }
    if( timerID == 2 ) // Starts faze 2 of wheat growth
    {
        iUsed.id = 0xc69;
//      iUsed.KillTimers();        
        iUsed.StartTimer( 60000, 4, true );
    }
   

    if( timerID == 4 ) // Wheat growth finished!
    {
        iUsed.id = 0xc6f;
    //  iUsed.KillTimers();
        iUsed.SetTag("OnionCounter", maxResource); 
        iUsed.SetTag("Onion", 1);

    }

}
Please save the following as cornpick.js
// Corn-Picking Script
// Edit of Xuri's Corn-Picking Script by Stranf
// replace "Corn" in comments by "corn"
// 20/02/2006 Xuri; xuri@sensewave.com
// When a (dynamic) Corn tree is double-clicked, it's setup with
// 3 Corns ripe for picking. After they've been picked, a timer starts,
// and until it's up no more Corns can be picked. Once the timer is over,
// new Corns are added. The apperance of the tree indicates whether or
// not there are any Corns left to pick.

// ** Corn does not change it's appearance.  I can't find an animation that shows a barren
//cornstalk**
// **Corn stalk will contain 3 ears of corn per stalk**
var resourceGrowthDelay = 120000; //Delay in milliseconds before resources respawns
var maxResource = 3; //maximum amount of resources on a given item

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 Corns have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1 );    // Marks tree as initialized
        iUsed.SetTag("Corn",1);         // If set to 1, there are Corn to be picked, if 0 there are no ripe Corn
        iUsed.SetTag("CornCounter", maxResource);   // Add 5 Corn to the tree initially
    }
    var Corn = iUsed.GetTag("Corn");
    var CornCount = iUsed.GetTag("CornCounter");
    if (Corn == 0)
    {  
        pUser.SysMessage( "You find no ripe corn to pick. Try again later." );
    }
    if( Corn == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail to find any ripe corn." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick an ear of corn." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c7f", 1, "ITEM", true );
            CornCount--;
            iUsed.SetTag( "CornCounter", CornCount );
            if( CornCount == 1)
                pUser.SysMessage( "There is "+CornCount+" ear of corn on the stalk.");
            else
                pUser.SysMessage( "There are "+CornCount+" ripe ears of corn left on the stalk." );
                if( CornCount == 0 )
            {
                iUsed.SetTag( "Corn", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time Corn respawn
            }
        }
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 )
    {
        iUsed.SetTag("CornCounter", maxResource);
        iUsed.SetTag("Corn", 1);
       
    }
}
save the following as carrotpick.js
// Carrot picking script
// An edit of Xuri's Wheatpicking script
// by Stranf
// 20/02/2006 Xuri; xuri@sensewave.com
// When (dynamic)wheat is double-clicked, it's setup with
// wheat ripe for picking. When it is harvested it turns into "harvested wheat",
// and a "growth" process happens, where the wheat goes through various stages
// like "sprouts", short wheat and finally becomes harvestable tall wheat again.
var resourceGrowthDelay = 60000; //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 wheats have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1);     // Marks what as initialized
        iUsed.SetTag("Carrot",1);       // If set to 1, there is carrot to be picked, if 0 there is no wheat left
        iUsed.SetTag("CarrotCounter", maxResource);     // Add 6 carrots to the tile
    }
   
    var Carrot = iUsed.GetTag("Carrot");
    var CarrotCount = iUsed.GetTag("CarrotCounter");
    if (Carrot == 0)
    {  
        pUser.SysMessage( "These carrots are not ready for harvesting." );
        return false;
    }
    if( Carrot == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail to pick any carrots." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick some carrots." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c77", 1, "ITEM", true );
            CarrotCount--;
            iUsed.SetTag( "CarrotCounter", CarrotCount );
            if( CarrotCount == 1)
                pUser.SysMessage( "There is "+CarrotCount+" 1 carrot left." );
            else
                pUser.SysMessage( "There are "+CarrotCount+" ripe carrots left." );
                if( CarrotCount == 0 )
            {
               
                iUsed.id = 0xc68;
                iUsed.SetTag( "Carrot", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time Carrot respawn
            }

       
           
        }
        return false;
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 ) // Starts faze 1 of wheat growth
    {
        iUsed.id = 0xc68;
//      iUsed.KillTimers();
        iUsed.StartTimer( 60000, 2, true);
    }
    if( timerID == 2 ) // Starts faze 2 of wheat growth
    {
        iUsed.id = 0xc69;
//      iUsed.KillTimers();        
        iUsed.StartTimer( 60000, 4, true );
    }
   

    if( timerID == 4 ) // Wheat growth finished!
    {
        iUsed.id = 0xc76;
    //  iUsed.KillTimers();
        iUsed.SetTag("Carrot", 1);
        iUsed.SetTag("CarrotCounter", maxResource);
    }

}
save the following as yellowgourd.js

// gourd-Picking Script
// Edit of Xuri's gourd-Picking Script by Stranf
// replace "gourd" in comments by "gourd"
// 20/02/2006 Xuri; xuri@sensewave.com
// When a (dynamic) gourd tree is double-clicked, it's setup with
// 3 gourds ripe for picking. After they've been picked, a timer starts,
// and until it's up no more gourds can be picked. Once the timer is over,
// new gourds are added. The apperance of the tree indicates whether or
// not there are any gourds left to pick.

// ** gourd does not change it's appearance.  I can't find an animation that shows a barren
//gourdstalk**
// **gourd stalk will contain 3 ears of gourd per stalk**
var resourceGrowthDelay = 120000; //Delay in milliseconds before resources respawns
var maxResource = 3; //maximum amount of resources on a given item

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 gourds have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1 );    // Marks tree as initialized
        iUsed.SetTag("gourd",1);        // If set to 1, there are gourd to be picked, if 0 there are no ripe gourd
        iUsed.SetTag("gourdCounter", maxResource);  // Add 3 gourd to the tree initially
    }
    var gourd = iUsed.GetTag("gourd");
    var gourdCount = iUsed.GetTag("gourdCounter");
    if (gourd == 0)
    {  
        pUser.SysMessage( "You are unable to find a ripe gourd to pick. Try again later." );
    }
    if( gourd == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail a ripe gourd." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick an ear of gourd." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c65", 1, "ITEM", true );
            gourdCount--;
            iUsed.SetTag( "gourdCounter", gourdCount );
            if( gourdCount == 1)
                pUser.SysMessage( "There is "+gourdCount+" ripe gourd left.");
            else
                pUser.SysMessage( "There are "+gourdCount+" gourds left." );
                if( gourdCount == 0 )
            {
                iUsed.SetTag( "gourd", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time gourd respawn
            }
        }
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 )
    {
        iUsed.SetTag("gourdCounter", maxResource);
        iUsed.SetTag("gourd", 1);
       
    }
}
Save the following as greengourd.js
// gourd-Picking Script
// Edit of Xuri's gourd-Picking Script by Stranf
// replace "gourd" in comments by "gourd"
// 20/02/2006 Xuri; xuri@sensewave.com
// When a (dynamic) gourd tree is double-clicked, it's setup with
// 3 gourds ripe for picking. After they've been picked, a timer starts,
// and until it's up no more gourds can be picked. Once the timer is over,
// new gourds are added. The apperance of the tree indicates whether or
// not there are any gourds left to pick.

// ** gourd does not change it's appearance.  I can't find an animation that shows a barren
//gourdstalk**
// **gourd stalk will contain 3 ears of gourd per stalk**
var resourceGrowthDelay = 120000; //Delay in milliseconds before resources respawns
var maxResource = 3; //maximum amount of resources on a given item

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 gourds have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1 );    // Marks tree as initialized
        iUsed.SetTag("gourd",1);        // If set to 1, there are gourd to be picked, if 0 there are no ripe gourd
        iUsed.SetTag("gourdCounter", maxResource);  // Add 3 gourd to the tree initially
    }
    var gourd = iUsed.GetTag("gourd");
    var gourdCount = iUsed.GetTag("gourdCounter");
    if (gourd == 0)
    {  
        pUser.SysMessage( "You are unable to find a ripe gourd to pick. Try again later." );
    }
    if( gourd == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail a ripe gourd." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick an ear of gourd." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c66", 1, "ITEM", true );
            gourdCount--;
            iUsed.SetTag( "gourdCounter", gourdCount );
            if( gourdCount == 1)
                pUser.SysMessage( "There is "+gourdCount+" ripe gourd left.");
            else
                pUser.SysMessage( "There are "+gourdCount+" gourds left." );
                if( gourdCount == 0 )
            {
                iUsed.SetTag( "gourd", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time gourd respawn
            }
        }
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 )
    {
        iUsed.SetTag("gourdCounter", maxResource);
        iUsed.SetTag("gourd", 1);
       
    }
}
Save the following as turnippick.js
// turnip picking script
// An edit of Xuri's Wheatpicking script
// by Stranf
// 20/02/2006 Xuri; xuri@sensewave.com
// When (dynamic)wheat is double-clicked, it's setup with
// wheat ripe for picking. When it is harvested it turns into "harvested wheat",
// and a "growth" process happens, where the wheat goes through various stages
// like "sprouts", short wheat and finally becomes harvestable tall wheat again.
var resourceGrowthDelay = 60000; //Delay in milliseconds before resources respawns
var maxResource =3;

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 wheats have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1);     // Marks what as initialized
        iUsed.SetTag("turnip",1);       // If set to 1, there is turnip to be picked, if 0 there is no wheat left
        iUsed.SetTag("turnipCounter", maxResource);     // Add 3 turnips to the tile
    }
   
    var turnip = iUsed.GetTag("turnip");
    var turnipCount = iUsed.GetTag("turnipCounter");
    if (turnip == 0)
    {  
        pUser.SysMessage( "These turnips are not ready for harvesting." );
        return false;
    }
    if( turnip == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail to pick any turnips." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick some turnips." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0d39", 1, "ITEM", true );
            turnipCount--;
            iUsed.SetTag( "turnipCounter", turnipCount );
            if( turnipCount == 1)
                pUser.SysMessage( "There is "+turnipCount+" 1 turnip left." );
            else
                pUser.SysMessage( "There are "+turnipCount+" ripe turnips left." );
                if( turnipCount == 0 )
            {
               
                iUsed.id = 0xc61;
                iUsed.SetTag( "turnip", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time turnip respawn
            }

       
           
        }
        return false;
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 ) // Starts faze 1 of wheat growth
    {
        iUsed.id = 0xc61;
//      iUsed.KillTimers();
        iUsed.StartTimer( 60000, 2, true);
    }
    if( timerID == 2 ) // Starts faze 2 of wheat growth
    {
        iUsed.id = 0xc62;
//      iUsed.KillTimers();        
        iUsed.StartTimer( 60000, 4, true );
    }
   

    if( timerID == 4 ) // Turnip! growth finished!
    {
        iUsed.id = 0xc63;
    //  iUsed.KillTimers();
        iUsed.SetTag("turnip", 1);
        iUsed.SetTag("turnipCounter", maxResource);
    }

}
save the following as watermelon.js
// Watermelon-Picking Script
// Edit of Xuri's Watermelon-Picking Script by Stranf
// replace "Watermelon" in comments by "Watermelon"
// 20/02/2006 Xuri; xuri@sensewave.com
// When a (dynamic) Watermelon tree is double-clicked, it's setup with
// 3 Watermelons ripe for picking. After they've been picked, a timer starts,
// and until it's up no more Watermelons can be picked. Once the timer is over,
// new Watermelons are added. The apperance of the tree indicates whether or
// not there are any Watermelons left to pick.

// ** Watermelon does not change it's appearance.  I can't find an animation that shows a barren
//Watermelonstalk**
// **Watermelon stalk will contain 3 ears of Watermelon per stalk**
var resourceGrowthDelay = 120000; //Delay in milliseconds before resources respawns
var maxResource = 3; //maximum amount of resources on a given item

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 Watermelons have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1 );    // Marks tree as initialized
        iUsed.SetTag("Watermelon",1);       // If set to 1, there are Watermelon to be picked, if 0 there are no ripe Watermelon
        iUsed.SetTag("WatermelonCounter", maxResource);     // Add 3 Watermelon to the tree initially
    }
    var Watermelon = iUsed.GetTag("Watermelon");
    var WatermelonCount = iUsed.GetTag("WatermelonCounter");
    if (Watermelon == 0)
    {  
        pUser.SysMessage( "You find no ripe Watermelon to pick. Try again later." );
    }
    if( Watermelon == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail a ripe watermelon." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick an ear of Watermelon." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c5c", 1, "ITEM", true );
            WatermelonCount--;
            iUsed.SetTag( "WatermelonCounter", WatermelonCount );
            if( WatermelonCount == 1)
                pUser.SysMessage( "There is "+WatermelonCount+" ripe Watermelon left.");
            else
                pUser.SysMessage( "There are "+WatermelonCount+" Watermelons left." );
                if( WatermelonCount == 0 )
            {
                iUsed.SetTag( "Watermelon", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time Watermelon respawn
            }
        }
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 )
    {
        iUsed.SetTag("WatermelonCounter", maxResource);
        iUsed.SetTag("Watermelon", 1);
       
    }
}
save the following as pumpkin.js

/ pumpkin-Picking Script
// Edit of Xuri's pumpkin-Picking Script by Stranf
// replace "pumpkin" in comments by "pumpkin"
// 20/02/2006 Xuri; xuri@sensewave.com
// When a (dynamic) pumpkin tree is double-clicked, it's setup with
// 3 pumpkins ripe for picking. After they've been picked, a timer starts,
// and until it's up no more pumpkins can be picked. Once the timer is over,
// new pumpkins are added. The apperance of the tree indicates whether or
// not there are any pumpkins left to pick.

// ** pumpkin does not change it's appearance.  I can't find an animation that shows a barren
//pumpkinstalk**
// **pumpkin stalk will contain 3 ears of pumpkin per stalk**
var resourceGrowthDelay = 120000; //Delay in milliseconds before resources respawns
var maxResource = 3; //maximum amount of resources on a given item

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 pumpkins have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1 );    // Marks tree as initialized
        iUsed.SetTag("pumpkin",1);      // If set to 1, there are pumpkin to be picked, if 0 there are no ripe pumpkin
        iUsed.SetTag("pumpkinCounter", maxResource);    // Add 3 pumpkin to the tree initially
    }
    var pumpkin = iUsed.GetTag("pumpkin");
    var pumpkinCount = iUsed.GetTag("pumpkinCounter");
    if (pumpkin == 0)
    {  
        pUser.SysMessage( "You find no ripe pumpkin to pick. Try again later." );
    }
    if( pumpkin == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail to pick a ripe pumpkin." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick a pumpkin." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c6b", 1, "ITEM", true );
            pumpkinCount--;
            iUsed.SetTag( "pumpkinCounter", pumpkinCount );
            if( pumpkinCount == 1)
                pUser.SysMessage( "There is "+pumpkinCount+" ripe pumpkin left.");
            else
                pUser.SysMessage( "There are "+pumpkinCount+" pumpkins left." );
                if( pumpkinCount == 0 )
            {
                iUsed.SetTag( "pumpkin", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time pumpkin respawn
            }
        }
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 )
    {
        iUsed.SetTag("pumpkinCounter", maxResource);
        iUsed.SetTag("pumpkin", 1);
       
    }
}
save the following as squash.js
// squash-Picking Script
// Edit of Xuri's squash-Picking Script by Stranf
// replace "squash" in comments by "squash"
// 20/02/2006 Xuri; xuri@sensewave.com
// When a (dynamic) squash tree is double-clicked, it's setup with
// 3 squashs ripe for picking. After they've been picked, a timer starts,
// and until it's up no more squashs can be picked. Once the timer is over,
// new squashs are added. The apperance of the tree indicates whether or
// not there are any squashs left to pick.

// ** squash does not change it's appearance.  I can't find an animation that shows a barren
//squashstalk**
// **squash stalk will contain 3 ears of squash per stalk**
var resourceGrowthDelay = 120000; //Delay in milliseconds before resources respawns
var maxResource = 3; //maximum amount of resources on a given item

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 squashs have been picked before, initialize settings
    {
        iUsed.SetTag("initialized", 1 );    // Marks tree as initialized
        iUsed.SetTag("squash",1);       // If set to 1, there are squash to be picked, if 0 there are no ripe squash
        iUsed.SetTag("squashCounter", maxResource);     // Add 3 squash to the tree initially
    }
    var squash = iUsed.GetTag("squash");
    var squashCount = iUsed.GetTag("squashCounter");
    if (squash == 0)
    {  
        pUser.SysMessage( "You are unable to find a ripe squash to pick. Try again later." );
    }
    if( squash == 1 )
    {
        iUsed.SoundEffect( 0x0050, true );
        var loot = RollDice( 1, 3, 0 );
        if( loot == 2 )
            pUser.SysMessage( "You fail a ripe squash." );
        if( loot == 3 || loot == 1 )
        {
            pUser.SysMessage( "You pick an ear of squash." );
            var itemMade = CreateDFNItem( pUser.socket, pUser, "0x0c72", 1, "ITEM", true );
            squashCount--;
            iUsed.SetTag( "squashCounter", squashCount );
            if( squashCount == 1)
                pUser.SysMessage( "There is "+squashCount+" ripe squash left.");
            else
                pUser.SysMessage( "There are "+squashCount+" squashes left." );
                if( squashCount == 0 )
            {
                iUsed.SetTag( "squash", 0 );
                iUsed.StartTimer( resourceGrowthDelay, 1, true ); // Puts in a delay until next time squash respawn
            }
        }
    }
    return false;
}

function onTimer( iUsed, timerID )
{
    if( timerID == 1 )
    {
        iUsed.SetTag("squashCounter", maxResource);
        iUsed.SetTag("squash", 1);
       
    }
}
Last edited by stranf on Thu Mar 29, 2007 8:01 pm, edited 2 times in total.
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 »

Nice, stranf :) You might want to change all the "wheat"-tags that are saved on the items to the specific resources that the scripts are for though, just for consistency. =)
-= Ho Eyo He Hum =-
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Yeah, Xu, there are few things like that.

I figure the "wheat" tag didn't effect the code. I had 45 minutes to spare before class, and I wanted to debug, and test each vegetable before I left... Oh and post it on dialup. 8)

Yeah...I was late for class!

Anyway, I'm going to mix the Wheat script with the apple Script for the onions and carrots, instead of getting all 6 veggies at once, have them pick them until 6 are gone (like the apples), and then run the regrow script growing all 6 come back.


Oh, and another bad programming technique: I have the computer pick a random number between 1 and 2 to decide if it is going to grow the exact same onion tile when the onions grow. :)

I didn't want to remove that timer due to time (if you butcher scripts you tend to debug more). I will clean them up when I can.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

1.3 released with corrected gourds, squash, watermelon, turnips and pumpkins.


Tricks for new users:

The new DFNs include vines for your vine growing plants. So to set up a good garden, first drop the harvestable fruits. Use the .dfn tag entry to add them.

For example 'add item squash_right will drop a sqaush with the stem facing right.

Now use either vine_end vine_middle or vine_top to cover the fruit with the vine. Notice that vine fruites are set to movable 3. This setting allows them to be immovable but still highlight when you put the mouse around them. This makes it easier to drop watermelons and other fruit that would get invisible under thick vines.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Add this fix to the turnip entry in

dfndata/items/misc/foods2.dfn

Code: Select all

[0x0d39]
{
get=base_food
name=turnip
id=0x0d39
value=6 3
pileable=1
}

The orignial turnip had a hex value for the "grown" turnip static and not the harvested/stackable stactic. Don't forget to change the name in the [] as well.
Post Reply