View Full Version : Squelch usage?
JustDan
05-28-2011, 09:18 AM
What's the usage for squelching? Even better, is there a script on the repo that makes use of it, so I can see it in action, so as to incorporate it into a few of mine?
Thanks.
Tillmen
05-28-2011, 01:31 PM
Here's a proc that sends the info verb and squelches the output while figuring out how many silvers you have:
check_silvers = proc {
silvers = nil
action = proc { |server_string|
if server_string =~ /^\s*Name\:|^\s*Gender\:|^\s*Normal \(Bonus\)|^\s*Strength \(STR\)\:|^\s*Constitution \(CON\)\:|^\s*Dexterity \(DEX\)\:|^\s*Agility \(AGI\)\:|^\s*Discipline \(DIS\)\:|^\s*Aura \(AUR\)\:|^\s*Logic \(LOG\)\:|^\s*Intuition \(INT\)\:|^\s*Wisdom \(WIS\)\:|^\s*Influence \(INF\)\:/
nil
elsif server_string =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
silvers = $1.to_i
DownstreamHook.remove('go2_check_silvers')
nil
else
server_string
end
}
DownstreamHook.add('go2_check_silvers', action)
silence_me unless undo_silence = silence_me
put 'info'
silence_me if undo_silence
wait_until { silvers }
silvers
}
echo check_silvers.call
The action proc is called each time a game line comes in. If the proc returns nil, the line is squelched. If the proc returns a modified line, that line is sent to the frontend instead, after going through any other DownstreamHooks. Modified and squelched lines don't affect scripts. The action proc stays active until DownstreamHook.remove is called, even if the script that added the hook ends. You can't do anything time consuming in the proc, because the frontend and scripts won't get any new lines from the game until the proc finishes. The name of the hook (here it's go2_check_silvers) should be unique, because adding a second hook with the same name replaces the first.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.