PDA

View Full Version : Renian's Lich Scripts



Renian
04-03-2008, 06:29 PM
I'll be using this thread to dump my Lich scripts. Feel free to add your comments/improvements.

My first offering is a few functions that you could load at the start of any given script via the load "<script location/scriptname>" command at the top of a lich script.

unbox() simply drops all of your boxes that you have on you. Useful for farming boxes back to a table.

silvercheck() opens up your info and returns, as an integer, the amount of silvers you have.

arrowcount(container) looks at the first bundle of arrows it sees and counts them. I use this to see when I need to restock, and if the number gets below a certain point it automatically runs a restock script.



def unbox
boxes = ["coffer", "strongbox", "box", "trunk", "chest"]
i = 0
while i <= 4
fput "get my " + boxes[i]
target_line = matchtimeout 3, "Get what?", "You remove"
if target_line =~ /Get what?/
i = i + 1
end
if target_line =~ /You remove/
fput "drop my " + boxes[i]
end
end
end

def silvercheck
target_line = String.new
fput "info"
while (target_line =~ /Silver/) == nil
target_line = get
#echo target_line
if target_line =~ /Silver: (\d+)/
mysilvers = $1
return mysilvers.to_i
break
#The break is here because my regex logic was a little flawed. I kept it because it works.
end
end
end

def arrowcount(container)
fput "look arrows in my " + container
target_line = get
if target_line =~ /find (\d+) in the bundle/
myarrows = $1
end
return myarrows.to_i
end

BigWorm
04-03-2008, 11:28 PM
Nice functions. I was just about to write my own function to do unbox(). I'll probably add these to my library.

I made a couple changes to your code. It's mostly style stuff since all of what you posted works, but I saw you had the comment about the regex so I thought I'd clean it up a bit and did the same for unbox(). There's nothing of significance to change in arrowcount() IMHO.


def unbox
boxes = ["coffer", "strongbox", "box", "trunk", "chest"]

for type in boxes
target_line = ""
while target_line !~ /Get what?/
fput "get my #{type}"
target_line = matchtimeout 3, "Get what?", "You remove"
fput "drop my #{type}" if target_line =~ /You remove/
end
end
end

def silvercheck
fput "info"
target_line = get while target_line !~ /Silver/
if target_line =~ /Silver: (\d+)/
mysilvers = $1
return mysilvers.to_i
end
end

def arrowcount(container)
fput "look arrows in my " + container
target_line = get
if target_line =~ /find (\d+) in the bundle/
myarrows = $1
end
return myarrows.to_i
end

# Simple driver code for testing the functions
if ( variable[1] )
if variable[1] =~ /unbox/
unbox()
elsif variable[1] =~ /silver/
echo "You have #{silvercheck()} silvers on you."
end
end

Renian
04-04-2008, 12:10 AM
Wow thanks for that, especially because you just showed me the regex expression for does not equal. I was wondering what the hell that was.

I was trying to use !=~ at one point.

BigWorm
04-04-2008, 12:55 AM
No problem. There's always more than one way to do something in Ruby which is nice because it make the language flexible, but it can be overwhelming sometimes too.

Renian
05-21-2008, 09:13 PM
This really isn't a useful script yet. I started making it just a few moments ago, but I was fumbling around with regular expressions and correct commands, and just testing it as I go while looking at a Ruby reference. However, when I ran it, it has this peculiar effect: It causes the Wizard to fucking implode.

Yes, this script casts 720 on the Wizard. It sends no commands to the game, and won't harm your computer...I think. But I've ran it twice on mine and lol'd at my failure.



fput "info"
waitfor "Normal"
target_line = String.new
while target_line !~ /Silver/
target_line = gets.chomp
echo target_line
if target_line =~ /Strength/
echo target_line.grep(/(\d)/)
end
end

Renian
05-21-2008, 09:33 PM
Alright, I fixed it.

The point of the script was to parse your stat bonuses into an array for you to use. However, I wanted it to give the real bonus, not the base bonus, and it seems to work--unless it's different than your base bonus.

Yes, for some reason, it doesn't parse CON right if your stung. It probably does the same thing with other bonuses too, so I'll paste my code and see if you guys can figure it out.

If you just want it to parse your base bonuses, remove the $ at the end of this regex:

target_line.grep(/\((\d+)\)$/)

The $ is supposed to only parse the digits if it's at the end of the line. Don't know why it fails for different colored digits.



#parsestats.lic
fput "info"
target_line = String.new
bonus_array = Array.new.to_i
=begin
0 = STR
1 = CON
2 = DEX
3 = AGI
4 = DIS
5 = AUR
6 = LOG
7 = INT
8 = WIS
9 = INF
=end

while target_line !~ /Silver/
target_line = get
if target_line =~ /Strength|Constitution|Dexterity|Agility|Discipline |Aura|Logic|Intuition|Wisdom|Influence/
target_line.grep(/\((\d+)\)$/)
#echo $1
bonus_array.push($1.to_i)
end
end
=begin
This will echo all the stats it found if you uncomment it.
i = 0
until i == 10
echo bonus_array[i]
i += 1
end
=begin


EDIT: Holy shit, then I go and download something and realize how completely useless this script is thanks to the Stats.(statname) command. FAIL.
EDIT 2: Oh wait, does Stats.(statname) even allow you to select the enhanced section of your stat?

Shaelun
05-22-2008, 06:55 AM
... Oh wait, does Stats.(statname) even allow you to select the enhanced section of your stat?

The value Lich'll have stored will be whatever it saw when you last typed INFO. Assuming you're running infomonitor.lic, of course.

As an example, if you typed INFO with no spells up and your strength bonus was 15, Lich would then return the integer 15 if you used Stats.str[1] (or Char.str[1] -- most of your char info can be checked through the Char class like that; it's the same data regardless of how you look it up, so just use whichever seems more intuitive to you).

If you then, say, had 509 cast on you, but didn't type INFO, Lich would still think your strength bonus was 15. If you did type INFO though, it would store and return the modified bonus. As I type this it occurs to me that I haven't really checked that for like 2 years, and I have no spells that enhance my stats to test with... it should work like that, but it's possible I'm wrong.


I think you'd be a lot happier using a hash (sometimes called an "associative array" or "dictionary" in other langauges) instead of an array here, BTW. In a nutshell, a hash is almost identical to an array, except instead of integer numbers that represent the index position of an element, you can use anything (including integer numbers just like an array, if you're so inclined). For instance:


stat_hash = Hash.new
target_line = String.new

while target_line !~ /Silver/
target_line = get
if target_line =~ /(Strength|Constitution|Dexterity|et cetera)/
stat_name = $1
stat_value = target_line.slice(/\((\d+)\)$/).to_i
stat_hash[stat_name] = stat_value
end
end

stat_hash.keys.each { |stat_name|
echo "#{stat_name}: #{stat_hash[stat_name]}"
}

I tried to make it almost identical to your code, except the display of the stats... the keys method of hashes returns an array filled with all the values that the hash is using as keys -- a "hash key" is a value that the hash is using to store a particular value. The "hash key" for a hash does the same thing as an index value does for an array. Note though that there's absolutely no order associated with those keys, unlike an array.

If you weren't familiar with hashes, I thought I'd point it out since you're asking for suggestions; I used to use them everywhere.

Renian
05-22-2008, 05:15 PM
Yeah, I wasn't familiar with them. Thanks, Shaelun.