eg:
There's Cow, Chicken, Pig and Sheep.
If i try to add Cow, it *might* add a sheep instead. (What animal it adds differ whenever i reopen the building OSD)
The same problem goes for removing the animal aswell.
I've tried tracking this down for a few hours and just can't seem to find the problem.
Here's the script:
Code: Select all
//**************Info**************//
//gBuildingVar20 = Amount of Cows
//gBuildingVar21 = Amount of Chickens
//gBuildingVar22 = Amount of Pigs
//gBuildingVar23 = Amount of Sheeps
//
//gBuildingTimeVar1 = Cow's birth date
//gBuildingTimeVar2 = Chicken's birth date
//gBuildingTimeVar3 = Pigs birth date
//gBuildingTimeVar4 = Sheeps birth date
//--------------------------
//AddToInventorySilent() exists in the ServerScript.mit file.
//No need to think about it.
//--------------------------
Function AnimalFarm_Display()
{
AnimalFarm_AddRemoveAnimals("Cow", 5);
AnimalFarm_AddRemoveAnimals("Chicken", 20);
AnimalFarm_AddRemoveAnimals("Pig", 35);
AnimalFarm_AddRemoveAnimals("Sheep", 50);
}
Function AnimalFarm_AddRemoveAnimals($animal, $posY)
{
//Get the amount of animals there is for $animal
if ($animal == "Cow")
{
$amountOfAnimal = $gBuildingVar20;
}
else if ($animal == "Chicken")
{
$amountOfAnimal = $gBuildingVar21;
}
else if ($animal == "Pig")
{
$amountOfAnimal = $gBuildingVar22;
}
else if ($animal == "Sheep")
{
$amountOfAnimal = $gBuildingVar23;
}
//Add button for animal
if (sysPlayerInventory($animal) > 0) //If player has $animal, add a Add button.
{
$addingAnimal = $animal;
OSDAddAt(BUTTON, 220, $posY, 50, 15, "AddAnimal", "Add");
}
else //If player doesn't have $animal, add a faded Add button
{
OSDAddAt(FADEDBUTTON, 220, $posY, 50, 15, "", "Add");
}
//Remove button for animal
if ($amountOfAnimal > 0) //If the farm does have $animal, add a Remove button
{
$removingAnimal = $animal;
OSDAddAt(BUTTON, 270, $posY, 90, 15, "RemoveAnimal", "Remove");
}
else //If the farm doesn't have a $animal, add a faded Remove button
{
OSDAddAt(FADEDBUTTON, 270, $posY, 90, 15, "", "Remove");
}
}
Event ("OSDSelect", "AnimalFarm:AddAnimal")
{
if ($addingAnimal == "Cow") //Adding Cows to farm
{
if ($gBuildingVar20 <= 0) //If this is the first cow that gets added, set a birth day for it.
{
$gBuildingTimeVar1 = $gGameDay;
}
$gBuildingVar20 = $gBuildingVar20 + 1; //Add cow to building.
AddToInventorySilent("Cow", -1, 1); //Remove cow from player inventory
}
else if ($addingAnimal == "Chicken") //Adding Chickens to farm
{
if ($gBuildingVar21 <= 0) //If this is the first chicken that gets added, set a birth day for it.
{
$gBuildingTimeVar2 = $gGameDay;
}
$gBuildingVar21 = $gBuildingVar21 + 1; //Add chicken to building.
AddToInventorySilent("Chicken", -1, 1); //Remove chicken from player inventory
}
else if ($addingAnimal == "Pig") //Adding Pigs to farm
{
if ($gBuildingVar22 <= 0) //If this is the first pig that gets added, set a birth day for it.
{
$gBuildingTimeVar3 = $gGameDay;
}
$gBuildingVar22 = $gBuildingVar22 + 1; //Add pig to building.
AddToInventorySilent("Pig", -1, 1); //Remove pig from player inventory
}
else if ($addingAnimal == "Sheep") //Adding Sheeps to farm
{
if ($gBuildingVar23 <= 0) //If this is the first sheep that gets added, set a birth day for it.
{
$gBuildingTimeVar4 = $gGameDay;
}
$gBuildingVar23 = $gBuildingVar23 + 1; //Add sheep to building.
AddToInventorySilent("Sheep", -1, 1); //Remove sheep from player inventory
}
else //If value isn't anything of above, notify it.
{
*say Error trying to add animal ($addingAnimal) from Animal Farm (ID:$gBuildingAccessNum)
}
AnimalFarm_Display();
}
Event ("OSDSelect", "AnimalFarm:RemoveAnimal")
{
if ($removingAnimal == "Cow") //If value is Cow, remove 1 from gBuildingVar20, and add 1 to inventory. (Same goes for the else...if's below)
{
$gBuildingVar20 = $gBuildingVar20 - 1;
AddToInventorySilent("Cow", 1, 1);
}
else if ($removingAnimal == "Chicken")
{
$gBuildingVar21 = $gBuildingVar21 - 1;
AddToInventorySilent("Chicken", 1, 1);
}
else if ($removingAnimal == "Pig")
{
$gBuildingVar22 = $gBuildingVar22 - 1;
AddToInventorySilent("Pig", 1, 1);
}
else if ($removingAnimal == "Sheep")
{
$gBuildingVar23 = $gBuildingVar23 - 1;
AddToInventorySilent("Sheep", 1, 1);
}
else //If value isn't anything of above, notify it.
{
*say Error trying to remove animal ($removingAnimal) from Animal Farm (ID:$gBuildingAccessNum)
}
AnimalFarm_Display();
}