buy = true;
afk = false; -- will go out clan hall then soe in time if true
LastBuyTimeManually = os.time({year=2012, month=1, day=1, hour=1, min=1, sec=1})
ClanHallNpcName = "Maid";
skip = false;
GiantEnergyQuantityAfterBuy = nil;
GiantEnergyQuantityBeforeBuy = nil;
function LoadLastBuyfromFile(filename) --function that uses filename file to obtain player stock.
local file = io.open(GetDir() .. filename, "r")
if (file == nil) then -- then create a file
file = io.open(GetDir() .. filename, "w")
else
for line in file:lines() do
if (tonumber(line) ~= nil) then
return tonumber(line);
end;
end;
end;
file:close();
return 0;
end;
function UpdateLastEnergyBuyFile(thefile)
local file = io.open(GetDir() .. thefile, "w+")
file:write(tostring(os.time() + 2) .. "\n");
file:close();
end;
LastBuyOnFile = LoadLastBuyfromFile(GetMe():GetName() .. "LastEnergyBuy.txt");
if (LastBuyTimeManually > LastBuyOnFile) then
LastBuyTime = LastBuyTimeManually;
else
LastBuyTime = LastBuyOnFile;
end;
--ShowToClient("Buying Energies Script","Next Giant Energy Sale will occur between " .. os.date("%X") .. " and ".. os.date("%X",os.time()+3600) .. " and it need to be done manually.");
if buy then
if (os.time() > LastBuyTime + 7200) then
ShowToClient("Buying Energies Script","No Idea When Spawn Might be.");
elseif (os.time() > LastBuyTime + 3610) and (os.time() < LastBuyTime + 7200) then
ShowToClient("Buying Energies Script","Next Giant Energy Sale will occur between " .. os.date("%X") .. " and ".. os.date("%X",os.time()+3600) .. " and it need to be done manually.");
while (GiantEnergyQuantityBeforeBuy == nil) or (GiantEnergyQuantityAfterBuy == nil) or ((GiantEnergyQuantityAfterBuy-GiantEnergyQuantityBeforeBuy) <= 0) do
Sleep(2000);
MyTarget = GetTarget();
if (MyTarget ~= nil) and (MyTarget:GetName() == ClanHallNpcName) then
GiantEnergy = GetInventory():FindByDisplayId(35563);
if (GiantEnergy == nil) then
GiantEnergyQuantityAfterBuy = 0;
if (GiantEnergyQuantityBeforeBuy == nil) then
GiantEnergyQuantityBeforeBuy = 0;
end;
else
GiantEnergyQuantityAfterBuy = GiantEnergy.ItemNum;
end;
else
GiantEnergy = GetInventory():FindByDisplayId(35563);
if (GiantEnergy == nil) then
GiantEnergyQuantityBeforeBuy = 0;
if (GiantEnergyQuantityAfterBuy == nil) then
GiantEnergyQuantityAfterBuy = 0;
end;
else
GiantEnergyQuantityBeforeBuy = GiantEnergy.ItemNum;
end;
end;
end;
ShowToClient("Buying Energies Script","Giant Energy Quantity Change Detected, time set for now");
UpdateLastEnergyBuyFile(GetMe():GetName() .. "LastEnergyBuy.txt");
skip = true;
else
ShowToClient("Buying Energies Script","Started, buy will occur in " .. tostring(math.ceil((3600-(os.time()-LastBuyTime))/60)).. " minutes.");
while ((os.time()-LastBuyTime) < 3600) do
Sleep(1000);
end;
end;
ShowToClient("Buying Energies Script","Attempting to buy for First Time.");
repeat
if not skip then
GiantEnergy = GetInventory():FindByDisplayId(35563);
if (GiantEnergy == nil) then
GiantEnergyQuantityBeforeBuy = 0;
else
GiantEnergyQuantityBeforeBuy = GiantEnergy.ItemNum;
end;
Command("/target " .. ClanHallNpcName);
Sleep(500);
Command("/target " .. ClanHallNpcName);
GetNormalNPCExchangeManager():Clear();
while(not GetNormalNPCExchangeManager():GetStatus()) do
Click("menu_select?ask=300&reply=1", "Create Item");
Sleep(1500);
end;
if (GetNormalNPCExchangeManager():AddBuyByID(35563,2) == true) then
Sleep(1000);
GetNormalNPCExchangeManager():RequestBuyItems();
ShowToClient("Auto Clan Hal buy","Request Buying");
UpdateLastEnergyBuyFile(GetMe():GetName() .. "LastEnergyBuy.txt")
end;
Sleep(100);
GetNormalNPCExchangeManager():RequestShopUIClose();
Sleep(4000);
GiantEnergy = GetInventory():FindByDisplayId(35563);
if (GiantEnergy == nil) then
GiantEnergyQuantityAfterBuy = 0;
else
GiantEnergyQuantityAfterBuy = GiantEnergy.ItemNum;
end;
Adena = GetInventory():FindByDisplayId(57);
if (Adena == nil) then
AdenaQuantity = 0;
else
AdenaQuantity = Adena.ItemNum;
end;
ShowToClient("Buying Energies Script","I got extra " .. tostring(GiantEnergyQuantityAfterBuy-GiantEnergyQuantityBeforeBuy) .. " Giant Energy.");
end;
skip = false;
ClanHallSoE = GetInventory():FindByDisplayId(1829);
if (ClanHallSoE == nil) then
ClanHallSoEQuantity = 0;
else
ClanHallSoEQuantity = ClanHallSoE.ItemNum;
end;
if (ClanHallSoEQuantity > 0) and (afk) then
moveDistance = 30;
waittime = 0;
timeofteleport = GetTime();
MoveTo(144841, 27723, -2269, moveDistance);
waittime = GetTime() - timeofteleport;
Sleep(57*60*1000 -2000);
timeofteleport = GetTime();
UseItem(1829); -- Scroll of Escape: Clan Hall
WaitForTeleport();
MoveTo(144227, 28245, -2242, moveDistance);
Command("/target " .. ClanHallNpcName);
waittime = waittime + GetTime() - timeofteleport;
else
waittime = 0;
Sleep(57*60*1000 -2000);-- this sleep can be slpit into more for soe scrolls
end;
ShowToClient("Buying Energies Script","Clicking in 2 minutes...");
Sleep(3*60*1000 -waittime);
until ((GiantEnergyQuantityAfterBuy-GiantEnergyQuantityBeforeBuy) <= 0) or (AdenaQuantity < 11000000)
end;