XenoBot Forums - Powered by vBulletin

User Tag List

Results 1 to 3 of 3

Thread: need help in my lua code

  1. #1

    Join Date
    Apr 2014
    Location
    mexico
    Posts
    71
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Question need help in my lua code

    this is my first attemp in script 100%afk is a easy rotworm

    i get this error

    15:43 XenoScript Error:
    Script: Rots near kaz bridge.lua
    Line #: 37
    Chunk: C:\Users\Luini\Documents\XenoBot\Scripts\Rots near kaz bridge.lua
    Error: 'end' expected (to close 'function' at line 32) near 'elseif'
    This is an error with user-input and should not be reported as a bug with XenoBot.
    Code:
    ------ REFILL SETTINGS ------
    local LeaveHealth = 5 --- How many health potions until you leave the hunt?
    local BuyHealth = 10 --- How many health potions you begin the hunt with?
    
    local LeaveCap = 80 --- Leaves spawn when character reaches this cap.
    local HideEquipment = true --- Do you want to minimize your equipment?
    local LogoutStamina = false --- Do you want to logout at 16 hours? (Inside the depot)
    
    -- Item ID's, if you don't want to use HP, change these:
    
    local HealthName = "Health Potion" 
    local HealthCost = 45
    
    -- Backpack Configuration:
    
    local LootBP = "Backpack"
    local GoldBP = "Red Backpack"
    
    -- Here I'm gonna get the item ids, leave this as it is.
    
    local HealthID = Item.GetID(HealthName)
    
    -- These are the flask IDs, not worth changing since it will sell all flasks regardless of type.
    local FlaskID = 283
    local FlaskIDA = 284
    local FlaskIDB = 285
    
    -- local GoldBP = 2867 --- Item ID of your gold backpack.
    
    registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")
    
    function onWalkerSelectLabel(labelName)
    	if (labelName == "Check") then
    		-- Check Supplies, Hunt or Leave
    		Walker.ConditionalGoto((Self.ItemCount(ManaID) <= LeaveMana) or (Self.Cap() < LeaveCap) or (Self.ItemCount(HealthID) <= LeaveHealth), "Leave", "BeginHunt")
    
    	elseif (labelName == "Start") then
    		Walker.ConditionalGoto((Self.Position().z == 11), "BeginHunt", "Reach")
    	
    	elseif (labelName == "depo/withdraw") then
    		-- Deposit Gold, check balance.
    		Walker.Stop()
    		Self.SayToNpc({"hi", "deposit all", "yes"}, 100)
    
    		local withdrawManas = math.max(BuyMana - Self.ItemCount(ManaID), 0)*ManaCost
    		local withdrawHealths = math.max(BuyHealth - Self.ItemCount(HealthID), 0)*HealthCost
    		local withdrawAmmo = math.max(BuyAmmo - Self.ItemCount(AmmoID), 0)*AmmoCost
    		local total = math.abs(withdrawManas + withdrawHealths + withdrawAmmo)
    
    		if total >= 1 then
    			Self.SayToNpc({"withdraw " .. total, "yes", "balance"}, 100)
    		end
    		Walker.Start()
    
    	elseif (labelName == "DepositItems") then
    		-- Deposit Items
    		Walker.Stop()
    		Self.ReachDepot(5)
    		Self.DepositItems({5902, 0}, {9689, 0}, {9692, 0})
    		Walker.Start()
    
    	elseif (labelName == "Buy hp") then
    		-- Buy Mana Potions
    		Walker.Stop()
    		if (Self.ItemCount(ManaID) < BuyMana) or (Self.ItemCount(HealthID) < BuyHealth) then
    			print("Buying manas or healths")
    			Self.SayToNpc({"hi", "flasks"}, 100)
    			while (Self.ItemCount(FlaskID) >= 1) or (Self.ItemCount(FlaskIDA) >= 1) or (Self.ItemCount(FlaskIDB) >= 1) do
    				Self.SayToNpc("yes", 100)
    			end
    			wait(2000)
    			Self.SayToNpc("trade", 100)
    			wait(2000)
    			while (Self.ItemCount(ManaID) < BuyMana) do
    				Self.ShopBuyItemsUpTo(ManaID, BuyMana)
    				wait(500,800)
    			end
    			if (Self.ItemCount(HealthID) < BuyHealth) then
    				Self.ShopBuyItemsUpTo(HealthID, BuyHealth)
    				wait(500)
    			end
    			wait(200, 500)
    		end
    		Walker.Start()
    
    			--------------------------------- TODO ------------------------
    
    	elseif (labelName == "ResetBps") then
    		-- Reset Backpacks
    		Walker.Stop()
    		Self.CloseContainers()
    		Self.OpenMainBackpack(true):OpenChildren({LootBP, true}, {GoldBP, true})
    		Container.GetFirst():Minimize()
    		Walker.Start()
    	end
    
    Self.Reach = 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

  2. #2
    Senior Member ppgab's Avatar
    Join Date
    Mar 2014
    Location
    Brazil
    Posts
    986
    Mentioned
    86 Post(s)
    Tagged
    0 Thread(s)
    @luini you forgot to end function onWalkerSelectLabel(labelName) after all the elseifs

  3. #3

    Join Date
    Apr 2014
    Location
    mexico
    Posts
    71
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ppgab View Post
    @luini you forgot to end function onWalkerSelectLabel(labelName) after all the elseifs
    ty
    im testing and it deposit,withdraw and buy pot now that was my problem

    im sharing this now
    Last edited by luini; 05-11-2014 at 10:24 PM. Reason: solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •