//:://///////////////////////////////////////////// //:: Nam: farm_purchase //:: Copyright (c) 2001 Bioware Corp. //::////////////////////////////////////////////// /* Attempt to allow the PC to purchase this plot of farmland. */ //::////////////////////////////////////////////// //:: Created By: Adam Walenga //:: Created On: September 3rd, 2004 //::////////////////////////////////////////////// #include "farm_include" void main() { object oPlayer = GetPCSpeaker(); int iFarmNumber = GetLocalInt (OBJECT_SELF, "Farm_Number"); int iSellPrice = Farm_GetSellPrice (iFarmNumber); //Determine the sell price. if (iSellPrice == 0) iSellPrice = GetLocalInt (OBJECT_SELF, "Farm_Price"); //Determine if PC can afford the farmland. if (GetGold (oPlayer) < iSellPrice) { SendMessageToPC (oPlayer, "You currently cannot afford to purchase " + "this plot of farmland."); return; } string sOwner = Farm_GetOwner (iFarmNumber); //Previous owner. //Allow PC to purchase farmland. TakeGoldFromCreature (iSellPrice, oPlayer, TRUE); Farm_SetOwner (iFarmNumber, oPlayer); Farm_SetIsForSale (iFarmNumber, FALSE); SendMessageToPC (oPlayer, "Congratulations! You've succesfully purchased " + "this plot of farmland."); if (sOwner != "") //Owner is a valid PC - check if currently online. { object oLoop = GetFirstPC(); //Loop through players in search of the previous owner. while (GetIsObjectValid (oLoop)) { if (sOwner == "FARM_" + GetPCPlayerName (oLoop)) break; oLoop = GetNextPC(); } //Check if previous owner was found. if (GetIsObjectValid (oLoop)) { SendMessageToPC (oLoop, GetName (oPlayer) + " has just purchased " + "one of your farmlands for " + IntToString (iSellPrice) + "!"); GiveGoldToCreature (oLoop, iSellPrice); } else { //Determing string size (cannot be larger than 32). if (GetStringLength (sOwner) > 32) sOwner = GetStringLeft (sOwner, 32); SetCampaignInt ("Farm_Main_Database", sOwner, GetCampaignInt ("Farm_Main_Database", sOwner) + iSellPrice); } } //Update max farm number - if possible. if (iFarmNumber > Farm_GetMaxFarm()) Farm_SetMaxFarm (iFarmNumber); }