Log in

View Full Version : Cant Execute my script



shamdis
03-17-2014, 03:03 PM
got some problems with my new script it just kills itself after like 10-15sec after i have Executed the script.

here is the lua file:



-- SammeSkog Scripts --


-- Refill Settings:
local LeaveMana = 30 -- Leave spawn when under = manapotions
local BringMana = 70 -- How many manas would u like to bring?
local ManaPotID = 268 -- Mana Potion ID
local ManaCost = 50 -- Cost of Mana Potion //EA


local BringAmmo = 15 -- Leave spawn when under = Royal Spears
local LeaveAmmo = 8 -- Leave spawn when under = Royal Spears
local SpearID = 7378 -- Spear ID, 7378 is Royal Spears
local SpearCost = 15 -- cost of Royal Spear //EA


-- Other Settings --
-- True = Yes, False = No --

local LeaveCap = 40 -- Leave spawn when under =
local GoldBP = 2866 -- Item ID of your gold backpack.
local HideEquipment = true -- Hide your Equipment


---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------

local info = [[
SammeSkog's Paladin Yalahar Cyclops ]]
wait(5000)

print([[
SammeSkog's Paladin Yalahar Cyclops ]])
wait(5000)


---------------------------------------------------------------------------------

function onWalkerSelectLabel(labelName)

if (labelName == "Boat1") then
Walker.Stop()
wait(1500,2000)
Self.SayToNpc("hi")
wait(1500,2000)
Self.SayToNpc("mistrock")
wait(1500,2000)
Self.SayToNpc("yes")
wait(2500,3000)
Looter.Stop()
Walker.Start()


elseif (labelName == "Boat2") then
Walker.Stop()
wait(1500,2000)
Self.SayToNpc("hi")
wait(1500,2000)
Self.SayToNpc("Yalahar")
wait(1500,2000)
Self.SayToNpc("yes")
wait(2500,3000)
Looter.Stop()
Walker.Start()
end


if (labelName == "Checker") then
if (Self.Cap() < Leavecap) then
Walker.Goto("Leave")
print([[Low cap, leaving.]])
elseif (Self.ItemCount(ManaPotID) < LeaveMana) then
Walker.Goto("Leave")
print([[Low mana pots, leaving.]])
elseif (Self.ItemCount(SpearID) < LeaveAmmo) then
Walker.Goto("Leave")
print([[Low ammo, leaving.]])
else
Walker.Goto("Hunt")
print([[Enough supplies & cap, keep hunting.]])
end
end

if (labelName == "Bank") then
Walker.Stop()
print([[Deposit & withdraw..]])
wait(1800,2400)
Self.SayToNpc("hi")
wait(1800,2400)
Self.SayToNpc("deposit all")
wait(1800,2400)
Self.SayToNpc("yes")
wait(1800,2400)
Self.WithdrawMoney(50*(MPBuy-Self.ItemCount(ManaPotID))+1000)
wait(1800,2400)
Self.WithdrawMoney(15*(AmmoBuy-Self.ItemCount(SpearID)))
wait(1800,2400)
Self.SayToNpc("balance")
Walker.Start()



elseif (labelName == "Potions") then
Walker.Stop()
print([[Potions..]])
wait(1900,2400)
Self.SayToNpc("hi")
wait(1900,2400)
Self.SayToNpc("trade")
wait(1900,2400)
Self.ShopBuyItemsUpTo(ManaPotID, BringMana)
wait(3500,4000)
Self.ShopBuyItemsUpTo(ManaPotID, BringMana)
wait(3500,4000)
Self.SayToNpc("bye")
Walker.Start()



elseif (labelName == "Ammo") then
Walker.Stop()
Self.SayToNpc("hi")
wait(1900,2400)
Self.SayToNpc("trade")
wait(1900,2400)
print([[Ammo..]])
Self.ShopBuyItemsUpTo(SpearID, BringAmmo)
wait(1600,2400)
Walker.Start()

elseif (labelName == "resetbp") then
Walker.Stop()
Container.Close(GoldBP)
wait(1000)
Container.GetFirst():OpenChildren(GoldBP)
wait(1000)
Container.GetByName(GoldBP):Minimize()


elseif (labelName == "Deposit") then
setWalkerEnabled(false)
Self.ReachDepot()
Self.DepositItems{9657, 7398}
wait(1500,1900)
end



-------------------------------------------------------------------------------



Self.ReachDepot = function (tries)
local tries = tries or 5
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 - 5
sleep(100)
print("Attempt to reach depot was unsuccessfull. " .. tries .. " tries left.")
until tries <= 0

return false
end
registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")

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
end

Infernal Bolt
03-17-2014, 04:08 PM
Tabbing the script correctly makes it a lot easier to find the problems.
This should work, added some comments on some improvements you can make.


-- SammeSkog Scripts --


-- Refill Settings:
local LeaveMana = 30 -- Leave spawn when under = manapotions
local BringMana = 70 -- How many manas would u like to bring?
local ManaPotID = 268 -- Mana Potion ID
local ManaCost = 50 -- Cost of Mana Potion //EA


local BringAmmo = 15 -- Leave spawn when under = Royal Spears
local LeaveAmmo = 8 -- Leave spawn when under = Royal Spears
local SpearID = 7378 -- Spear ID, 7378 is Royal Spears
local SpearCost = 15 -- cost of Royal Spear //EA


-- Other Settings --
-- True = Yes, False = No --

local LeaveCap = 40 -- Leave spawn when under =
local GoldBP = 2866 -- Item ID of your gold backpack.
local HideEquipment = true -- Hide your Equipment


---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------

local info = [[
SammeSkog's Paladin Yalahar Cyclops ]]
wait(5000)

print([[
SammeSkog's Paladin Yalahar Cyclops ]])
wait(5000)


---------------------------------------------------------------------------------

registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")
function onWalkerSelectLabel(labelName)

if (labelName == "Boat1") then -- npc taking can be done on one line, you do not need to split them up like this.
Walker.Stop()
wait(1500,2000)
Self.SayToNpc("hi")
wait(1500,2000)
Self.SayToNpc("mistrock")
wait(1500,2000)
Self.SayToNpc("yes")
wait(2500,3000)
Looter.Stop()
Walker.Start()


elseif (labelName == "Boat2") then -- npc talking example:
Walker.Stop()
Self.SayToNpc({"hi", "yalahar", "yes"}, 65, 7) -- 65 = words per minute, lower number = slower. 7 = how much it should randomize it
wait(2500,3000)
Looter.Stop()
Walker.Start()


if (labelName == "Checker") then -- why are you overcomplicating this, just add all the checkers to the same script.
if (Self.Cap() < Leavecap) then
Walker.Goto("Leave")
print([[Low cap, leaving.]])
elseif (Self.ItemCount(ManaPotID) < LeaveMana) then
Walker.Goto("Leave")
print([[Low mana pots, leaving.]])
elseif (Self.ItemCount(SpearID) < LeaveAmmo) then
Walker.Goto("Leave")
print([[Low ammo, leaving.]])
else
Walker.Goto("Hunt")
print([[Enough supplies & cap, keep hunting.]])
end
end

if (labelName == "Bank") then
Walker.Stop()
print([[Deposit & withdraw..]])
wait(1800,2400)
Self.SayToNpc("hi")
wait(1800,2400)
Self.SayToNpc("deposit all")
wait(1800,2400)
Self.SayToNpc("yes")
wait(1800,2400)
Self.WithdrawMoney(50*(MPBuy-Self.ItemCount(ManaPotID))+1000)
wait(1800,2400)
Self.WithdrawMoney(15*(AmmoBuy-Self.ItemCount(SpearID)))
wait(1800,2400)
Self.SayToNpc("balance")
Walker.Start()



elseif (labelName == "Potions") then
Walker.Stop()
print([[Potions..]])
wait(1900,2400)
Self.SayToNpc("hi")
wait(1900,2400)
Self.SayToNpc("trade")
wait(1900,2400)
Self.ShopBuyItemsUpTo(ManaPotID, BringMana)
wait(3500,4000)
Self.ShopBuyItemsUpTo(ManaPotID, BringMana)
wait(3500,4000)
Self.SayToNpc("bye")
Walker.Start()



elseif (labelName == "Ammo") then
Walker.Stop()
Self.SayToNpc("hi")
wait(1900,2400)
Self.SayToNpc("trade")
wait(1900,2400)
print([[Ammo..]])
Self.ShopBuyItemsUpTo(SpearID, BringAmmo)
wait(1600,2400)
Walker.Start()

elseif (labelName == "resetbp") then
Walker.Stop()
Container.Close(GoldBP)
wait(1000)
Container.GetFirst():OpenChildren({GoldBP, true})
wait(1000)


elseif (labelName == "Deposit") then
setWalkerEnabled(false)
Self.ReachDepot()
Self.DepositItems{9657, 7398}
wait(1500,1900)

end
end



-------------------------------------------------------------------------------




Self.ReachDepot = function (tries)
local tries = tries or 5
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 - 5
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

shamdis
03-17-2014, 10:22 PM
it dosent kill itself now but semms like the script wont work, wont deposit/withdraw/buypotions

only4tibia
03-18-2014, 02:02 AM
it dosent kill itself now but semms like the script wont work, wont deposit/withdraw/buypotions

This may help with "Deposit". Set up for your own items ofc.

elseif (Label == "DepositItems") then
local Rares = 0 -- 1st slot of depot should be rares backpack
local Stackables = 1 -- 2nd slot of depot should be stackables backpack
Self.ReachDepot()
Self.DepositItems(
{"terramite shell", Stackables},
{"scimitar", Rares}
)

Regards,
O4T