PDA

View Full Version : My Scripts (Repository & Snippets)



DaCapn
07-17-2012, 02:35 AM
Just wanted to make a place where I post a list of my scripts that I'd like to share. Scripts on the repo are in this post, random snippets are in the next post.

Feel free to post if you have a bug report or feature suggestion.

A couple of notes:
- Please don't post with random praise/hate which clutters the thread
- I may not choose to take any action on any posts in this thread
- Check the repository info (;repository help) and comments in the code
- Background scripts: work well as favorites
- Active scripts: intended to run, complete a task, then exit
- Each script has an italicized "to-do" list which is more of a "considering-but-currently-too-lazy to-do" or "don't-forget-this-idea" list

----- Repository Scripts -----

amunet.lic - Keeps the amunet on at all times (CoL, GoS, amulets). Has a setting for where you keep your amulets. Anti-magic zone aware. (Background script)
fire.lic - Ranged script for firing bows. It's entirely about aiming, target prioritization, etc. (Active script)
group2.lic - Group-friendly go2. Basically just steals step2 code and puts a check for group integrity. (Active script)
Check for successful HOLD action. Figure out why starting in Icemule TC only makes one step.
instrumentrest.lic - Plays an instrument if you're resting at a node. Stores it when you leave. (Background script)
manabattery.lic - Sends/requests mana between two characters running this script. (Active script)
orbsort.lic - Loresings to gems to sort out orbs. (Active script)
Check that ultra low value orbs get sorted
shopsearch - Searches some playershop containers for items to buy. Mostly for my shop and gem jars I sell. (Active script)
Add more shop containers, maybe switch to using room_desc
tracklumnis.lic - Tracks exp gained on Lumnis cycle. Has code to insert into xp.lic which shows projected Lumnis total. (Background script)
Logging feature
unlock.lic - Uses 407 to unlock something. Good for the rolaren gate as well as boxes. Has some options. (Active script)
untrammel.lic - Waits for room webs or webbed PCs. Casts 209 if known, uses untrammel dust otherwise. (Background script)

DaCapn
07-17-2012, 02:35 AM
This is where I post snippets of code. These are for people who know what they're doing or want ideas. I'm likely to ignore questions/suggestions/feedback since they suit all of my needs perfectly.

Details about snippets:
- Not repo-worthy in my opinion for some reason
- Could be very situational, character-specific, not particularly fool-proof, unpolished, etc
- Mostly here as primers for people
- Probably won't get updated
- May use some global variables that I define at the beginning of my library

----- Snippets -----

Safe sign of wracking

$library_deflist['sign_of_wracking'] = ['utility','Makes sure that it is safe to use sign of wracking before wracking']
def sign_of_wracking
if Society.status == "Council of Light" and Society.rank >= 18
drainpool = [9912,9913,9914].find_all { |sign| active?"#{sign}" }.size
if active?9916 then drainpool += 3; end
if checkspirit >= 6+drainpool and (checkpcs.nil? or hidden?) then fput "sign of wracking"
else echo "### Unsafe to wrack!"
end
else
echo "### You don't know sign of wracking!"
end
end

Move objects by type

$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/
if type =~ /trap/
GameObj.right_hand.contents.find_all { |obj| $trap_components.include?(obj.name) }.each { |obj|
fput "_drag ##{obj.id} ##{GameObj[container].id}"
}
else
GameObj.right_hand.contents.find_all { |obj| obj.type =~ /#{type}/i }.each { |obj|
fput "_drag ##{obj.id} ##{GameObj[container].id}"
}
end
else num.times { fput "_drag ##{GameObj.right_hand.contents.find{ |obj| obj.type =~ /#{type}/i }.id} ##{GameObj[container].id}" }
end
end

Upgraded 10deeds

$library_deflist['ten_deeds'] = ['utility','Buys 10 deeds with dwarf-cut rubies at the Landing']
def ten_deeds
# Adapted from '10deeds' on the repo
# Go to the bank
start_script 'go2', [ '400', '_disable_confirm_' ]; wait_while { running?('go2') }
if checkleft then lefthand = GameObj.left_hand; multifput "open my #{Lich.lootsack}","put ##{lefthand.id} in my #{Lich.lootsack}"; end
if checkright then righthand = GameObj.right_hand; multifput "open my #{Lich.lootsack}","put ##{righthand.id} in my #{Lich.lootsack}"; end
fput "close my #{Lich.lootsack}"
fput "withdraw 45000"
# Buy rubies
start_script 'go2', [ '9269', '_disable_confirm_' ]; wait_while { running?('go2') }
fput "open my #{Lich.lootsack}"
10.times{multifput("order 14","buy","put ruby in my #{Lich.lootsack}")}
fput "close my #{Lich.lootsack}"
# Go to temple
start_script 'go2', [ '4044', '_disable_confirm_' ]; wait_while { running?('go2') }
fput "open my #{Lich.lootsack}"
10.times{multifput("go tapestry","ring chime with mallet","ring chime with mallet","kneel","get my ruby from my #{Lich.lootsack}","drop my ruby","ring chime with mallet","out")}
if !lefthand.nil? then fput "get ##{lefthand.id}"; end
if !righthand.nil? then fput "get ##{righthand.id}"; end
fput "close my #{Lich.lootsack}"
# Return to Landing bank
start_script 'go2', [ '400', '_disable_confirm_' ]; wait_while { running?('go2') }
echo "You should have 10 more deeds now"
end

Stance dance casting a bolt spell

$library_deflist['cast_bolt'] = ['utility','Stances and casts a bolt spell; (spell target)']
def cast_bolt(args)
arglist = args.split(" ")
spellnum = arglist.find { |val| val =~ /\d{3,4}/ }; arglist.delete(spellnum)
num = arglist.find { |val| $enumeratives.include?(val) }; arglist.delete(num)
targetname = arglist.join(" ")

if num.nil? then target = GameObj.npcs.find { |npc| npc.type =~ /aggressive/i and npc.status !~ /dead/ and npc.name =~ /#{targetname}/i }
else target = GameObj.npcs.find_all { |npc| npc.type =~ /aggressive/i and npc.status !~ /dead/ and npc.name =~ /#{targetname}/i }[$enumeratives.index(num)]
end

if target.nil? then echo "### Invalid target!"; return false
else
if !standing? then fput "stand"; waitrt?; end
waitcastrt?; multifput "prep #{spellnum}","stance offensive","cast ##{target.id}","stance defensive"
end
end

Wander hard-coded areas

$library_deflist['wander'] = ['utility', 'Custom wander routine with defined locations (location,help)']
def wander(arg)
if arg =~ /\bhelp\b/i
echo "### ----- Wander Locations ------------------------------------------------- ###"
$wander_locations.each { |k,v| echo "\# #{k}\t-\t#{v.size} rooms\t\t\t\t\t\t"}
echo "### ------------------------------------------------------------------------ ###"
exit
end
wander_list = Hash.new
$wander_locations.each { |k,v|
if v.include?(Room.current.id)
v.each { |roomid| wander_list[roomid] = 0 }
elsif k =~ /#{arg}/i
v.each { |roomid| wander_list[roomid] = 0 }
start_script "go2",[v[0]]; wait_until { !running?"go2" }
else
echo "### Bad argument or bad location"
return false
end
}
if wander_list.size > 0
until GameObj.npcs.any? { |npc| npc.name =~ /#{arg}/i }
wander_list[Room.current.id] += 1
destination = wander_list.sort { |k,v| k[1] <=> v[1] }[0]
start_script "step2",["#{destination[0]}"]; wait_until { !running?"step2" }
end
end
end

Looting functions


# Used for loot_room
$metal_list = ["Alexandrite","Bronze","Coraesine","Drakar","Drake","Eahnor","Eonake","Faenor","Feras","Glaes","Golvern","Gornar","Imflass","Invar","Iron","Ironwood","Kelyn","Krodera","Mithglin","Mithril","Obsidian","Ora","Razern","Rhimar","Rolaren","Urglaes","Urnon","Vaalorn","Veil","Veniom","Vultite","Zorchar"]
$wood_list = ["Carmiln","Deringo","Faewood","Fireleaf","Glowbark","Hoarbeam","Ilthorn","Ipantor","Kakore","Lor","Mesille","Modwir","Mossbark","Orase","Rowan","Ruic","Sephwir","Villswood","Witchwood","Wyrwood","Yew"]
$crap_adjectives = ["moldy","moth-eaten","ragged","ripped","rotted","slashed","sloppy","tattered","torn"]
$crap_list = ["wolifrew lichen","rose-marrow potion","bandana","woven cloak","pair of unlaced boots"]
# Use for loot_monster
$badloot_list = ["glacei","golem","elemental"]

$library_deflist['loot_monsters'] = ['utility','Searches all dead monsters in the room']
def loot_monsters
GameObj.npcs.each { |npc| waitrt?; if npc.status=~ /dead/ and !$badloot_list.include?(npc.noun) then fput "loot ##{npc.id}"; end }
end

$library_deflist['loot_disk'] = ['utility','Grabs an item and puts it in your disk; (item)']
def loot_disk(item)
# Manage full hands
if checkright and checkleft
handsfull = true
fput "open my #{Lich.lootsack}"
if GameObj.left_hand.name =~ /shield|buckler|targe|heater|parma|aegis|scutum|man tlet|pavis/i
stoweditem = [GameObj.left_hand,"worn"]; fput "wear ##{stoweditem[0].id}"
elsif GameObj.left_hand.noun =~ /bow/
stoweditem = [GameObj.right_hand,"stowed"]; fput "put ##{stoweditem[0].id} in my #{Lich.lootsack}"
else stoweditem = [GameObj.left_hand,"stowed"]; fput "put ##{stoweditem[0].id} in my #{Lich.lootsack}"
end
fput "close my #{Lich.lootsack}"
else handsfull = false
end

fput "open #{Char.name} disk"
item.each { |obj|
lootitem = GameObj.loot.find { |thing| thing.name =~ /#{obj}/i }
multifput "get ##{lootitem.id}","put ##{lootitem.id} in #{Char.name} disk"; pause 0.25
if checkleft =~ /#{lootitem.noun}/ or checkright =~ /#{lootitem.noun}/
multifput "open my #{Lich.lootsack}","put ##{obj.id} in my #{Lich.lootsack}","close my #{Lich.lootsack}"
end
}
fput "close #{Char.name} disk"

# Manage full hands
if handsfull
if stoweditem[1] =~ /worn/ then fput "remove ##{stoweditem[0].id}"
else multifput "open my #{Lich.lootsack}","get ##{stoweditem[0].id} from my #{Lich.lootsack}","close my #{Lich.lootsack}"; end
end
end

$library_deflist['loot_stow'] = ['utility','Grabs an item and puts it in your lootsack; (item)']
def loot_stow(item)
# Manage full hands
if checkright and checkleft
handsfull = true
fput "open my #{Lich.lootsack}"
if GameObj.left_hand.name =~ /shield|buckler|targe|heater|parma|aegis|scutum|man tlet|pavis/i
stoweditem = [GameObj.left_hand,"worn"]; fput "wear ##{stoweditem[0].id}"
elsif GameObj.left_hand.noun =~ /bow/
stoweditem = [GameObj.right_hand,"stowed"]; fput "put ##{stoweditem[0].id} in my #{Lich.lootsack}"
else stoweditem = [GameObj.left_hand,"stowed"]; fput "put ##{stoweditem[0].id} in my #{Lich.lootsack}"
end
fput "close my #{Lich.lootsack}"
else handsfull = false
end

fput "open my #{Lich.lootsack}"
item.each { |obj|
lootitem = GameObj.loot.find { |thing| thing.name =~ /#{obj}/i }
multifput "get ##{lootitem.id}","put ##{lootitem.id} in my #{Lich.lootsack}"
}
fput "close my #{Lich.lootsack}"

# Manage full hands
if handsfull
if stoweditem[1] =~ /worn/ then fput "remove ##{stoweditem[0].id}"
else multifput "open my #{Lich.lootsack}","get ##{stoweditem[0].id} from my #{Lich.lootsack}","close my #{Lich.lootsack}"; end
end
end

$library_deflist['loot_bundle'] = ['utility','Consolidates backpacks full of loot at a table']
def loot_bundle
packlist = GameObj.loot.find_all { |obj| obj.name =~ /heavy backpack/ }
packlist.each { |obj| multifput "open ##{obj.id}","look in ##{obj.id}" }
GameObj.loot.find_all { |obj| obj.type !~ /clothing/ and obj.noun !~ /disk|coins/ }.each { |obj|
fput "_drag ##{obj.id} ##{packlist[0].id}"
}
while packlist.size > 1
multifput "get ##{packlist[1].id}","empty ##{packlist[1].id} in ##{packlist[0].id}"; waitrt?
if !packlist[1].contents.empty?
packlist[1].contents.each { |obj| fput "_drag ##{obj.id} ##{packlist[0].id}"}
end
multifput "drop ##{packlist[1].id}","clean table"
packlist.delete_at(1)
end
end

$library_deflist['loot_room'] = ['utility','Gather all loot from the room, skipping crap']
def loot_room
# Build array of good loot in the room
lootlist=[]
GameObj.loot.each { |obj|
goodloot = false
# Never loot
if obj.type =~ /food|junk|ammo|cursed/ then goodloot = false
# Other junk
elsif !$crap_list.find { |crap| obj.name =~ /#{crap}/i }.nil? then goodloot = false
# Always loot
elsif obj.type =~ /reagent|note|box|gem|magic|scroll|wand|skin|instru ment|jar|jewelry|herb|lockpick/ then goodloot = true
# Exceptions
elsif obj.type =~ /armor|weapon/
if !$metal_list.find { |mat| obj.name =~ /#{mat}/i }.nil? then goodloot = true; end
if !$wood_list.find { |mat| obj.name =~ /#{mat}/i }.nil? then goodloot = true; end
elsif obj.type =~ /clothing/
if $crap_adjectives.find { |mat| obj.name =~ /#{mat}/i }.nil? then goodloot = true; end
else goodloot = false; end
# Create array of good loot
if goodloot then lootlist.push(obj); end
}

if lootlist.size >= 1
fput "open my #{Lich.lootsack}"
# Manage full hands
if checkright and checkleft
handsfull = true
if GameObj.left_hand.name =~ /shield|buckler|targe|heater|parma|aegis|scutum|man tlet|pavis/i
stoweditem = [GameObj.left_hand,"worn"]; fput "wear ##{stoweditem[0].id}"
elsif GameObj.left_hand.noun =~ /bow/
stoweditem = [GameObj.right_hand,"stowed"]; fput "put ##{stoweditem[0].id} in my #{Lich.lootsack}"
else stoweditem = [GameObj.left_hand,"stowed"]; fput "put ##{stoweditem[0].id} in my #{Lich.lootsack}"
end
else handsfull = false
end

# Get all of the good loot
lootlist.each { |obj|
# Put boxes in disk if one exists
if obj.type =~ /box/ and GameObj.loot.any? { |item| item.name =~ /#{Char.name} disk/i }
multifput "open #{Char.name} disk","get ##{obj.id}","put ##{obj.id} in #{Char.name} disk","close #{Char.name} disk"
if GameObj.right_hand.type =~ /box/ or GameObj.left_hand.type =~ /box/ then fput "put ##{obj.id} in my #{Lich.lootsack}"; end
# Otherwise stow
else
if obj.noun == Lich.lootsack then multifput "get ##{obj.id}","put ##{obj.id} in my second #{Lich.lootsack}"
else multifput "get ##{obj.id}","put ##{obj.id} in my #{Lich.lootsack}"
end
end
}

# Manage full hands
if handsfull
if stoweditem[1] =~ /worn/ then fput "remove ##{stoweditem[0].id}"
else fput "get ##{stoweditem[0].id} from my #{Lich.lootsack}"; end
end
fput "close my #{Lich.lootsack}"
end
end

Tillmen
07-17-2012, 04:37 AM
I'm likely to ignore questions/suggestions/feedback since they suit all of my needs perfectly.

I don't care!



$library_deflist['sign_of_wracking'] = ['utility','Makes sure that it is safe to use sign of wracking before wracking']
def sign_of_wracking
if Society.status == "Council of Light" and Society.rank >= 18
drainpool = [9912,9913,9914].find_all { |sign| active?"#{sign}" }.size
if active?9916 then drainpool += 3; end
if checkspirit >= 6+drainpool and (checkpcs.nil? or hidden?) then fput "sign of wracking"
else echo "### Unsafe to wrack!"
end
else
echo "### You don't know sign of wracking!"
end
end


This doesn't check for sign of madness, which makes it not very safe. You could have used Spell['Sign of Wracking'].affordable? or Spell[9918].affordable?, which checks for all of them.

Also, fput is very risky for something like sign of wracking. fput most often fails by not trying again, but it can also fail by trying again when it shouldn't. The problem is it only pays attention to the next game line recieved after it sends a command, which may have nothing to do with the command at all. Most of the time problems with fput are caused by lag, but they can also be caused by a busy room or just really bad luck. It would be safter to use put, which won't retry on its own, and then check for the relevent game lines and maybe use a timeout. Then if the timeout is reached, you could send a different game command just to see if you're stuck in lag. When a response to the other command is recieved, you can be sure that the attempt to wrack has finished either succeeding or failing, and check for spirit again before retrying if it failed. If you don't feel like doing all that, you can use Spell['Sign of Wracking'].cast, or Spell[9918].cast, or cast 'sign of wracking', which does all that stuff I said.

DaCapn
07-17-2012, 02:52 PM
I don't care!
There's always one wise guy...


This doesn't check for sign of madness, which makes it not very safe. You could have used Spell['Sign of Wracking'].affordable? or Spell[9918].affordable?, which checks for all of them.

Also, fput is very risky for something like sign of wracking. fput most often fails by not trying again, but it can also fail by trying again when it shouldn't. The problem is it only pays attention to the next game line recieved after it sends a command, which may have nothing to do with the command at all. Most of the time problems with fput are caused by lag, but they can also be caused by a busy room or just really bad luck. It would be safter to use put, which won't retry on its own, and then check for the relevent game lines and maybe use a timeout. Then if the timeout is reached, you could send a different game command just to see if you're stuck in lag. When a response to the other command is recieved, you can be sure that the attempt to wrack has finished either succeeding or failing, and check for spirit again before retrying if it failed. If you don't feel like doing all that, you can use Spell['Sign of Wracking'].cast, or Spell[9918].cast, or cast 'sign of wracking', which does all that stuff I said.

Madness is 9916, which it checks.

I expected the affordable? method to just check what was left of the pool, rather than what would be left. That's nice. You've got a much cuter way of doing it. Sign of madness costs 3 spirit, not 5, though, right?
elsif (self.spirit_cost > 0) and not checkspirit(self.spirit_cost + 1 + [ 9912, 9913, 9914, 9916, 9916, 9916, 9916, 9916 ].delete_if { |num| !Spell[num].active? }.length)

Also, I saw the comment below and thought I might mention that I made a bard multi-song renewal offset thread to try and sort out the exact values (since KP is wrong) but I basically stopped playing my bard and lost interest. Just wanted you to know that there's still some unknowns there.
# fixme: deal with them dirty bards!

Thanks a lot for the fput suggestion. I have a few other places that I might convert.