Apiculture v0.1

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Apiculture v0.1

Post by dragon slayer »

This is just the basic Apiculture Beehive. Requires no personal care or anything will just produce honey every 23 hours. you can change this number.

Once it hits the max Honey of 20 it will not produce any more honey and you can extract the honey by going to the production gump and clicking on the honey jar. if you have empty bottles in you backpack.
Takes 3 honey to make a jar of honey.

Drop it in your js folder any where and add script number 5032 to your js file if it is not used.

First you will need both of this items for.
[beehive]
{
get=base_item
name=Bee Hive
id=2330
weight=100
script=5032
}

[bees]
{
get=base_item
name=Bee's
id=0x91b
weight=100
}
Here is the Code
///////////////////////////////////////////
// Apiculture Version 0.1                //
// Written by Dragon Slayer              //
///////////////////////////////////////////

var hivestage = 0; //growth stage
var honey = 0; //amount of Honey
var maxhoney = 20; // Max Amount of Honey it can hold Chnage this number to your liking
const scriptID = 5032;
const BeeHiveTimer = 82800000; // This is 23 Hours before it will go to the next stage and produce honey.

function onUseChecked(pUser, iUsed)
{
    var socket = pUser.socket;
    socket.tempObj = iUsed;
    var BeeHiveGump = new Gump;
    var gumpID = scriptID + 0xffff;
    socket.CloseGump(gumpID, 0);

    iUsed.StartTimer(BeeHiveTimer, 0, true);

    BeeHiveGump.AddPage(0);
    BeeHiveGump.AddBackground(37, 26, 205, 161, 3600);

    //vines
    BeeHiveGump.AddPicture(12, 91, 3307);
    BeeHiveGump.AddPicture(11, 24, 3307);
    BeeHiveGump.AddPicture(206, 87, 3307);
    BeeHiveGump.AddPicture(205, 20, 3307);

    BeeHiveGump.AddGump(101, 66, 1417);  //circle thing
    BeeHiveGump.AddPicture(118, 89, 2330);   //beehive

    //status icons
    BeeHiveGump.AddPicture(44, 49, 5154);//honey

    //corner boxes
    BeeHiveGump.AddGump(34, 20, 210);
    BeeHiveGump.AddGump(228, 20, 210);
    BeeHiveGump.AddGump(34, 172, 210);
    BeeHiveGump.AddGump(228, 172, 210);

    AddLevel(BeeHiveGump)

    BeeHiveGump.AddButton(58, 46, 212, 212, 1, 0, 1);//Button to open production gump

    BeeHiveGump.Send(pUser);
    BeeHiveGump.Free();
}

function AddLevel(BeeHiveGump)
{
    BeeHiveGump.AddText(30, 20, 0x481, " " + hivestage );
}

function BeeHiveProductionGump(pUser, iUsed)
{
    var socket = pUser.socket;
    socket.tempObj = iUsed;
    var BeeHiveGump = new Gump;
    var gumpID = scriptID + 0xffff;
    socket.CloseGump(gumpID, 0);

    BeeHiveGump.AddPage(0);

    BeeHiveGump.AddBackground(37, 133, 205, 54, 3600);
    BeeHiveGump.AddBackground(37, 67, 205, 80, 3600);
    BeeHiveGump.AddBackground(37, 26, 205, 55, 3600);


    BeeHiveGump.AddPicture(12, 91, 3307);
    BeeHiveGump.AddPicture(11, 24, 3307);
    BeeHiveGump.AddPicture(206, 87, 3307);
    BeeHiveGump.AddPicture(205, 20, 3307);

    BeeHiveGump.AddPicture(76, 99, 5154);
    BeeHiveGump.AddPicture(149, 97, 2540);

    if (hivestage == 0)
    {//too early to produce
        BeeHiveGump.AddText(185, 97, 37, "X");
    }
    else
    {
        BeeHiveGump.AddText(185, 97, 0x481, " " + honey);
    }

    BeeHiveGump.AddText(110, 43, 92, "Production");

    BeeHiveGump.AddPicture(44, 47, 6256);
    BeeHiveGump.AddPicture(191, 151, 2540);

    BeeHiveGump.AddPicture(42, 153, 5154);

    BeeHiveGump.AddGump(162, 96, 212);
    BeeHiveGump.AddGump(90, 96, 212);

    BeeHiveGump.AddButton(204, 150, 212, 212, 1, 0, 2);//get honey
    BeeHiveGump.AddButton(57, 43, 212, 212, 1, 0, 3);//exit back to home gump

    BeeHiveGump.Send(pUser);
    BeeHiveGump.Free();
}

function onTimer(myObj, timerID)
{
    var basehoney = 0;
    if (!ValidateObject(myObj))
        return;

    switch (timerID)
    {
        case 0:
            myObj.SetTag("BeeStatus", 1)
            myObj.StartTimer(BeeHiveTimer, 1, true);
            break;
        case 1:
            hivestage = 1;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 2, true);
            break;
        case 2:
            hivestage = 2;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 3, true);
            break;
        case 3:
            hivestage = 3;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 4, true);
            break;
        case 4:
            hivestage = 4;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 5, true);
            break;
        case 5:
            hivestage = 5;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 6, true);
            break;
        case 6:
            hivestage = 6;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 7, true);
            break;
        case 7:
            hivestage = 7;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 8, true);
            break;
        case 8:
            hivestage = 8;
            if (honey < maxhoney)
            {
                basehoney++;
                honey += basehoney;
            }
            myObj.StartTimer(BeeHiveTimer, 8, true);
            break;
    }
}

function onGumpPress(socket, pButton, gumpData)
{
    var pUser = socket.currentChar;
    var iUsed = socket.tempObj;
    switch (pButton)
    {
        case 0:
            break;
        case 1:
            TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
            break;
        case 2:
            var iMakeResource = pUser.ResourceCount(0x0F0E);
            if (honey < 3)
            {
                socket.SysMessage("There isn't enough honey in the hive to fill a bottle!");
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
            if (iMakeResource)
            {
                honey -= 3;
                CreateDFNItem(socket, pUser, "0x09EC", 1, "ITEM", true);
                socket.SysMessage("You fill a bottle with golden honey and place it in your pack.");
                pUser.UseResource(1, 0x0F0E);
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
            else
            {
                socket.SysMessage("You need a bottle to fill with honey!");
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
        case 3:
            TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
            break;
    }
}
These users thanked the author dragon slayer for the post:
Xuri
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 »

Version 0.2
Features Hp for the beehive and damage

Redid all global values as tags to keep from breaking during gameplay thanks to xuri for all the help on it.
Added you can push the poison button and add up to two poison potions to kill parasites.
Redid the hole timer to only need one timer id to run it and loop.
Added new functions for each sections so they can be easily changed without looking though a lot of code.
The plant will check for parasites at a small value and if it hits that value your plant will get parasites. if you have poison pots on the plant it will kill the parasites.

parasites will kill your plant and they plant will change status as it loses HP. when it dies. next time you open it will collapse.
Then you will have to get a new hive.

if the hive is thriving it will produce honey.


///////////////////////////////////////////
// Apiculture Version 0.2                //
// Written by Dragon Slayer              //
///////////////////////////////////////////

const scriptID = 5032;
const BeeHiveTimer = 82800000; // This is 23 Hours before it will go to the next stage and produce honey.

function onUseChecked(pUser, iUsed)
{
    var socket = pUser.socket;
    socket.tempObj = iUsed;
    var BeeHiveGump = new Gump;
    var gumpID = scriptID + 0xffff;
    socket.CloseGump(gumpID, 0);

    if (iUsed.GetTag("Dead"))
    {
        socket.SysMessage("your bee hive has collapsed");
        iUsed.Delete();
    }

    if (!iUsed.GetTag("init"))
    {
        iUsed.SetTag("Health", 10);
        iUsed.SetTag("Parasite", 0)
        iUsed.SetTag("init", true);
    }

    if (iUsed.GetTag("beestatus") == 0)
    {
        iUsed.StartTimer(BeeHiveTimer, 0, true);
    }

    BeeHiveGump.AddPage(0);
    BeeHiveGump.AddBackground(37, 26, 205, 161, 3600);

    //vines
    BeeHiveGump.AddPicture(12, 91, 3307);
    BeeHiveGump.AddPicture(11, 24, 3307);
    BeeHiveGump.AddPicture(206, 87, 3307);
    BeeHiveGump.AddPicture(205, 20, 3307);

    BeeHiveGump.AddGump(101, 66, 1417);  //circle thing
    BeeHiveGump.AddPicture(118, 89, 2330);   //beehive

    //potions
    //BeeHiveGump.AddPicture(195, 46, 3848);//heal
    //BeeHiveGump.AddPicture(185, 96, 3847);// cure
    BeeHiveGump.AddPicture(198, 71, 3850); //poison
    //BeeHiveGump.AddPicture(183, 121, 3852);
    //BeeHiveGump.AddPicture(186, 146, 3849);

    //status icons
    BeeHiveGump.AddPicture(44, 49, 5154);//honey
    BeeHiveGump.AddPicture(-5, 76, 882); //little bug thing

    //corner boxes
    BeeHiveGump.AddGump(34, 20, 210);
    BeeHiveGump.AddGump(228, 20, 210);
    BeeHiveGump.AddGump(34, 172, 210);
    BeeHiveGump.AddGump(228, 172, 210);

    //boxes around status icons
    BeeHiveGump.AddGump(58, 71, 212);  //infestation

    BeeHiveGump.AddText(188, 71, 0x481, " " + iUsed.GetTag("PoisonPot"));   //poison

    //status labels
    switch (iUsed.GetTag("Parasite"))  //parasites
    {
        case 1: BeeHiveGump.AddText(81, 71, 52, "-"); break;
        case 2: BeeHiveGump.AddText(81, 71, 37, "-"); break;
    }
    AddLevel(BeeHiveGump, iUsed);
    //overall health
    switch (iUsed.GetTag("HealthStatus"))
    {
        case 1:
            BeeHiveGump.AddText(116, 146, 37, "Dying");
            iUsed.name = "Dying BeeHive";
            break;
        case 2:
            BeeHiveGump.AddText(116, 146, 52, "Sickly");
            iUsed.name = "Sickly BeeHive";
            break;
        case 3:
            BeeHiveGump.AddText(116, 146, 67, "Healthy");
            iUsed.name = "Healthy BeeHive";
            break;
        case 4:
            BeeHiveGump.AddText(116, 146, 92, "Thriving");
            iUsed.name = "Thriving BeeHive";
    }

    //BeeHiveGump.AddText(116, 146, 92, " " + iUsed.GetTag("Health"));
    BeeHiveGump.AddButton(58, 46, 212, 212, 1, 0, 1);//Button to open production gump

    //poison
    BeeHiveGump.AddButton(207, 71, 212, 212, 1, 0, 4);

    BeeHiveGump.Send(pUser);
    BeeHiveGump.Free();
}

function AddLevel(BeeHiveGump, iUsed)
{
    BeeHiveGump.AddText(30, 20, 0x481, " " +  iUsed.GetTag("HiveStage") );
}

function OverallHealth(iUsed)
{
    var maxhealth = 10 + (iUsed.GetTag("HiveStage") * 2);
    var perc = iUsed.GetTag("Health") * 100 / maxhealth;

    if (perc < 33)
    {
        iUsed.SetTag("HealthStatus", 1);//dying
    }
    else if (perc < 66)
    {
        iUsed.SetTag("HealthStatus", 2);//sickly
    }
    else if (perc < 100)
    {
        iUsed.SetTag("HealthStatus", 3);//healthy
    }
    else
    {
        iUsed.SetTag("HealthStatus", 4);//thriving
    }
}

function Die(iUsed)
{
    iUsed.SetTag("HoneyComb", 0);
    iUsed.SetTag("HiveStage", 0);
    iUsed.SetTag("Dead", 1);
}

function ApplyMaladiesEffects(iUsed)
{
    var damage = 0;

    if(iUsed.GetTag("Parasite") > 0)
        damage += iUsed.GetTag("Parasite") * RandomNumber(3, 6);

    iUsed.SetTag("Health", Math.max(0, (iUsed.GetTag("Health") - damage)));
}

function ApplyBenefitEffects(iUsed)
{
    var poison = iUsed.GetTag("PoisonPot");

    if (poison >= iUsed.GetTag("Parasite"))
    {
        poison -= iUsed.GetTag("Parasite");
        iUsed.SetTag("Parasite", 0);
    }
    iUsed.SetTag("PoisonPot", poison);
}

function ParasiteLevel(iUsed)
{
    //parasite level(0, 1, 2)
    var parasite = iUsed.GetTag("Parasite");

    if (parasite < 0)
        parasite = 0;
    else if (parasite >= 2)
       parasite = 2;
    else
        parasite++;

    iUsed.SetTag("Parasite", parasite);
}

function HiveStage(iUsed)
{
    //Growth Stages
    var hivestage = iUsed.GetTag("HiveStage");

    if (hivestage < 0)
        hivestage = 0;
    else if (hivestage >= 8)
        hivestage = 8;
    else
        hivestage++;

    iUsed.SetTag("HiveStage", hivestage);
}

function Honey(iUsed)
{
    //Honey
    var maxhoney = 20;// Max Amount of Honey it can hold Change this number to your liking
    var honey = iUsed.GetTag("HoneyComb");//amount of Honey

    if (honey < 0)
        honey = 0;
    else if (honey >= maxhoney)
        honey = maxhoney;
    else
        honey++;

    iUsed.SetTag("HoneyComb", honey);
}

function PoisonPotion(iUsed)
{
    var poison = iUsed.GetTag("PoisonPot");//amount of poison pots

    if (poison < 0)
        poison = 0;
    else if (poison > 2)
        poison = 2;
    else
        poison++

    iUsed.SetTag("PoisonPot", poison);
}

function onTimer(myObj, timerID)
{
    var parasiteChance = 30;

    if (!ValidateObject(myObj))
        return;

    switch (timerID)
    {
        case 0:
            myObj.SetTag("beestatus", 1)
            ApplyBenefitEffects(myObj);
            OverallHealth(myObj);
            if (myObj.GetTag("Health") == 0)
            {
                Die(myObj);
                break;
            }

            ApplyMaladiesEffects(myObj);

            if (RandomNumber(1, 100) < parasiteChance)
                ParasiteLevel(myObj);

            Honey(myObj);

            HiveStage(myObj)
            myObj.StartTimer(BeeHiveTimer, 0, true);
            break;
    }
}

function BeeHiveProductionGump(pUser, iUsed)
{
    var socket = pUser.socket;
    socket.tempObj = iUsed;
    var BeeHiveGump = new Gump;
    var gumpID = scriptID + 0xffff;
    socket.CloseGump(gumpID, 0);

    BeeHiveGump.AddPage(0);

    BeeHiveGump.AddBackground(37, 133, 205, 54, 3600);
    BeeHiveGump.AddBackground(37, 67, 205, 80, 3600);
    BeeHiveGump.AddBackground(37, 26, 205, 55, 3600);


    BeeHiveGump.AddPicture(12, 91, 3307);
    BeeHiveGump.AddPicture(11, 24, 3307);
    BeeHiveGump.AddPicture(206, 87, 3307);
    BeeHiveGump.AddPicture(205, 20, 3307);

    BeeHiveGump.AddPicture(76, 99, 5154);
    BeeHiveGump.AddPicture(149, 97, 2540);

    if (iUsed.GetTag("HiveStage") == 0)
    {//too early to produce
        BeeHiveGump.AddText(185, 97, 37, "X");
    }
    else
    {
        BeeHiveGump.AddText(185, 97, 0x481, " " + iUsed.GetTag("HoneyComb"));
    }

    BeeHiveGump.AddText(110, 43, 92, "Production");

    BeeHiveGump.AddPicture(44, 47, 6256);
    BeeHiveGump.AddPicture(191, 151, 2540);

    BeeHiveGump.AddPicture(42, 153, 5154);

    BeeHiveGump.AddGump(162, 96, 212);
    BeeHiveGump.AddGump(90, 96, 212);

    BeeHiveGump.AddButton(204, 150, 212, 212, 1, 0, 2);//get honey
    BeeHiveGump.AddButton(57, 43, 212, 212, 1, 0, 3);//exit back to home gump

    BeeHiveGump.Send(pUser);
    BeeHiveGump.Free();
}

function onGumpPress(socket, pButton, gumpData)
{
    var pUser = socket.currentChar;
    var iUsed = socket.tempObj;
    switch (pButton)
    {
        case 0:
            break;
        case 1:
            TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
            break;
        case 2:
            var iMakeResource = pUser.ResourceCount(0x0F0E);
            if (iUsed.GetTag("HoneyComb") < 3)
            {
                socket.SysMessage("There isn't enough honey in the hive to fill a bottle!");
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
            if (iMakeResource)
            {
                iUsed.SetTag("HoneyComb") - 3;
                CreateDFNItem(socket, pUser, "0x09EC", 1, "ITEM", true);
                socket.SysMessage("You fill a bottle with golden honey and place it in your pack.");
                pUser.UseResource(1, 0x0F0E);
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
            else
            {
                socket.SysMessage("You need a bottle to fill with honey!");
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
        case 3:
            TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
            break;
        case 4:
            var PoisonR = pUser.ResourceCount(0x0F0A);
            if (PoisonR)
            {
                PoisonPotion(iUsed);
                socket.SysMessage("You add Poison Potion to BeeHive to kill Parasites.");
                TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
                break;
            }
            else
            {
                socket.SysMessage("You don't have any strong potions of that type in your pack.");
                TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
                break;
            }
            break
    }
}
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 »

Version 0.3
Added ability to use heal potions to heal your health of hive
Changed the health starting from 10 to 100
Fixed the poison potion now it deletes out of pack
Changed how Poison Potion amount from 2 to 4 to be able to have on hive
Removed Beestatus no longer was needed.
Added Some checks to timer for growing your hive.
Redid the chance to get parasites so it will not get them as often.
///////////////////////////////////////////
// Apiculture Version 0.3                //
// Written by Dragon Slayer              //
///////////////////////////////////////////

const scriptID = 5032;
const BeeHiveTimer = 82800000; // This is 23 Hours before it will go to the next stage and produce honey.

function onUseChecked(pUser, iUsed)
{
    var socket = pUser.socket;
    socket.tempObj = iUsed;
    var BeeHiveGump = new Gump;
    var gumpID = scriptID + 0xffff;
    socket.CloseGump(gumpID, 0);

    if (iUsed.GetTag("Dead"))
    {
        socket.SysMessage("your bee hive has collapsed");
        iUsed.Delete();
    }

    if (!iUsed.GetTag("init"))
    {
        iUsed.SetTag("Health", 100);
        iUsed.SetTag("Parasite", 0)
        iUsed.StartTimer(BeeHiveTimer, 0, true);
        iUsed.SetTag("init", true);
    }

    BeeHiveGump.AddPage(0);
    BeeHiveGump.AddBackground(37, 26, 205, 161, 3600);

    //vines
    BeeHiveGump.AddPicture(12, 91, 3307);
    BeeHiveGump.AddPicture(11, 24, 3307);
    BeeHiveGump.AddPicture(206, 87, 3307);
    BeeHiveGump.AddPicture(205, 20, 3307);

    BeeHiveGump.AddGump(101, 66, 1417);  //circle thing
    BeeHiveGump.AddPicture(118, 89, 2330);   //beehive

    //potions
    //BeeHiveGump.AddPicture(198, 46, 3848);//Agility
    //BeeHiveGump.AddPicture(185, 96, 3847);// cure
    BeeHiveGump.AddPicture(198, 71, 3850); //poison
    BeeHiveGump.AddPicture(198, 121, 3852); //heal
    //BeeHiveGump.AddPicture(186, 146, 3849);

    //status icons
    BeeHiveGump.AddPicture(44, 49, 5154);//honey
    BeeHiveGump.AddPicture(-5, 76, 882); //little bug thing

    //corner boxes
    BeeHiveGump.AddGump(34, 20, 210);
    BeeHiveGump.AddGump(228, 20, 210);
    BeeHiveGump.AddGump(34, 172, 210);
    BeeHiveGump.AddGump(228, 172, 210);

    //boxes around status icons
    BeeHiveGump.AddGump(58, 71, 212);  //infestation

    BeeHiveGump.AddText(188, 71, 0x481, " " + iUsed.GetTag("PoisonPot"));   //poison
    BeeHiveGump.AddText(190, 121, 0x481, " " + iUsed.GetTag("HealPot") );   //heal

    //status labels
    switch (iUsed.GetTag("Parasite"))  //parasites
    {
        case 1: BeeHiveGump.AddText(81, 71, 52, "-"); break;
        case 2: BeeHiveGump.AddText(81, 71, 37, "-"); break;
    }
    AddLevel(BeeHiveGump, iUsed);
    //overall health
    switch (iUsed.GetTag("HealthStatus"))
    {
        case 1:
            BeeHiveGump.AddText(116, 146, 37, "Dying");
            iUsed.name = "Dying BeeHive";
            break;
        case 2:
            BeeHiveGump.AddText(116, 146, 52, "Sickly");
            iUsed.name = "Sickly BeeHive";
            break;
        case 3:
            BeeHiveGump.AddText(116, 146, 67, "Healthy");
            iUsed.name = "Healthy BeeHive";
            break;
        case 4:
            BeeHiveGump.AddText(116, 146, 92, "Thriving");
            iUsed.name = "Thriving BeeHive";
    }

    switch (iUsed.GetTag("HiveGrowthIndicator"))
    {
        case 1: BeeHiveGump.AddText(234, 20, 37, "-"); break;//PopulationDown: //red -
        case 2: BeeHiveGump.AddText(234, 20, 67, "+"); break;//PopulationUp: //green +
        case 3: BeeHiveGump.AddText(234, 20, 37, "!"); break;//HiveGrowthIndicator.NotHealthy: //red !
        case 4: BeeHiveGump.AddText(234, 20, 52, "!"); break;//LowResources: //yellow !
        case 5: BeeHiveGump.AddText(234, 20, 92, "+"); break;// Grown: //blue +
    }

    //BeeHiveGump.AddText(116, 146, 92, " " + iUsed.GetTag("Health"));
    BeeHiveGump.AddButton(58, 46, 212, 212, 1, 0, 1);//Button to open production gump

    //poison
    BeeHiveGump.AddButton(207, 71, 212, 212, 1, 0, 4);
    //heal
    BeeHiveGump.AddButton(207, 121, 212, 212, 1, 0, 5);
    BeeHiveGump.Send(pUser);
    BeeHiveGump.Free();
}

function AddLevel(BeeHiveGump, iUsed)
{
    BeeHiveGump.AddText(30, 20, 0x481, " " +  iUsed.GetTag("HiveStage") );
}

function OverallHealth(iUsed)
{
    var maxhealth = 10 + (iUsed.GetTag("HiveStage") * 2);
    var perc = iUsed.GetTag("Health") * 100 / maxhealth;

    if (perc < 33)
    {
        iUsed.SetTag("HealthStatus", 1);//dying
    }
    else if (perc < 66)
    {
        iUsed.SetTag("HealthStatus", 2);//sickly
    }
    else if (perc < 100)
    {
        iUsed.SetTag("HealthStatus", 3);//healthy
    }
    else
    {
        iUsed.SetTag("HealthStatus", 4);//thriving
    }
}

function Die(iUsed)
{
    iUsed.SetTag("HoneyComb", 0);
    iUsed.SetTag("HiveStage", 0);
    iUsed.SetTag("Dead", 1);
}

function ApplyMaladiesEffects(iUsed)
{
    var damage = 0;

    if(iUsed.GetTag("Parasite") > 0)
        damage += iUsed.GetTag("Parasite") * RandomNumber(3, 6);

    iUsed.SetTag("Health", Math.max(0, (iUsed.GetTag("Health") - damage)));
}

function ApplyBenefitEffects(iUsed)
{
    var poison = iUsed.GetTag("PoisonPot");
    var heal = iUsed.GetTag("HealPot");
    var healing = heal * 7;

    if (poison >= iUsed.GetTag("Parasite"))
    {
        poison -= iUsed.GetTag("Parasite");
        iUsed.SetTag("Parasite", 0);
    }
    iUsed.SetTag("PoisonPot", poison);

    if (!iUsed.GetTag("Parasite"))
    {
        if (heal > 0)
        {
            iUsed.SetTag("Health", Math.max(0, (iUsed.GetTag("Health") + healing)));
            iUsed.SetTag("HealPot") - 1;
        }
        else
            iUsed.SetTag("Health", Math.max(0, (iUsed.GetTag("Health") + 2)));
    }
}

function ParasiteLevel(iUsed)
{
    //parasite level(0, 1, 2)
    var parasite = iUsed.GetTag("Parasite");

    if (parasite < 0)
        parasite = 0;
    else if (parasite >= 2)
       parasite = 2;
    else
        parasite++;

    iUsed.SetTag("Parasite", parasite);
}

function HiveStage(iUsed)
{
    //Growth Stages
    var hivestage = iUsed.GetTag("HiveStage");

    if (hivestage < 0)
        hivestage = 0;
    else if (hivestage >= 8)
        hivestage = 8;
    else
        hivestage++;

    iUsed.SetTag("HiveStage", hivestage);
}

function Honey(iUsed)
{
    //Honey
    var maxhoney = 20;// Max Amount of Honey it can hold Change this number to your liking
    var honey = iUsed.GetTag("HoneyComb");//amount of Honey

    if (honey < 0)
        honey = 0;
    else if (honey >= maxhoney)
        honey = maxhoney;
    else
        honey++;

    iUsed.SetTag("HoneyComb", honey);
}

function PoisonPotion(iUsed)
{
    var poison = iUsed.GetTag("PoisonPot");//amount of poison pots

    if (poison < 0)
        poison = 0;
    else if (poison > 4)
        poison = 4;
    else
        poison++

    iUsed.SetTag("PoisonPot", poison);
}

function HealPotion(iUsed)
{
    var heal = iUsed.GetTag("HealPot");//amount of heal pots

    if (heal < 0)
        heal = 0;
    else if (heal > 4)
        heal = 4;
    else
        heal++

    iUsed.SetTag("HealPot", heal);
}

function onTimer(myObj, timerID)
{
    var parasiteChance = 3.30 * 1.10 + (iUsed.GetTag("HiveStage") * 1.01);

    if (!ValidateObject(myObj))
        return;

    switch (timerID)
    {
        case 0:
            ApplyBenefitEffects(myObj);
            OverallHealth(myObj);
            if (myObj.GetTag("Health") == 0)
            {
                Die(myObj);
                break;
            }

            ApplyMaladiesEffects(myObj);

            if (RandomNumber(1, 100) < parasiteChance)
                ParasiteLevel(myObj);

            if (iUsed.GetTag("HealthStatus") < 3)
            {
                if (!iUsed.GetTag("HiveGrowthIndicator", 1)) //population down takes precedence
                {
                    iUsed.SetTag("HiveGrowthIndicator", 3)
                    myObj.StartTimer(BeeHiveTimer, 1, true);
                    break;
                }
            }
            else if (iUsed.GetTag("HiveStage") < 5)
            {//not producing yet, so just grow
                iUsed.SetTag("HiveGrowthIndicator", 5)
                return;
            }
            else
            {

                Honey(myObj);

                HiveStage(myObj)
                iUsed.SetTag("HiveGrowthIndicator", 5)
                myObj.StartTimer(BeeHiveTimer, 0, true);
            }
            break;
        case 1:
            if (iUsed.GetTag("HealthStatus") < 3)
            {
                iUsed.SetTag("HiveGrowthIndicator", 3)
                myObj.StartTimer(BeeHiveTimer, 1, true);
                break;
            }
            else
            {
                myObj.StartTimer(BeeHiveTimer, 0, true);
                break;
            }

    }
}

function BeeHiveProductionGump(pUser, iUsed)
{
    var socket = pUser.socket;
    socket.tempObj = iUsed;
    var BeeHiveGump = new Gump;
    var gumpID = scriptID + 0xffff;
    socket.CloseGump(gumpID, 0);

    BeeHiveGump.AddPage(0);

    BeeHiveGump.AddBackground(37, 133, 205, 54, 3600);
    BeeHiveGump.AddBackground(37, 67, 205, 80, 3600);
    BeeHiveGump.AddBackground(37, 26, 205, 55, 3600);


    BeeHiveGump.AddPicture(12, 91, 3307);
    BeeHiveGump.AddPicture(11, 24, 3307);
    BeeHiveGump.AddPicture(206, 87, 3307);
    BeeHiveGump.AddPicture(205, 20, 3307);

    BeeHiveGump.AddPicture(76, 99, 5154);
    BeeHiveGump.AddPicture(149, 97, 2540);

    if (iUsed.GetTag("HiveStage") == 0)
    {//too early to produce
        BeeHiveGump.AddText(185, 97, 37, "X");
    }
    else
    {
        BeeHiveGump.AddText(185, 97, 0x481, " " + iUsed.GetTag("HoneyComb"));
    }

    BeeHiveGump.AddText(110, 43, 92, "Production");

    BeeHiveGump.AddPicture(44, 47, 6256);
    BeeHiveGump.AddPicture(191, 151, 2540);

    BeeHiveGump.AddPicture(42, 153, 5154);

    BeeHiveGump.AddGump(162, 96, 212);
    BeeHiveGump.AddGump(90, 96, 212);

    BeeHiveGump.AddButton(204, 150, 212, 212, 1, 0, 2);//get honey
    BeeHiveGump.AddButton(57, 43, 212, 212, 1, 0, 3);//exit back to home gump

    BeeHiveGump.Send(pUser);
    BeeHiveGump.Free();
}

function onGumpPress(socket, pButton, gumpData)
{
    var pUser = socket.currentChar;
    var iUsed = socket.tempObj;
    switch (pButton)
    {
        case 0:
            break;
        case 1:
            TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
            break;
        case 2:
            var iMakeResource = pUser.ResourceCount(0x0F0E);
            if (iUsed.GetTag("HoneyComb") < 3)
            {
                socket.SysMessage("There isn't enough honey in the hive to fill a bottle!");
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
            if (iMakeResource)
            {
                iUsed.SetTag("HoneyComb") - 3;
                CreateDFNItem(socket, pUser, "0x09EC", 1, "ITEM", true);
                socket.SysMessage("You fill a bottle with golden honey and place it in your pack.");
                pUser.UseResource(1, 0x0F0E);
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
            else
            {
                socket.SysMessage("You need a bottle to fill with honey!");
                TriggerEvent(scriptID, "BeeHiveProductionGump", pUser, iUsed);
                break;
            }
        case 3:
            TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
            break;
        case 4:
            var PoisonR = pUser.ResourceCount(0x0F0A);
            if (PoisonR)
            {
                PoisonPotion(iUsed);
                socket.SysMessage("You add Poison Potion to BeeHive to kill Parasites.");
                TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
                pUser.UseResource(1, 0x0F0A);
                break;
            }
            else
            {
                socket.SysMessage("You don't have any strong potions of that type in your pack.");
                TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
                break;
            }
            break
        case 5:
            var PoisonR = pUser.ResourceCount(0x0F0C);
            if (PoisonR)
            {
                HealPotion(iUsed);
                socket.SysMessage("You add Heal Potion to BeeHive to restore its health.");
                TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
                pUser.UseResource(1, 0x0F0C);
                break;
            }
            else
            {
                socket.SysMessage("You don't have any strong potions of that type in your pack.");
                TriggerEvent(scriptID, "onUseChecked", pUser, iUsed);
                break;
            }
            break
    }
}
Post Reply