Page 1 of 1

Making userfunction...

Posted: Wed Aug 17, 2011 12:32 pm
by botje

Code: Select all

function CleanBag(sellprize)
	for i, item in pairs(inventory.BagSlot) do
		if item.SlotNumber >= settings.profile.options.INV_AUTOSELL_FROMSLOT and
			settings.profile.options.INV_AUTOSELL_TOSLOT >= item.SlotNumber then
			if (item:isType("weapons") or item:isType("armor")) and sellprize > item.Worth then
				printf("Deleting Item:  "..item.Name.."\n");
				item:delete()
			end
		end
	end
end
Trying to make a userfunction to clean my bags, but it doesnt work at ll, no errors though.

also would llike to drop on color...

Botje

Re: Making userfunction...

Posted: Wed Aug 17, 2011 9:02 pm
by lisa
at first glance I don't see why it wouldn't work, when and how do you call the userfunction?

Re: Making userfunction...

Posted: Thu Aug 18, 2011 12:30 am
by rock5
I see a problem with the line I think I gave you. I'm notorious for not double checking my code as Lisa knows. :)

"weapons" and "armor" should be "Weapons" and "Armor". Sorry.

Code: Select all

         if (item:isType("Weapons") or item:isType("Armor")) and sellprize > item.Worth then

Re: Making userfunction...

Posted: Thu Aug 18, 2011 4:33 am
by lisa
I guess we could add in a string.lower so caps or no caps would make no difference.

Re: Making userfunction...

Posted: Thu Aug 18, 2011 4:52 am
by botje
oh nice, gonna test that ^^

and how are things like chains rings etc called?

i cant seem to find anything related to those in the item file O.o

Botje

Re: Making userfunction...

Posted: Thu Aug 18, 2011 5:09 am
by rock5
What do you mean by "chains rings"? Do you mean, how to identify if the item is an Accessory? You can use

Code: Select all

item:isType("Accessories")
BUT accessories are a sub type of armor so checking for "Armor" will include accessories.

You can find all the "types" in the file itemtypestable.lua in the cache folder.

Re: Making userfunction...

Posted: Thu Aug 18, 2011 7:21 am
by botje
oh i see, so armor will work regardless, nice :)

so thats where that info is, and here i was looking at items file all the time xd

Botje

Re: Making userfunction...

Posted: Mon Aug 22, 2011 9:23 am
by Hexacore
lootomatic is a gread addon so you dont have to mess with scripting :P just record items and drop them ;) i use it for KS

btw i have a noob question about userfunctions :P

if you write a function like function DoSomething()
...................
end

can i call the function by name like <waypoint>DoSomething()</waypoint>
and another noob question what programming language does micromacro understands and what one is used for .lua and .xml files

ty (didnt want to start another thread)

Re: Making userfunction...

Posted: Mon Aug 22, 2011 9:35 am
by botje
but i use a lootfilter too, thats not the point, now i can set what stuff to drop.

more control :)

Botje

Re: Making userfunction...

Posted: Mon Aug 22, 2011 9:51 am
by rock5
Both the game and lua files use the .lua language. Micromacro is for executing lua scripts like the rombot. .xml files have xml code in them and are basically just a way to store information using tags. It can have lua in between the xml tags. The lua reference can be found here.
http://www.lua.org/manual/5.1/

If you create a function it needs to be put somewhere so that it gets loaded and becomes available for you to use like you said
<waypoint>DoSomething()</waypoint>
You can put functions in a number of places.

If you want to make a function that you will use in many scripts, you can place it in the "userfunctions.lua" file(you will have to create it if it doesn't already exist).

If you want to create a function that you will share, you can create a file for it in the "userfunctions" folder. The name of the file should be prefixed with "userfunction_", eg. "userfunction_myfunction.xml".

If you want to create a function for a specific need in a particular waypoint file you can put it in the onLoad section of the waypoint file.

There are probably a few other places you can put them but you get the idea.