View Full Version : Jar Script (1st Script)
Haldrik
10-13-2015, 01:23 PM
Heyo,
I managed to hack together my first script. This pulls all gems from my orc hide sack and puts it into an empty bottle.
I basically put stuff in until it worked. I know there's way more efficient ways to do a lot of this so I'd appreciate any insight or suggestions.
thanks!
gem_sack = GameObj.inv.find{ |i| i.name =~ /orc hide sack/}
gem_sack.contents.each{ |gem|
fput "get jar from coat" if righthand.nil?
dothistimeout "get ##{gem.id}", 3, /^You remove|Get what/
next if lefthand.nil?
dothistimeout "put my #{gem.noun} in my jar", 3, /^You put|^You add/
gem_sack.contents.each{ |nextgem|
if "#{nextgem.name}" == "#{gem.name}" then
dothistimeout "get ##{nextgem.id}", 3, /^You remove|^Get what/
next if lefthand.nil?
output = dothistimeout "put my #{gem.noun} in my jar", 3, /^You put|^You add|^The/
if output =~ /^The .+ is full/
multifput "put jar in back", "get jar from coat", "put my #{gem.noun} in my jar"
output = xxx
end
end
}
fput "put jar in back"
}
DaCapn
10-13-2015, 02:11 PM
Oh, the places you'll go!
It's a bit of jankery the way you've nested the two blocks to iterate over all gems of a specific name first but I see that it probably mostly works.
You could give the following a try:
(1) Collect the names of all of the gems in the sack
(2a) Use the uniq method to remove redundant gem names
(2b) Parse that list for annoying exceptions (like tiny, medium, large pearls which can share a jar as long as they're the same color).
(3) Iterate over all of the gem names and use find_all method (like you used find) to collect all gems that match the name.
That reduces unnecessary iteration. When you think about it, the way you've written it, the script is ignoring most of the things you're iterating over. I doubt it matters for the user experience here but that's always something that you should think about.
There's also an exception for gem-like things that can't go into jars. You can see the messaging if you try to place a chrism in a jar. In addition, it's handy to put pull the containers out of your main code. At the least, they can be hard-coded variables at the top. That way if you change your backpack or coat or whatever, it's trivial to fix.
Some other things to look into would be using ids to refer to game objects. The type method is also handy for isolating the gems in your gemsack. Have a look at the gameobj-data.xml file in your scripts directory.
Haldrik
10-13-2015, 06:56 PM
Oh, the places you'll go!
It's a bit of jankery the way you've nested the two blocks to iterate over all gems of a specific name first but I see that it probably mostly works.
You could give the following a try:
(1) Collect the names of all of the gems in the sack
(2a) Use the uniq method to remove redundant gem names
(2b) Parse that list for annoying exceptions (like tiny, medium, large pearls which can share a jar as long as they're the same color).
(3) Iterate over all of the gem names and use find_all method (like you used find) to collect all gems that match the name.
That reduces unnecessary iteration. When you think about it, the way you've written it, the script is ignoring most of the things you're iterating over. I doubt it matters for the user experience here but that's always something that you should think about.
There's also an exception for gem-like things that can't go into jars. You can see the messaging if you try to place a chrism in a jar. In addition, it's handy to put pull the containers out of your main code. At the least, they can be hard-coded variables at the top. That way if you change your backpack or coat or whatever, it's trivial to fix.
Some other things to look into would be using ids to refer to game objects. The type method is also handy for isolating the gems in your gemsack. Have a look at the gameobj-data.xml file in your scripts directory.
Awesome! Thanks for your reply. There is a ton of good stuff in here!
--(2a) Use the uniq method to remove redundant gem names
Nice, I had tried to do this originally but couldn't get the syntax right. Tillmen helped me figured it out on LNET. But I decided that maybe I didn't want unique because then it wont know how many gems are in there and I'd have to create some new code to count. Or get until hand is empty which is a bit less streamlined.
--(2b) Parse that list for annoying exceptions (like tiny, medium, large pearls which can share a jar as long as they're the same color).
Damn. I had NO IDEA you could do this. No wonder i have like 150 jars now. Super irritating.
--(3) Iterate over all of the gem names and use find_all method (like you used find) to collect all gems that match the name.
Ahh. I see what you are saying now on (2A).
--In addition, it's handy to put pull the containers out of your main code. At the least, they can be hard-coded variables at the top. That way if you change your backpack or coat or whatever, it's trivial to fix.
Will do!
--Some other things to look into would be using ids to refer to game objects. The type method is also handy for isolating the gems in your gemsack. Have a look at the gameobj-data.xml file in your scripts directory.
I definitely want to do this, but unsure the syntax for calling the .XML.
----------------------------
Okay. So my next step is to do a bit of tinkering to parse my 150+ bottles to remove all the annoying exceptions which can be placed in the same jar. How annoying! Is there a list anywhere?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.