PDA

View Full Version : moving item script



zzentar
09-11-2014, 02:05 PM
playing around trying to learn regex, I made this stupid script. Useful to me and maybe to you.

Usage is ;<script_name> <item_type> <from_container> <to_container>

It moves any type of item (armor, weapon, reagent, gem, clothing, ect ect) from <from_container> to <to_container>


if script.vars[0] =~ /(.*)\s+(.*)\s+(.*)/
item_type = $1
container1 = $2
container2 = $3
GameObj[container1].contents.each {|item| if item.type =~ /#{item_type}/;fput "get ##{item.id} ";fput "put ##{item.id} in my #{GameObj[container2]}";end}
end

I tried for hours to make this an Alias, but finally gave up.



Drafix gave me the alias
;alias add mover=;eq vars=%w(\?); GameObj[vars[1]].contents.each {|item| if item.type =~ /#{vars[0]}/;fput "get ##{item.id} ";fput "put ##{item.id} in my #{GameObj[vars[2]]}";end}

usage for alias same as the script above
mover <item_type> <from_container> <to_container>

DaCapn
09-11-2014, 02:54 PM
Better than aliases is to keep these small things together in a favorited library and call them with an exec script. Easy to modify, easy to look at, better portability, allows the functions to be used in other scripts, etc.

Something in my library that's similar to what you have:

$library_deflist['move_objs'] = ['utility','Moves objects of a type from container in right hand to new container; (type,num,container)']
def move_objs(type,num,container)
fput "open ##{GameObj.right_hand.id}"
if num =~ /all/
GameObj.right_hand.contents.find_all { |obj| obj.type =~ /#{type}/i }.each { |obj|
fput "_drag ##{obj.id} ##{GameObj[container].id}"
}
else num.times { fput "_drag ##{GameObj.right_hand.contents.find{ |obj| obj.type =~ /#{type}/i }.id} ##{GameObj[container].id}" }
end
end

This is a small piece of what my alias list looks like:

bank => ;e errand("bank")
errands => ;e errand(["gems","bank","pawn","bank","shop"])
disk => ;e loot_disk("\?")
grab => ;e loot_stow("\?")
enc => ;e echo percentencumbrance
eremove => ;e enhancive("remove")
ewear => ;e enhancive("wear")

zzentar
09-11-2014, 04:16 PM
I only have a couple things in my library, nothing special just definitions I use in other personal scripts.

I disagree with you about aliases.
I make a lot of my small utility scripts into oneliners, that I can macro or make an alias
an example is my alias selling (Thats not really what it looks like, short for sell ingredients) , I just type selling <container>
;alias add selling=;eq container = "\?"; silence_me;GameObj[container].contents.each {|item| if item.type =~ /reagent/;fput "get ##{item.id}";fput "sell ##{item.id}";end}

DaCapn
09-11-2014, 10:14 PM
I disagree with you about aliases.


Better than aliases is to keep these small things together in a favorited library and call them with an exec script. Easy to modify, easy to look at, better portability, allows the functions to be used in other scripts, etc.

What is there to disagree with?