View Full Version : A simple ;exec script to have narost show a tag after it's been found
Catts
03-21-2013, 04:37 AM
I don't know ruby but I've tried to pick up a few things from this board and other sources
Basically someone shared this tag search script on lnet:
;e echo Room.current.find_nearest_by_tag("herb name")
So I mapped it to a key so that when I press it, it prompts me to type the herb name:
\x;e echo Room.current.find_nearest_by_tag("\?")\r
So then I found out narost will show rooms if you do ;narost 228 or whatever, as long as narost isn't already active. So my idea was first run
\x;e echo Room.current.find_nearest_by_tag("\?")\r
somehow store the echo'd room# as a variable?
;kill narost
put ;narost room# (that was echod)
I'd use this a lot I think...I just have no idea how to take the results and grab them for step 2.
[exec: 42] <--- is an example of what was echoed when I searched for the tag "some acantha leaf"
Any ideas would be welcome. Also if there's a way to do this within a SF script that'd be cool because I'm actually starting to figure that out. Ruby is a bit too complex to understand by glancing at
subzero
03-21-2013, 05:33 AM
I don't know ruby but I've tried to pick up a few things from this board and other sources
Basically someone shared this tag search script on lnet:
;e echo Room.current.find_nearest_by_tag("herb name")
So I mapped it to a key so that when I press it, it prompts me to type the herb name:
\x;e echo Room.current.find_nearest_by_tag("\?")\r
So then I found out narost will show rooms if you do ;narost 228 or whatever, as long as narost isn't already active. So my idea was first run
\x;e echo Room.current.find_nearest_by_tag("\?")\r
somehow store the echo'd room# as a variable?
;kill narost
put ;narost room# (that was echod)
I'd use this a lot I think...I just have no idea how to take the results and grab them for step 2.
[exec: 42] <--- is an example of what was echoed when I searched for the tag "some acantha leaf"
Any ideas would be welcome. Also if there's a way to do this within a SF script that'd be cool because I'm actually starting to figure that out. Ruby is a bit too complex to understand by glancing at
Try this (I'm not sure why you'd need to kill narost, so I'm leaving that out, but if you do need it you can always toss it in later):
x = Room.current.find_nearest_by_tag("#{script.vars[0]}")
start_script "narost", [x] unless script.vars.empty? || x == nil
Alias that to something: ;alias add whatever=;e start_script "script", ['\?']
The \? didn't seem to want to work when I tried to just alias the whole thing rather than make a script and call that with the alias, but it may still be possible somehow.
Catts
03-21-2013, 05:38 AM
\? only seems to work when I map an F key
Damn you did that fast...I can kinda see what's going on there. I'm starting to see how ruby is way better because you can call multiple scripts then have narost access that script.vars
So I basically need to create a script and save it in my /lich folder I"m guessing? Going to try that then let you know how it goes.
subzero
03-21-2013, 05:41 AM
lich\scripts should be the directory, but yes, copy that script and save it then modify the alias accordingly.
Catts
03-21-2013, 05:51 AM
it works! I just copied and pasted your script into a text file, then changed the extension to lic using filezilla
Then i made F11 macro to what you gave me (I named it naroherb):
\x;e start_script "naroherb", ['\?']\r
You still have to kill narost for it to work, but that's easy to work in I think. All i have to do is press F11, type the herb and then it'll show me. This is way better than doing :go herbname because I want to know where I"m going first
I love it, I think I'll use this a bunch. Thanks for your help!
also, I changed the marcro to \x;k narost\r;e start_script "naroherb", ['\?']\r to kill narost, which works fine
Tillmen
03-21-2013, 02:33 PM
To get \? to work in an alias with an exec script, it needs doubles quotes around it. It might looks something like this:
;alias add whatever=;eq if room_id = Room.current.find_nearest_by_tag("\?"); if running?('narost'); kill_script('narost') ; 50.times { sleep 0.1; break unless running?('narost') }; end; start_script('narost', [ room_id ]); else; respond 'You did it wrong.'; end
This isn't exactly the same \? as a macro though. For this you'd just type: whatever some acantha leaf
Catts
03-21-2013, 02:41 PM
wow , thats actually way easier...it works perfect. Damn I wish I understood what the hell is going on in that script. Seems pretty clever...
As a ranger this comes is damn handy and saves me a buncha steps that I'd been doing.
greatly appreciated!
Tillmen
03-21-2013, 06:48 PM
Damn I wish I understood what the hell is going on in that script.
There are a couple differences between this and a normal script. First, it's an alias with \? in it. When you trigger an alias that has a \? in it, it will replace all the \?'s with whatever comes after the alias trigger. For example:
;alias add molest=look \?\rtouch \?\rrub \?\rlick \?\r
>molest kobold
You see a fairly typical kobold.
He appears to be in good shape.
He has a short sword, a wooden shield and some light leather (worn).
>
You reach out towards a kobold.
>
You rub your hands together, anticipating combat with a kobold.
>
You stick your tongue out at a kobold.
So when you type "whatever some acantha leaf" with the alias set up, it's equivalent to typing this in the game prompt:
;eq if room_id = Room.current.find_nearest_by_tag("some acantha leaf"); if running?('narost'); kill_script('narost') ; 50.times { sleep 0.1; break unless running?('narost') }; end; start_script('narost', [ room_id ]); else; respond 'You did it wrong.'; end
The line start's with ;eq, which just tells Lich to take everything that comes after it and pretend it's a script. ;e does the same thing, but ;eq hides the script active and exited messages.
So the alias did the equivalent of typing that line for us, which is the equivalent of having this code (without the line numbers) in a script and starting it:
1 if room_id = Room.current.find_nearest_by_tag("some acantha leaf")
2 if running?('narost')
3 kill_script('narost')
4 50.times {
5 sleep 0.1
6 break unless running?('narost')
7 }
8 end
9 start_script('narost', [ room_id ])
10 else
11 respond 'You did it wrong.'
12 end
The first line does Room.current.find_nearest_by_tag("some acantha leaf") and assigns the result to room_id. The result will either be the room number or if it doesn't find anything it will be nil. After that, still on the first line, it does "if room_id". Everything is true except false and nil. If it's nil, it skips down to line 11 and prints "You did it wrong." on the screen. Otherwise it continues to line 2.
Line 2 just tests if narost is currently running. If it's not, it skips down to line 9. If it is, it continues on line 3.
Line 3 kills narost. However, the kill_script method doesn't wait for the script to die before returning. You need a pause so you don't get the message "narost is already running" when you try to start it too quickly.
Lines 4 to 7 are an overcomplicated pause. 50.times {} is going to run the code withing the brackets 50 times before continueing, unless something stops it. Line 5 sleeps a tenth of a second, so at most this loop is going to wait 5 seconds.
Line 6 is shorthand for
unless running?('narost')
break
end
break will cause an early end to the loop, which will happen if narost isn't running.
Line 9 starts narost with the room number we found on line 1.
Catts
03-21-2013, 07:25 PM
ahhh brilliant...I'm actually starting to see how it's piecing together. it seems like there's some constants going on there you'd have to know...global variables? like room_id and then other things...operations like Kill_script and break...but I bet if I learned them and got all the punctuation down I could make a script or two...it's definitely much easier to look at when you put each code on lines. It reminds me of javascript. I used to do web design, but mostly css and jquery, because you didn't really need to know the code, and you could pretty much find templates for anything you wanted to do. It's surprising how many people seem to know ruby...like where'd you all learn it? lol
that bit about the ;eq vs ;e is nifty too, I might work that into some of my aliases just to unclutter my screen.
that was cool, thanks for breakin that down :)
Catts
03-22-2013, 10:10 AM
apparently there's a ton more I need to learn tho...
http://www.krakiipedia.org/wiki/Lich_scripting_reference is a pretty nice resource
lookin at a general ruby for dummies site for the format
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.