Beo
07-22-2013, 06:18 PM
Hi, I'm new to scripting myself and I have only learned the basics, not even that!
I thought I'd make a tutorial since there isn't one here to make a simple depositer / refiller script and hopefully people can learn from it and make their own personal basic refillers/depositers.
Credits;
Myself for the screenshots, tutorial etc
JXScripts for the LUA script that I have edited (I hope you do not mind, if you do then I can remove it and create my own script, I just didn't want to spend the time to create it for a tutorial. xiaospike Joshwa534 Syntax - It was a free script (Terramites) and it's being released for a good cause I guess.
So here goes!
First, let's focus on the waypoints and labels.
Create a label called 'Start' - This will allow you to check your items and go back to this label.
http://3.imgland.net/ZTS1s9.png (http://3.imgland.net/ZTS1s9.png)
Begin to make your waypoints around the hunting ground ensure that the last waypoint is the first waypoint (so it can loop).
Now you've done that create a label called 'Check' and a label called 'Leave'. Now make waypoints back to the depot. I suggest to -1 or +1 depot so it isn't always full and there's less chance of you failing to deposit.
http://3.imgland.net/Q6Nva7.png (http://3.imgland.net/Q6Nva7.png)
Okay, now you're at the depot make a stand in the middle of the floor. Then put a label called 'Deposit'.
http://3.imgland.net/rORBS7.png (http://3.imgland.net/rORBS7.png)
After that, make waypoints to the bank and make a label called 'Bank'.
http://3.imgland.net/RlAsmb.png (http://3.imgland.net/RlAsmb.png)
Now continue making waypoints to the potion seller and make a label called 'BuyPots'.
http://3.imgland.net/6CadTi.png (http://3.imgland.net/6CadTi.png)
Once done, make a stand node around 3-4 steps away from the pot seller and make labels called 'Backpacks' and 'ToHunt'.
http://3.imgland.net/cz0x8s.png (http://3.imgland.net/cz0x8s.png)
Now make waypoints to your hunting grounds ensure that the last waypoint connects with the first waypoint of 'Start' so it can loop.
Finished! Well, the waypoints and labels atleast!
Now onto the LUA - Thanks once again to JXS.
local MinHealth = 100
local MaxHealth = 200
local MinMana = 100
local MaxMana = 200
local GoldBP = 1234
local MinCap = 100
registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")
print("Example LUA by Beo")
wait(1000)
function onWalkerSelectLabel(labelName)
if (labelName == "Check") then
Walker.ConditionalGoto((Self.Cap() < MinCap) or (Self.ItemCount(266) <= MinHealth) or (Self.ItemCount(268) <= MinMana) or ((LogoutStamina) and (Self.Stamina() < 840)), "Leave", "Start")
elseif (labelName == "BuyPots") then
Walker.Stop()
if (Self.ItemCount(268) < MaxMana) or (Self.ItemCount(266) < MaxHealth) then
Self.SayToNpc({"hi", "flasks", "yes", "trade"}, 65)
wait(2000)
if (Self.ItemCount(268) < MaxMana) then
BuyItems(268, MaxMana)
wait(500)
BuyItems(268, MaxMana)
wait(500)
end
if (Self.ItemCount(266) < MaxHealth) then
BuyItems(266, MaxHealth)
wait(500)
end
wait(200, 500)
end
Walker.Start()
elseif (labelName == "Bank") then
local withdrawManas = math.max(MaxMana - Self.ItemCount(268), 0)*50
local withdrawHealths = math.max(MaxHealth - Self.ItemCount(266), 0)*45
local withdrawFood = math.max(MaxFood - Self.ItemCount(3586), 0)*10
local totalmoneyneeded = (withdrawHealths + withdrawManas + withdrawFood)
local MATHCEIL = (math.ceil((totalmoneyneeded/1000)))*1000
Walker.Stop()
Self.SayToNpc({"hi", "deposit all", "yes"}, 65)
if (totalmoneyneeded > 0) then
Self.SayToNpc({"withdraw " .. MATHCEIL, "yes", "balance"}, 65)
end
wait(2000)
Walker.Start()
elseif (labelName == "Deposit") then
Walker.Stop()
Self.ReachDepot()
Self.DepositItems({1234,0},{1234,0},{1234,0})
if (LogoutStamina) and (Self.Stamina() < 960) then
Walker.Start()
end
elseif (labelName == "Backpacks") then
Walker.Stop()
Container.Close(GoldBP)
wait(1000)
Container.GetFirst():OpenChildren(GoldBP)
wait(1000)
Container.GetByName(GoldBP):Minimize()
Walker.Start()
end
end
----------------------- Functions ----------------------
function BuyItems(item, count) -- item = item id, count = how many you want to buy up to
wait(900, 1200)
if (Self.ItemCount(item) < count) then
Self.ShopBuyItem(item, (count-Self.ItemCount(item)))
wait(200, 500)
end
end
Self.ReachDepot = function (tries)
local tries = tries or 3
Walker.Stop()
local DepotIDs = {3497, 3498, 3499, 3500}
local DepotPos = {}
for i = 1, #DepotIDs do
local dps = Map.GetUseItems(DepotIDs[i])
for j = 1, #dps do
table.insert(DepotPos, dps[j])
end
end
local function gotoDepot()
local pos = Self.Position()
print("Depots found: " .. tostring(#DepotPos))
for i = 1, #DepotPos do
location = DepotPos[i]
Self.UseItemFromGround(location.x, location.y, location.z)
wait(1000, 2000)
if Self.DistanceFromPosition(pos.x, pos.y, pos.z) >= 1 then
wait(5000, 6000)
if Self.DistanceFromPosition(location.x, location.y, location.z) == 1 then
Walker.Start()
return true
end
else
print("Something is blocking the path. Trying next depot.")
end
end
return false
end
repeat
reachedDP = gotoDepot()
if reachedDP then
return true
end
tries = tries - 1
sleep(100)
print("Attempt to reach depot was unsuccessfull. " .. tries .. " tries left.")
until tries <= 0
return false
end
Map.GetUseItems = function (id)
if type(id) == "string" then
id = Item.GetID(id)
end
local pos = Self.Position()
local store = {}
for x = -7, 7 do
for y = -5, 5 do
if Map.GetTopUseItem(pos.x + x, pos.y + y, pos.z).id == id then
itemPos = {x = pos.x + x, y = pos.y + y, z = pos.z}
table.insert(store, itemPos)
end
end
end
return store
end
Now let's break it down a bit!
local MinHealth = 100
local MaxHealth = 200
local MinMana = 100
local MaxMana = 200
local GoldBP = 1234
local MinCap = 100 [/lua]
MinHealth - This will determine how many health pots you want to leave the cave on.
MaxHealth - This will determine how many health pots you want to buy to go back to the cave.
MinMana - Same as MinHealth.
MaxMana - Same as MaxHealth.
GoldBP - This will determine your gold backpack so it can reset.
MinCap - This will determine how much cap you would like to go back to refill.
The rest you don't really need to touch except the following;
[xcode=lua](Self.ItemCount(266)
This will determine what pot you will purchase. 266 being normal health potions, you can find a list of ID's using the search function.
If you CTRL+F you can find this easily allowing you to change it to what you need. 268 is the mana potion ID, you can also CTRL+F that and change it too.
elseif (labelName == "Deposit") then
Walker.Stop()
Self.ReachDepot()
Self.DepositItems({1234,0},{1234,0},{1234,0})
if (LogoutStamina) and (Self.Stamina() < 960) then
Walker.Start()
end
Now the 1234 were just example ID's. You'll need to change these to the ID's you wish to deposit. The 0 next to them is which slot you want to drag them to.
0 being the first slot
1 being the second slot
2 being third slot
etc
E.G.
http://4.imgland.net/lO2DdC.png (http://4.imgland.net/lO2DdC.png)
I thought I'd make a tutorial since there isn't one here to make a simple depositer / refiller script and hopefully people can learn from it and make their own personal basic refillers/depositers.
Credits;
Myself for the screenshots, tutorial etc
JXScripts for the LUA script that I have edited (I hope you do not mind, if you do then I can remove it and create my own script, I just didn't want to spend the time to create it for a tutorial. xiaospike Joshwa534 Syntax - It was a free script (Terramites) and it's being released for a good cause I guess.
So here goes!
First, let's focus on the waypoints and labels.
Create a label called 'Start' - This will allow you to check your items and go back to this label.
http://3.imgland.net/ZTS1s9.png (http://3.imgland.net/ZTS1s9.png)
Begin to make your waypoints around the hunting ground ensure that the last waypoint is the first waypoint (so it can loop).
Now you've done that create a label called 'Check' and a label called 'Leave'. Now make waypoints back to the depot. I suggest to -1 or +1 depot so it isn't always full and there's less chance of you failing to deposit.
http://3.imgland.net/Q6Nva7.png (http://3.imgland.net/Q6Nva7.png)
Okay, now you're at the depot make a stand in the middle of the floor. Then put a label called 'Deposit'.
http://3.imgland.net/rORBS7.png (http://3.imgland.net/rORBS7.png)
After that, make waypoints to the bank and make a label called 'Bank'.
http://3.imgland.net/RlAsmb.png (http://3.imgland.net/RlAsmb.png)
Now continue making waypoints to the potion seller and make a label called 'BuyPots'.
http://3.imgland.net/6CadTi.png (http://3.imgland.net/6CadTi.png)
Once done, make a stand node around 3-4 steps away from the pot seller and make labels called 'Backpacks' and 'ToHunt'.
http://3.imgland.net/cz0x8s.png (http://3.imgland.net/cz0x8s.png)
Now make waypoints to your hunting grounds ensure that the last waypoint connects with the first waypoint of 'Start' so it can loop.
Finished! Well, the waypoints and labels atleast!
Now onto the LUA - Thanks once again to JXS.
local MinHealth = 100
local MaxHealth = 200
local MinMana = 100
local MaxMana = 200
local GoldBP = 1234
local MinCap = 100
registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")
print("Example LUA by Beo")
wait(1000)
function onWalkerSelectLabel(labelName)
if (labelName == "Check") then
Walker.ConditionalGoto((Self.Cap() < MinCap) or (Self.ItemCount(266) <= MinHealth) or (Self.ItemCount(268) <= MinMana) or ((LogoutStamina) and (Self.Stamina() < 840)), "Leave", "Start")
elseif (labelName == "BuyPots") then
Walker.Stop()
if (Self.ItemCount(268) < MaxMana) or (Self.ItemCount(266) < MaxHealth) then
Self.SayToNpc({"hi", "flasks", "yes", "trade"}, 65)
wait(2000)
if (Self.ItemCount(268) < MaxMana) then
BuyItems(268, MaxMana)
wait(500)
BuyItems(268, MaxMana)
wait(500)
end
if (Self.ItemCount(266) < MaxHealth) then
BuyItems(266, MaxHealth)
wait(500)
end
wait(200, 500)
end
Walker.Start()
elseif (labelName == "Bank") then
local withdrawManas = math.max(MaxMana - Self.ItemCount(268), 0)*50
local withdrawHealths = math.max(MaxHealth - Self.ItemCount(266), 0)*45
local withdrawFood = math.max(MaxFood - Self.ItemCount(3586), 0)*10
local totalmoneyneeded = (withdrawHealths + withdrawManas + withdrawFood)
local MATHCEIL = (math.ceil((totalmoneyneeded/1000)))*1000
Walker.Stop()
Self.SayToNpc({"hi", "deposit all", "yes"}, 65)
if (totalmoneyneeded > 0) then
Self.SayToNpc({"withdraw " .. MATHCEIL, "yes", "balance"}, 65)
end
wait(2000)
Walker.Start()
elseif (labelName == "Deposit") then
Walker.Stop()
Self.ReachDepot()
Self.DepositItems({1234,0},{1234,0},{1234,0})
if (LogoutStamina) and (Self.Stamina() < 960) then
Walker.Start()
end
elseif (labelName == "Backpacks") then
Walker.Stop()
Container.Close(GoldBP)
wait(1000)
Container.GetFirst():OpenChildren(GoldBP)
wait(1000)
Container.GetByName(GoldBP):Minimize()
Walker.Start()
end
end
----------------------- Functions ----------------------
function BuyItems(item, count) -- item = item id, count = how many you want to buy up to
wait(900, 1200)
if (Self.ItemCount(item) < count) then
Self.ShopBuyItem(item, (count-Self.ItemCount(item)))
wait(200, 500)
end
end
Self.ReachDepot = function (tries)
local tries = tries or 3
Walker.Stop()
local DepotIDs = {3497, 3498, 3499, 3500}
local DepotPos = {}
for i = 1, #DepotIDs do
local dps = Map.GetUseItems(DepotIDs[i])
for j = 1, #dps do
table.insert(DepotPos, dps[j])
end
end
local function gotoDepot()
local pos = Self.Position()
print("Depots found: " .. tostring(#DepotPos))
for i = 1, #DepotPos do
location = DepotPos[i]
Self.UseItemFromGround(location.x, location.y, location.z)
wait(1000, 2000)
if Self.DistanceFromPosition(pos.x, pos.y, pos.z) >= 1 then
wait(5000, 6000)
if Self.DistanceFromPosition(location.x, location.y, location.z) == 1 then
Walker.Start()
return true
end
else
print("Something is blocking the path. Trying next depot.")
end
end
return false
end
repeat
reachedDP = gotoDepot()
if reachedDP then
return true
end
tries = tries - 1
sleep(100)
print("Attempt to reach depot was unsuccessfull. " .. tries .. " tries left.")
until tries <= 0
return false
end
Map.GetUseItems = function (id)
if type(id) == "string" then
id = Item.GetID(id)
end
local pos = Self.Position()
local store = {}
for x = -7, 7 do
for y = -5, 5 do
if Map.GetTopUseItem(pos.x + x, pos.y + y, pos.z).id == id then
itemPos = {x = pos.x + x, y = pos.y + y, z = pos.z}
table.insert(store, itemPos)
end
end
end
return store
end
Now let's break it down a bit!
local MinHealth = 100
local MaxHealth = 200
local MinMana = 100
local MaxMana = 200
local GoldBP = 1234
local MinCap = 100 [/lua]
MinHealth - This will determine how many health pots you want to leave the cave on.
MaxHealth - This will determine how many health pots you want to buy to go back to the cave.
MinMana - Same as MinHealth.
MaxMana - Same as MaxHealth.
GoldBP - This will determine your gold backpack so it can reset.
MinCap - This will determine how much cap you would like to go back to refill.
The rest you don't really need to touch except the following;
[xcode=lua](Self.ItemCount(266)
This will determine what pot you will purchase. 266 being normal health potions, you can find a list of ID's using the search function.
If you CTRL+F you can find this easily allowing you to change it to what you need. 268 is the mana potion ID, you can also CTRL+F that and change it too.
elseif (labelName == "Deposit") then
Walker.Stop()
Self.ReachDepot()
Self.DepositItems({1234,0},{1234,0},{1234,0})
if (LogoutStamina) and (Self.Stamina() < 960) then
Walker.Start()
end
Now the 1234 were just example ID's. You'll need to change these to the ID's you wish to deposit. The 0 next to them is which slot you want to drag them to.
0 being the first slot
1 being the second slot
2 being third slot
etc
E.G.
http://4.imgland.net/lO2DdC.png (http://4.imgland.net/lO2DdC.png)