PDA

View Full Version : GameObj question



glinty
07-28-2013, 02:48 PM
Hi all,
Finally decided to get my hands dirty with lich scripting. A gripe I've had for a while is that when using

;useherbs crate
in RR town commons, the script is unable to see if there are any herbs inside.
I've examined the useherbs.lic script and I see that it uses the GameObj class in order to get the id of the relevant herb container.
However, when I prod all the various arrays inside GameObj (loot, inv, room_desc) I don't see the crate object anywhere. I guess this explains why this script is borked on this particular issue.

How can I get a handle on the crate object if it's not present in the GameObj? On the off chance that it's relevant, I'm using ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

Cheers,
Glinty

DaCapn
07-28-2013, 08:04 PM
You're saying you get nothing crate-like with either of these?
;e GameObj.loot.each { |obj| echo obj.name }
;e GameObj.room_desc.each { |obj| echo obj.name }

EDIT: That is... While you're in the room with the crate?

zzentar
07-28-2013, 08:08 PM
the crate is
You're saying you get nothing crate-like with either of these?
;e GameObj.loot.each { |obj| echo obj.name }
;e GameObj.room_desc.each { |obj| echo obj.name }

EDIT: That is... While you're in the room with the crate?
the crate is under a bench or or something, not visible in a room look

DaCapn
07-28-2013, 08:59 PM
In that case, I'd suggest doing something like adding a line that looks under the bench and in the crate and then using GameObj.containers. I'm not really looking at useherbs right now. Whatever the case, it will require some doing.

GameObj.containers returns a hash. The keys are all of the known container IDs with contents in the room and the values are the contents (type array, each element of the array is a object class). For example:

;e GameObj.containers.each { |k,v| echo k,v.type }
Returns the IDs of the containers and the word "Array"
;e GameObj.containers.each { |k,v| echo k; v.each { |obj| echo obj.name } }
Returns the IDs of the containers and the name of all contents

Tillmen
07-29-2013, 01:14 AM
I updated useherbs so you can give it a container id.

Here's some code to find the id of the crate and use it to start useherbs. You could make it into an alias or a script or whatever.


;eq script.want_downstream_xml = true; result = dothistimeout 'look under bench', 3, /Under the .* you see/; if result =~ /exist="([^"]+)" noun="crate"/; start_script 'useherbs', [ 'in', "##{$1}" ]; else; echo 'aint got no crate'; end

zzentar
07-29-2013, 01:44 AM
LOL @ aint got no crate

glinty
07-29-2013, 03:23 AM
DaCapn, thanks for the tip. I think this is the solution I am looking for. Will try it when I get home from work.

Tillmen, thanks for the code snippet.

Buckwheet
07-29-2013, 08:46 AM
Thanks for the information. I was running into problems building a script to mass unload a premium locker with all the different containers inside the locker. This helped out quite a bit.

glinty
07-30-2013, 06:07 PM
Update on this issue..
Tillmen, I redownloaded useherbs in order to incorporate your changes. However there's still an issue.
When running the command you listed above, useherbs is actually able to look inside the crate and see the various herbs. Yet, at the stage where it should actually grab the herb from the container (line 1004), the commands returns "Get what?"


get_result = dothistimeout "get ##{herb.id}", 5, /^You (?:carefully )?remove|^Get what\?$|^Why don't you leave some for others\?$|^You need a free hand for that\.|^You need a free hand to pick that up\./

By making the following change to the command I was able to get it to work.


get_result = dothistimeout "get ##{herb.id} from crate", 5, /^You (?:carefully )?remove|^Get what\?$|^Why don't you leave some for others\?$|^You need a free hand for that\.|^You need a free hand to pick that up\./

Obviously hard coding the container is a terrible solution but it does show that the container has to be specified in the get command. I'll look into a more clever solution soon, maybe passing in argv[1] to the get command.

Cheers,
Glinty