problem witha function im trying to write

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
raider4ever
Posts: 12
Joined: Tue Mar 05, 2013 1:14 pm

problem witha function im trying to write

#1 Post by raider4ever » Wed Jan 14, 2015 3:33 am

I'm not very good with coding so could someone please help, thank you in advanced.

What im trying to do is have the bot check items in my backpack and look at the stats and if the stats are not part of my list it sells them.

I get "attempt to index field 'stat' <a nil value>" every time i try and execute this version the main change i made was in Backchack() up to inventory:useItem("Salioca Upheaval Cloak") i added itemHasStat("Salioca Upheaval Cloak", "Guardian of the Basin") to try to specify what items i want to keep and sale, because the rest of the Backcheck() sales all items regardless of stats.

sorry for the trouble.

Code: Select all

		function itemHasStat(item, stat)
    if (item.Stats[1] and item.Stats[1].Name == "Ability of the Basin") or -- Str/pa
      (item.Stats[2] and item.Stats[2].Name == "Guardian of the Basin") or --Stam/Pa
	  (item.Stats[3] and item.Stats[3].Name == "Illusion of the Basin") or -- Int / MA
      (item.Stats[4] and item.Stats[4].Name == "Sorcery of the Basin") or -- Int / Stam
	  (item.Stats[5] and item.Stats[5].Name == "Triumph of the Basin") or -- Dex PA
      (item.Stats[6] and item.Stats[6].Name == "Protection of the Basin") or -- Stam / Def
	  (item.Stats[7] and item.Stats[7].Name == "Ability of the Jungle") or -- Str/PA
      (item.Stats[8] and item.Stats[8].Name == "Guardian of the Jungle") or -- Stam/ PA
	  (item.Stats[9] and item.Stats[9].Name == "Illusion of the Jungle") or -- Int MA
      (item.Stats[10] and item.Stats[10].Name == "Sorcery of the Jungle") or -- Int / Stam
	  (item.Stats[11] and item.Stats[11].Name == "Triumph of the Jungle") or -- Dex PA
      (item.Stats[12] and item.Stats[12].Name == "Protection of the Jungle") then -- Stam / Def
        return true
    end
end

		function Backcheck()
	  for slot = 61,120 do
					local item = inventory.BagSlot[slot]
					
		if item.Name == "Salioca Upheaval Cloak" then
			inventory:update()
			if itemHasStat("Salioca Upheaval Cloak", "Guardian of the Basin") or
		
			itemHasStat("Salioca Upheaval Cloak", "Protection of the Basin") then
           shells()						
			else
		player:openStore("Byron - Archeologist")
		inventory:useItem("Salioca Upheaval Cloak")
			
			end
		
		
		elseif item.Name == "Hortek Subversion Shoulder Armor" then
					if #item.Stats == 8 then
		
        elseif #item.Stats == 12 then
				-- send to mule 2						
		else
		player:openStore("Byron - Archeologist")
				if player:openStore("Byron - Archeologist") then
				inventory:useItem("Hortek Subversion Shoulder Armor")
					end
				end
				
				
				elseif item.Name == "Salioca Crush Cloak" then
					if #item.Stats == 1 then
					
		else
				player:openStore("Byron - Archeologist")
				if player:openStore("Byron - Archeologist") then
				inventory:useItem("Salioca Crush Cloak")
					end
				end		
				
				elseif item.Name == "Hortek Crush Shoulder Armor" then
					if #item.Stats == 7 then
							
					else
				player:openStore("Byron - Archeologist")
				if player:openStore("Byron - Archeologist") then
				inventory:useItem("Hortek Crush Shoulder Armor")
					end
				end		
				
				elseif item.Name == "Salioca Vengeance Cloak" then
					if #item.Stats == 5 then
							
		else
		player:openStore("Byron - Archeologist")
				if player:openStore("Byron - Archeologist") then
				inventory:useItem("Salioca Vengeance Cloak")
					end
				end		
				
				elseif item.Name == "Hortek Vengeance Shoulder Armor" then
					if #item.Stats == 11 then
						
		else
		player:openStore("Byron - Archeologist")
				if player:openStore("Byron - Archeologist") then
				inventory:useItem("Hortek Vengeance Shoulder Armor")
					end
				end		
				
				elseif item.Name == "Salioca Wisdom Cloack" then
					if #item.Stats == 3 then
		
        elseif #item.Stats == 4 then
				-- send to mule 2						
		else
		player:openStore("Byron - Archeologist")
				if player:openStore("Byron - Archeologist") then
				inventory:useItem("Salioca Wisdom Cloack")
					end
				end		
				
				elseif item.Name == "Hortek Wisdom Shoulder Guards" then
					if #item.Stats == 9 then
		
        elseif #item.Stats == 10 then
				-- send to mule 2						
		else
		player:openStore("Byron - Archeologist")
				if player:openStore("Byron - Archeologist") then
				inventory:useItem("Hortek Wisdom Shoulder Guards")
					end
				end
	
		end		
	end
end
		

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: problem witha function im trying to write

#2 Post by BlubBlab » Wed Jan 14, 2015 4:06 am

maybe you should test if Stats really exists, maybe the items has no Stats crafting-runes or something like that has no.
You only check if you are outside a specific number, on top of that a item can only hold 6 stats you are going until 12 ??

Code: Select all

    function itemHasStat(item, stat)
    if(item.Stats == nil)then
        return false;
    end
    if (item.Stats[1] and item.Stats[1].Name == "Ability of the Basin") or -- Str/pa
      (item.Stats[2] and item.Stats[2].Name == "Guardian of the Basin") or --Stam/Pa
     (item.Stats[3] and item.Stats[3].Name == "Illusion of the Basin") or -- Int / MA
      (item.Stats[4] and item.Stats[4].Name == "Sorcery of the Basin") or -- Int / Stam
     (item.Stats[5] and item.Stats[5].Name == "Triumph of the Basin") or -- Dex PA
      (item.Stats[6] and item.Stats[6].Name == "Protection of the Basin") or -- Stam / Def
     (item.Stats[7] and item.Stats[7].Name == "Ability of the Jungle") or -- Str/PA
      (item.Stats[8] and item.Stats[8].Name == "Guardian of the Jungle") or -- Stam/ PA
     (item.Stats[9] and item.Stats[9].Name == "Illusion of the Jungle") or -- Int MA
      (item.Stats[10] and item.Stats[10].Name == "Sorcery of the Jungle") or -- Int / Stam
     (item.Stats[11] and item.Stats[11].Name == "Triumph of the Jungle") or -- Dex PA
      (item.Stats[12] and item.Stats[12].Name == "Protection of the Jungle") then -- Stam / Def
        return true
    end
end
By the way you don't use actually stats in the argument I would straight up your code either to use that argument or use a loop
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

raider4ever
Posts: 12
Joined: Tue Mar 05, 2013 1:14 pm

Re: problem witha function im trying to write

#3 Post by raider4ever » Wed Jan 14, 2015 4:28 am

item can only hold 6 stats you are going until 12 ??
i may have used it wrong but what i was doing was naming the sats i wanted to keep. my Bot pulls a shell peice of gear and they have those listed stats on them but only 1 stat. i was trying to make it so that the bot drops all junk stats like dex/m... also how would i establish "stat" to allow the bot to check the stats on items? that is where i have been getting lost.

raider4ever
Posts: 12
Joined: Tue Mar 05, 2013 1:14 pm

Re: problem witha function im trying to write

#4 Post by raider4ever » Wed Jan 14, 2015 4:38 am

This is the main part im having an issue with

Code: Select all

function itemHasStat(item, stat)
    if (item.Stats[1] and item.Stats[1].Name == "Ability of the Basin") or -- Str/pa
      (item.Stats[2] and item.Stats[2].Name == "Guardian of the Basin") or --Stam/Pa
	  (item.Stats[3] and item.Stats[3].Name == "Illusion of the Basin") or -- Int / MA
      (item.Stats[4] and item.Stats[4].Name == "Sorcery of the Basin") or -- Int / Stam
	  (item.Stats[5] and item.Stats[5].Name == "Triumph of the Basin") or -- Dex PA
      (item.Stats[6] and item.Stats[6].Name == "Protection of the Basin") or -- Stam / Def
	  (item.Stats[7] and item.Stats[7].Name == "Ability of the Jungle") or -- Str/PA
      (item.Stats[8] and item.Stats[8].Name == "Guardian of the Jungle") or -- Stam/ PA
	  (item.Stats[9] and item.Stats[9].Name == "Illusion of the Jungle") or -- Int MA
      (item.Stats[10] and item.Stats[10].Name == "Sorcery of the Jungle") or -- Int / Stam
	  (item.Stats[11] and item.Stats[11].Name == "Triumph of the Jungle") or -- Dex PA
      (item.Stats[12] and item.Stats[12].Name == "Protection of the Jungle") then -- Stam / Def
        return true
    end
end

	function Backcheck()
		for slot = 61,120 do
					local item = inventory.BagSlot[slot]
					
			if item.Name == "Salioca Upheaval Cloak" then
			inventory:update()
				if itemHasStat("Salioca Upheaval Cloak", "Guardian of the Basin") or
		
				itemHasStat("Salioca Upheaval Cloak", "Protection of the Basin") then
				shells()						
				else
				player:openStore("Byron - Archeologist")
				inventory:useItem("Salioca Upheaval Cloak")
			
				end
		
			end

	
		end		
	end

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: problem witha function im trying to write

#5 Post by BlubBlab » Wed Jan 14, 2015 4:50 am

Sry I didn't read all but than also:

Code: Select all


   function Backcheck()
      for slot = 61,120 do
               local item = inventory.BagSlot[slot]
         if(item)then     
         if item.Name == "Salioca Upheaval Cloak" then
         inventory:update()
            if itemHasStat(item, "Guardian of the Basin") or
      
            itemHasStat(item, "Protection of the Basin") then
            shells()                  
            else
            player:openStore("Byron - Archeologist")
            inventory:useItem("Salioca Upheaval Cloak")
           end
            end
      
         end
         
   
      end      
   end
You must give itemHasStat a item to check not a string no wonder it will fail on top of that you forgot to check if a item exist in the first place. I can only repeat me get first ride of the chaos in your code first.
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests