Log in

View Full Version : Help with my script open trade windows in npc but dont but the item it get stuck



felipe93
05-13-2016, 09:15 AM
hello well im eiting an script to make it for paladin
i think i've edited everything well
script deposit /buy manas healh etc but the part i edited wich its buy spears opens the windows but doesn't buy anything just get stuck there

here is the script pls someone could help me im sure i've edited everything well or could be the lua that i use to buy spears is too old¿?

---------INFORMATION---------
-- BP SETUP
-- [BP 1] -- Main
-- [BP 2] -- Pouches
-- [BP 3] -- Gold

--DP SETUP
-- [BP 1] -- All loot
------------------------------------------------------
---------SETTINGS---------
-- BP ID
local goldBP = 2866 -- ID of your Gold BP

-- Cap
local minCap = 20 --Cap to leave spawn

-- Pouches
local maxPouches = 4 --Max amount of Medicine Pouches

-- MP
local manasToLeave = 1 --Manas to leave spawn
local wantedMPS = 2 --Wanted amount of manapotions
local manaPotID = 268 --Manapotion ID
local manaCost = 50 --Manapotion price

local AmmoName = "Spear" --- What ammunition are you using?
local LeaveAmmo = 2 --- How much ammunition until you leave hunt?
local BuyAmmo = 5 --- How much ammunition do you begin the hunt with?
local AmmoCost = 10 --- What is the cost of your selected ammunition?

-- Other
local safeCheckID = 17462 -- Set an item which is looted regurlary. The script will, after depositting, check for this item to ensure it has depositted -- and if not it will try depositting again.
------------------------------------------------------
displayInformationMessage("Venore: Swamp Troll cave by:vinhzika \n -- Basiq's Swamp troll Script! Enjoy!")
registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")
function onWalkerSelectLabel(labelName)
if (labelName == "checker") then
if (Self.Cap() < minCap) or ((Self.ItemCount(manaPotID) < manasToLeave)) or ((Self.ItemCount(12517) > maxPouches)) or (Self.ItemCount(AmmoID) <= LeaveAmmo) then
gotoLabel("leaveSpawn")
else
gotoLabel("keepHunting")
end

elseif (labelName == "checkDoor1") then
local item = Map.GetTopUseItem(33004, 32099, 7)
if (item.id == 17700) then
Self.UseItemFromGround(33004, 32099, 7)
else
gotoLabel("continue1")
end
elseif (labelName == "checkDoor2") then
local item = Map.GetTopUseItem(32999, 32096, 6)
if (item.id == 17569) then
Self.UseItemFromGround(32999, 32096, 6)
else
gotoLabel("continue2")
end
elseif (labelName == "checkDoor3") then
local item = Map.GetTopUseItem(32999, 32096, 6)
if (item.id == 17569) then
Self.UseItemFromGround(32999, 32096, 6)
else
gotoLabel("continue3")
end
elseif (labelName == "checkDoor4") then
local item = Map.GetTopUseItem(33004, 32099, 7)
if (item.id == 17700) then
Self.UseItemFromGround(33004, 32099, 7)
else
gotoLabel("continue4")
end

elseif (labelName == "posCheck1") then
if (Self.Position().x == 32798 and Self.Position().y == 32155 and Self.Position().z == 8) then
gotoLabel("AfterPosCheck1")
else
gotoLabel("checkShovel1")
end

elseif (labelName == "floor1") then
if not (floor1) then
gotoLabel("cont1")
end

elseif (labelName == "checkShovel1") then
sleep(math.random(1000, 2000))
local item = Map.GetTopUseItem(32798, 32155, 7)
if (item.id == 593) then
gotoLabel("shovel1")
else
gotoLabel("cont3")
end

elseif (labelName == "shovel1") then
setWalkerEnabled(false)
Self.UseItemWithGround(shovelID, 32798, 32155, 7)
sleep(math.random(1100, 3000))
setWalkerEnabled(true)

elseif (labelName == "cut1") then
setWalkerEnabled(false)
Self.UseItemWithGround(macheteID, 32855, 32109, 7)
sleep(math.random(1100, 3000))
setWalkerEnabled(true)

elseif (labelName == "looterOff1") then
setLooterEnabled(false)

elseif (labelName == "looterOn1") then
setLooterEnabled(true)

elseif (labelName == "backpackReset") then
delayWalker(2000)
setWalkerEnabled(false)
Container.Close(goldBP)
sleep(math.random(500, 1000))
Container.GetFirst():OpenChildren(goldBP)
sleep(math.random(500, 1000))
setWalkerEnabled(true)

elseif (labelName == "bank") then
setWalkerEnabled(false)
delayWalker(5000)
Self.Say("hi")
sleep(math.random(700, 1400))
Self.SayToNpc("deposit all")
sleep(math.random(300, 1000))
Self.SayToNpc("yes")
sleep(math.random(300, 1000))
Self.WithdrawMoney((manaCost*(wantedMPS-Self.ItemCount(manaPotID)))+200)
sleep(math.random(300, 1000))
Self.SayToNpc("yes")
sleep(math.random(300, 1000))
Self.SayToNpc("balance")
setWalkerEnabled(true)
elseif (labelName == "reachDepot") then
Self.ReachDepot()

elseif (labelName == "deposit") then
Self.DepositItems(
{8031, 0},
{5894, 0},
{9689, 0},
{11485, 0},
{9692, 0},
{12600, 0},
{9686, 0},
{3741, 0},
{12517, 0}
)
sleep(math.random(500, 1000))

elseif (labelName == "buyManas") then
setWalkerEnabled(false)
delayWalker(7000)
Self.Say("hi")
sleep(math.random(500, 1000))
Self.SayToNpc("vials")
sleep(math.random(500, 1000))
Self.SayToNpc("yes")
sleep(math.random(500, 1000))
Self.SayToNpc("trade")
sleep(math.random(500, 1000))
buyManas(manaPotID, (wantedMPS-Self.ItemCount(manaPotID)))
sleep(math.random(500, 1000))
setWalkerEnabled(true)

elseif (labelName == "checkManas2") then
if (Self.ItemCount(manaPotID) < wantedMPS) then
gotoLabel("goBank")
else
gotoLabel("goHunt")
end

elseif (labelName == "BuySpears") then
Walker.Stop()
Self.SayToNpc({"hi", "trade"}, 100)
-- Buy spears, make sure Self.ItemCount returns items in hands.
while (Self.ItemCount(AmmoID) < BuyAmmo) do
Self.ShopBuyItemsUpTo(AmmoID, BuyAmmo)
wait(500,800)
end
Walker.Start()

elseif (labelName == "checkSpears") then
if (Self.ItemCount(AmmoID) < wantedAmmo) then
gotoLabel("goBank")
else
gotoLabel("goHunt")
end

elseif (labelName == "checkDepo") then
if (Self.ItemCount(safeCheckID) > 1) then
gotoLabel("goDeposit")
end

elseif (labelName == "gate2")then
Self.UseItemFromGround(32729, 31199, 5)
end
end

function buyManas(item, count)
count = tonumber(count) or 1
repeat
local amnt = math.min(count, 100)
if(Self.ShopBuyItem(item, amnt) == 0)then
return printf("ERROR", tostring(item))
end
wait(200,500)
count = (count - amnt)
until count <= 0
end

Self.ReachDepot = function (tries)
local tries = tries or 3
setWalkerEnabled(false)
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
setWalkerEnabled(true)
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