PDA

View Full Version : Body Count



Drunken Durfin
09-25-2009, 10:55 AM
I want to write a little bit of code that keeps track of my kills. The simple way to do it would be this:


bodycount = 0

loop {
waitfor "You search the"
bodycount = bodycount + 1
echo "Bodycount = " + bodycount.to_s
}
exit

But, because I am hunting in the temple, there are several critters that either cannot be searched (water elementals go poof and drop gems as soon as they die) and others you might miss searching, as they vanish if you are too slow.

Any suggestions?

crb
09-25-2009, 01:27 PM
do it on the death message, but you'll have to build a table of all possible death messages, most critters have at least a handful, and some spells create their own. And of course you won't know you killed it as opposed to someone else in the room.

The way I do it, not real time, is to set a trigger to ON when I make an attack, and then if I see a death message prior to seeing an RT message to mark it. That way I know it was my attack.

Drunken Durfin
09-25-2009, 02:06 PM
I was afraid of that.

So, as far as death messaging handling, beside doing something like this:



if clear.find {|line| line =~ /Death message 01|death message 02|death message 03|death messgage 04/} then
UpdateCount
end


Is there a cleaner, and easier, way to set up the count?

Drunken Durfin
09-25-2009, 04:23 PM
This is what I have so far:

http://drunkendurfin.webs.com/scoreboard.jpg

Eventually I want to add more stuff, but I really want to get the body count working well before I move ahead, since critter death is how I am triggering the loop.

Once it is done I will put in a config that will allow you to pick and choose what is displayed in the window. Some of the options I am planning on adding are silvers gathered, boxes found, and gems.

Smythe
09-25-2009, 05:01 PM
Use'm if ya want.

==========

@deathmsg = [ "gurgles", "expiring", "weeping", "dies" ]

if clear.find { |line| line =~ /#{@deathmsg}/i } then UpdateCount end

==========
- Smythe

Drunken Durfin
09-26-2009, 03:17 PM
I went with a match on attack (AS, CS and MB) and searching that checks to see if the fame amount changes. If the critter vanishes or you miss the search your fame will increase and you get credit on Scoreboard. Credit is also given on successful search.

http://drunkendurfin.webs.com/scoreboard02.jpg

I have not uploaded it to the repository yet, there are still some changes I want to make. If you want to play with it in its current state here is the current code:


#Durfin's Scoreboard
#Tracks fame increase on a per session and per critter basis.
#Also logs number of kills.

check_fame = proc {
action = proc { |server_string|
if server_string =~ /You are a/
DownstreamHook.remove('go2_check_fame')
nil
elsif server_string =~ /Your personal fame is (\d+)/
$Scoreboard_check_fame = $1.to_i

nil
else
server_string
end
}

$Scoreboard_check_fame = nil
DownstreamHook.add('go2_check_fame', action)
$_SERVER_.puts "<c>fame\n"
wait_while { $Scoreboard_check_fame.nil? }
currentfame = $Scoreboard_check_fame
$Scoreboard_check_fame = nil
currentfame
}

openLines = ["<closeDialog id='Scoreboard'/>",
"<openDialog type='dynamic' id='Scoreboard' title='Score Board' target='Scoreboard' location='main' top='0' left='0' align='nw' height='200' width='210' resident='false'>",
"<dialogData id='Scoreboard'>"]
tosend = openLines.join

nIFame = check_fame.call

openLines = [
"<label id='ifame' value='Initial Fame:' justify='4' align='nw' top='5' left='3' height='15' width='110'/>",
"<label id='cfame' value='Current Fame:' justify='4' anchor_left='nothing' anchor_top='ifame' top='4' left='3' height='15' width='110'/>",
"<label id='session' value='This Session:' justify='4' anchor_left='nothing' anchor_top='cfame' top='4' left='3' height='15' width='110'/>",
"<label id='last' value='Last Critter:' justify='4' anchor_left='nothing' anchor_top='session' top='4' left='3' height='15' width='110'/>",
"<label id='critters' value='Critters Killed:' justify='4' anchor_left='nothing' anchor_top='last' top='4' left='3' height='15' width='110'/>",
"<label id='ifamev' value='#{nIFame}' justify='6' anchor_left='ifame' align='n' top='5' left='0' height='15' width='75'/>",
"<label id='cfamev' value='#{nIFame}' justify='6' anchor_left='cfame' anchor_top='ifamev' top='4' left='0' height='15' width='75'/>",
"<label id='sessionv' value='0' justify='6' anchor_left='last' anchor_top='cfamev' top='4' left='0' height='15' width='75'/>",
"<label id='lastv' value='0' justify='6' anchor_left='last' anchor_top='session' top='4' left='0' height='15' width='75'/>",
"<label id='crittersv' value='0' justify='6' anchor_left='last' anchor_top='lastv' top='4' left='0' height='15' width='75'/>",
]
tosend += openLines.join
tosend += "</dialogData></openDialog>"
puts(tosend)


nBodyCount = 0
nSession = 0
nPreviousFame = nIFame

loop {
nFameThen = check_fame.call
waitfor "AS: +","CS: +","MB: +","you search"
nFameNow = check_fame.call

if nFameNow > nPreviousFame then
nPreviousFame = nFameNow
nFameCritter = nFameNow - nFameThen
nBodyCount = nBodyCount + 1
nSession = nSession + nFameCritter
doLines = "<dialogData id='Scoreboard'>"
doLines += "<label id='cfamev' value='#{nFameNow}' justify='6' anchor_left='cfame' anchor_top='ifamev' top='4' left='0' height='15' width='75'/>"
doLines += "<label id='sessionv' value='#{nSession}' justify='6' anchor_left='last' anchor_top='cfamev' top='4' left='0' height='15' width='75'/>"
doLines += "<label id='lastv' value='#{nFameCritter}' justify='6' anchor_left='last' anchor_top='sessionv' top='4' left='0' height='15' width='75'/>"
doLines += "<label id='crittersv' value='#{nBodyCount}' justify='6' anchor_left='last' anchor_top='lastv' top='4' left='0' height='15' width='75'/>"
doLines += "</dialogData>"
puts(doLines) if doLines != "<dialogData id='Scoreboard'></dialogData>"
end

}

Joseph
09-26-2009, 03:35 PM
reget is joo friend.

Drunken Durfin
09-26-2009, 03:51 PM
How would you implement it here?

Alorn15
09-26-2009, 03:58 PM
You could do reget 5 "silvers" after every search for your silvers implementation.

I've always been hesitant to use reget, though. If I'm reading the documentation right, there's no way to guarantee that you won't reget directly after a ram clear. And with clears every two minutes, it doesn't seem unlikely.

Tillmen
09-26-2009, 05:42 PM
If you're using my version of Lich, the ram buffer doesn't clear completly. After it gets up to 250 lines, it writes 50 lines to file, so you have at least 200 lines from reget. Something like half of those are xml-only lines, though. Reget may be a bit buggy right now. There's a chance that the xml stripping part of it will conflict with the xml stripping for scripts, and scripts stop getting game lines until you restart. This is fixed in Lich v4, which I'm still having trouble releasing because of Windows. If you're using Shaelun's version of Lich, reget may crash Lich. There's also the option of using find or find_all on $_SERVERBUFFER_.

Here's an example of that:



my_ambush = false
ambush_room_count = XMLData.room_count

check_ambush = proc {
if my_ambush and (ambush_room_count == XMLData.room_count)
true
else
last_line = $_SERVERBUFFER_.reverse.find { |line| line =~ /<pushStream id='room'\/>|An? .*? fearfully exclaims, "It's an ambush!"|set of carefully concealed metal jaws|nearly invisible length of razor wire|carefully concealed inflated pouch|tiny shard of jet black crystal/ }
if last_line.nil?
my_ambush
elsif last_line =~ /<pushStream id='room'\/>/
my_ambush = false
else
ambush_room_count = XMLData.room_count
my_ambush = true
end
end
}

if check_ambush.call
# screw the pcs
else
# don't poach
end

Drunken Durfin
09-30-2009, 09:51 AM
Current incarnation is on the repository. Will update it with the silver portion...eventually. If there are other options you folks would like let me know and I'll see about adding them in.

Monsoon
09-30-2009, 09:53 AM
How about one-hit/cast kills? :D

Monsoon
09-30-2009, 06:55 PM
It inserts blank lines after each attack.

Also after >info.

Drunken Durfin
10-04-2009, 10:59 AM
It is not inserting blank lines, is just hiding the spam required needed to do the fame checks using downstreamhook. I don't know that there is any way to keep that from happening.

Tillmen
10-04-2009, 12:01 PM
The blank line is given by the game with the fame results, but not hidden by the script.



<output class="mono"/>
Your personal fame is 431.
You are a level 86 Halfling Wizard.

<output class=""/>


By looking for the output tag, you can get rid of the blank line. Here's some code that does that, and also turns your fame flag on if needed. I also got rid of the global variable.



check_fame = proc {
scoreboard_check_fame = nil
scoreboard_check_fame_active = false
action = proc { |server_string|
if server_string =~ /Your fame flag is turned off\./
$_SERVER_.puts "<c>set fame on\n"
nil
elsif server_string =~ /You will now be included in the fame lists\./
$_SERVER_.puts "<c>fame\n"
nil
elsif scoreboard_check_fame_active and server_string =~ /<output class=""\/>/
DownstreamHook.remove('scoreboard_check_fame')
server_string
elsif server_string =~ /Your personal fame is (\d+)/
scoreboard_check_fame = $1.to_i
scoreboard_check_fame_active = true
nil
elsif scoreboard_check_fame_active
nil
else
server_string
end
}
DownstreamHook.add('scoreboard_check_fame', action)
$_SERVER_.puts "<c>fame\n"
wait_while { scoreboard_check_fame.nil? }
scoreboard_check_fame
}

echo check_fame.call

Drunken Durfin
10-04-2009, 01:37 PM
Works great. Uploaded new version to the repository. Thanks.

Morrff
10-04-2009, 04:49 PM
;repo download scoreboard
--- Lich: repository active.
Contacting the Lich server... if it's busy, this will take awhile...

Downloading Scoreboard.lic in 3 secs. Kill the script if that's incorrect.
Beginning...
Done!
--- Lich: repository finished.
>;scoreboard
--- Lich: scoreboard active.
--- Error: scoreboard: uninitialized constant DownstreamHook
--- Lich: scoreboard has exited.
>;list
--- Lich: infomonitor, lichnet2.

Tillmen
10-04-2009, 04:52 PM
Your version of Lich is too old.

Morrff
10-04-2009, 06:47 PM
Your version of Lich is too old.

Bleh, busted!