PDA

View Full Version : Help with RUBY



Kaelozim
09-29-2010, 12:14 AM
Ok, so I took Tillmen's npcpick script and modified it to use PC picker, and I know there is a few things that need to be done with the code but my problem is that I can't get the thing to run at all I've downloaded a variety of ruby editors to try and use some error-checking features but I can't seem to figure it out. All of my brackets are closed and I've ended all my evaluations. If someone could skim through this and maybe help me out it would be greatly appreciated. I've tried making various other scripts and it always seems to end this way. Anyway heres the code:



close_lootsack = false
junk_nouns = [ 'lockpick', 'doughnut', 'tart', 'cupcake', 'ribbon', 'cookie', 'horseshoe', 'muffin' ]
junk_regex = /^(?:scratched|corroded|polished|shiny|tarnished|de nted|rusty|bent) (?:ring|medallion|earring|anklet|bracelet|fork|spo on|plate|coin|cup|nail|doorknob)$|^smooth stone$|^steel shield$|^some tree bark$|^table leg$|^moldy bone$|^some tattered cloth$|^piece of iron$|^chipped brick$|^scratched steel helm$/

disk = GameObj.loot.find { |obj| obj.name =~ /#{Char.name} disk$/ }

if UserVars.lootsack.nil? or UserVars.lootsack.empty?
echo 'error: lootsack is not set (;set change lootsack <container>)'
exit
end
unless lootsack = GameObj.inv.find { |obj| obj.name =~ /#{Regexp.escape(UserVars.lootsack.strip)}/i } || GameObj.inv.find { |obj| obj.name =~ /#{Regexp.escape(UserVars.lootsack).sub(' ', ' .*')}/i }
echo "error: unable to find your lootsack #{UserVars.lootsack} in your inventory"
exit
end
if lootsack.contents.nil?
open_result = dothis "open ##{lootsack.id}", /You open|already open/
close_lootsack = true if open_result =~ /You open/
if lootsack.contents.nil?
dothis "look in ##{lootsack.id}", /In the .* you see/
if lootsack.contents.nil?
echo 'fixme (1)'
exit
end
end
end

unless (GameObj.right_hand.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/) or (GameObj.left_hand.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/) or lootsack.contents.find { |obj| obj.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/ }
if disk and disk.contents.nil?
dothistimeout "look in ##{disk.id}", 2, /^In the|^There is nothing in there\.$/
end
unless disk.contents.any? { |obj| obj.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/ }
echo 'no boxes'
exit
end
end

start_script 'go2name', [ 'Ledron', '_disable_confirm_' ]
wait_while { running?('go2') }

empty_hands

unless trash = (GameObj.room_desc.to_a + GameObj.loot.to_a).find { |obj| obj.noun =~ /^(?:crate|barrel|wastebarrel|casket)$/ } || trash = (GameObj.room_desc.to_a + GameObj.loot.to_a).find { |obj| obj.noun == 'coffer' }
echo 'warning: failed to find a trash container'
end


open_box = proc { |box|
unless (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
dothistimeout "get ##{box.id}", 3, /^You remove|^Get what\?$/
end
if (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You offer|^Your .*? won't fit on .*?\.$/
end
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You put|^Your .*? won't fit on .*?\.$/

end
}



if GameObj.right_hand.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/
open_box.call(GameObj.right_hand)
end
if GameObj.left_hand.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/
open_box.call(GameObj.left_hand)
end
for obj in lootsack.contents
if obj.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/
open_box.call(obj)
end
end

if disk
50.times { break if GameObj.loot.any? { |obj| obj.id == disk.id }; sleep 0.1 }
if GameObj.loot.any? { |obj| obj.id == disk.id }
if disk.contents.nil?
dothistimeout "look in ##{disk.id}", 2, /^In the|^There is nothing in there\.$/
end
for obj in disk.contents
if obj.noun =~ /^(?:box|strongbox|chest|coffer|trunk)$/
open_box.call(obj)
end
end
end
end

fill_hands

fput "close ##{lootsack.id}" if close_lootsack

Tillmen
09-29-2010, 01:16 AM
For the open_box proc, you have this:

open_box = proc { |box|
unless (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
dothistimeout "get ##{box.id}", 3, /^You remove|^Get what\?$/
end
if (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You offer|^Your .*? won't fit on .*?\.$/
end
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You put|^Your .*? won't fit on .*?\.$/

end
}


Proper indenting makes it much easier to find the errors.


open_box = proc { |box|
unless (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
dothistimeout "get ##{box.id}", 3, /^You remove|^Get what\?$/
end
if (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You offer|^Your .*? won't fit on .*?\.$/
end
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You put|^Your .*? won't fit on .*?\.$/
end
}


I'm not sure, but I'm guessing you were going for:

open_box = proc { |box|
unless (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
dothistimeout "get ##{box.id}", 3, /^You remove|^Get what\?$/
end
if (GameObj.right_hand.id == box.id) or (GameObj.left_hand.id == box.id)
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You offer|^Your .*? won't fit on .*?\.$/
end
}

Kaelozim
09-29-2010, 10:47 AM
Ok, thanks Tillmen. That fixed everything but I'm not sure what the problem was for future reference?

Liagala
09-29-2010, 10:53 AM
Ok, thanks Tillmen. That fixed everything but I'm not sure what the problem was for future reference?


put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You offer|^Your .*? won't fit on .*?\.$/
end
put_result = dothistimeout "give ##{box.id} to Ledron", 5, /^You put|^Your .*? won't fit on .*?\.$/
end


You had this twice.

Gibreficul
09-29-2010, 03:02 PM
use_pickbot.lic

Kaelozim
09-29-2010, 05:40 PM
I can't because not every has the back-end to it. :) So what I've done is re-tweaked the npcpicker that Tillmen made and got it setup to use the picker.lic back-end. It's fully functional now but before I upload to repository I'm going to add self-picking functionality to run in tandem with bigshot so if your able to pick you will pick your own boxes after a hunt.

Gibreficul
09-29-2010, 06:30 PM
offer/accept takes too long and requires both ends to function perfectly. If something goes wrong, both scripts could halt.

Something as simple as, "picker can only have one outstanding offer at a time" can totally screw the whole system.

Kaelozim
09-29-2010, 07:08 PM
True that on the "faultability?" of the two interacting but I'm pretty much just writing this as a 1-on-1 script for now. Instead of a bunch of people using the same picker I've just set it up for personal use for now but I don't think a line would be that hard to throw in there with a simple array containing the names in the list and the use of some lnet private message features to inform the client when it is their turn if there is a line. As far as speed the way I have it set-up is very efficient. As ;picker is picking I've got it to empty the previous box and ready the next one, then accept and give the next one to the locksmith. Really, the only thing as far as speed that I'm waiting on is round-time, but again I've only been using it for a day so I'll do some more testing.
Hands-free is really a non-issue because the intent is again to run in tandem with bigshot and sloot sell which can be configured to end a hunt with both hands empty. Now, as far as I can foresee the only issue would be someone offering an item to either client or server while this whole process is going on and again. If that person doing the offering is not the name of the person in the current element of the array decline. Or even better setting it up to only deal with people on my friends list could alleviate some uncertainty. I'm at school right now so I should have some sort of beta on the repo by this weekend.