Page 1 of 10 123 ... LastLast
Results 1 to 10 of 99

Thread: my script questions

  1. #1

    Default my script questions

    Just going to keep an on going thread for myself here instead of making a thread every time I have a question. I'll end up filling up the forums!

    My next question is...

    I want to kill a script, but it could be any one of these scripts:

    big_apple.lic
    red_apple.lic
    small_apple.lic

    Is there a wild card character I can use to circumvent having to type in every script?

    if Script.running?("$_apple")
    kill_script("$_apple")
    end

    I am sure this isnt the correct characters to use, but do you see what I am saying?



    Thanks for all the help so far...

  2. #2

    Default

    Quote Originally Posted by onurb View Post
    Just going to keep an on going thread for myself here instead of making a thread every time I have a question. I'll end up filling up the forums!

    My next question is...

    I want to kill a script, but it could be any one of these scripts:

    big_apple.lic
    red_apple.lic
    small_apple.lic

    Is there a wild card character I can use to circumvent having to type in every script?

    if Script.running?("$_apple")
    kill_script("$_apple")
    end

    I am sure this isnt the correct characters to use, but do you see what I am saying?



    Thanks for all the help so far...
    If you mean you want to kill those scripts if they are running you could do this:

    Code:
    all_scripts = [ "big_apple", "red_apple", "small_apple" ]
    all_scripts.each{ |script_name| kill_script script_name }
    That would kill each listed script.

  3. #3

    Default

    Well thats some good info, and I will definately make use of that. However, the examples I gave you was just 3 script names. What if it was 100 script names? Not saying that it is. But is there not a way that you can do something like anything that ends in _apple will be killed?

  4. #4

    Default

    Quote Originally Posted by onurb View Post
    Well thats some good info, and I will definately make use of that. However, the examples I gave you was just 3 script names. What if it was 100 script names? Not saying that it is. But is there not a way that you can do something like anything that ends in _apple will be killed?
    Script.running.each{ |running_script| kill_script running_script if running_script.name =~ /.*_apple/ }

  5. #5

    Default

    Thank you, that worked out just as I needed it to. I knew * meant everything but didnt realize it was in lich/ruby also.

    So I got this problem now...

    I am trying to get a heirloom out of my container and the command below usually works, but sometimes the critter I killed will carry the item I need but its not classified as "jewelry".

    do_client(";foreach first 1 jewelry in knapsack;get item")

    So I started using this, and it was working for a while, atleast until the last critter I killed carried a box, a gem, and the heirloom. When I looted them, the gem ended up being the first item in my container and therfor, was pulled out with the command below.

    do_client(";foreach first 1 unique in knapsack;get item")

    What can I do to fix this?

  6. #6

    Default

    Quote Originally Posted by onurb View Post
    Thank you, that worked out just as I needed it to. I knew * meant everything but didnt realize it was in lich/ruby also.

    So I got this problem now...

    I am trying to get a heirloom out of my container and the command below usually works, but sometimes the critter I killed will carry the item I need but its not classified as "jewelry".

    do_client(";foreach first 1 jewelry in knapsack;get item")

    So I started using this, and it was working for a while, atleast until the last critter I killed carried a box, a gem, and the heirloom. When I looted them, the gem ended up being the first item in my container and therfor, was pulled out with the command below.

    do_client(";foreach first 1 unique in knapsack;get item")

    What can I do to fix this?
    I'm not sure about using the ;foreach script, I have never used it before.

    This bit of code should work for you though:

    Code:
    if checkbounty =~ /You have located (?:an?|some) (.*) and should bring it back/
    	heirloom_name = $1
    	container = GameObj.inv.find{ |item| item.noun == "knapsack" }
    	needed_item = container.contents.find{ |item| item.name =~ /#{heirloom_name}/ }
    	fput "get ##{needed_item.id}"
    end

  7. #7

    Default

    that works well, ty. what does $1 mean

  8. #8

    Default

    $ in this context means a regex match. In the previous line, (.*) sets up a regex group, and you match against that using the =~ syntax. You can run each of these from the client in game to see what they do:

    Code:
    ;e foo=/(.*) (.*)/;"hello world"=~foo;echo $1
    ;e foo=/(.*) (.*)/;"hello world"=~foo;echo $2
    ;e foo=/(.*)/;"hello world"=~foo;echo $1
    Just to be clear, the 1 in $1 means the first regex match. $2 is the second one, etc.
    Last edited by Slark; 07-19-2022 at 12:20 PM.

  9. #9

    Default

    Quote Originally Posted by Slark View Post
    $ in this context means a regex match. In the previous line, (.*) sets up a regex group, and you match against that using the =~ syntax. You can run each of these from the client in game to see what they do. Just to be clear, the 1 in $1 means the first regex match. $2 is the second one, etc.
    hmm, thats very cool. ty for the explanation. this will come in handy.

  10. #10

    Default

    trying to adjust the code to accomodate gems, but it appears I may have something wrong...

    if checkbounty =~ /multiple customers requesting (?:an?|some) (.*)/
    gem_name = $1
    container = GameObj.inv.find{ |item| item.noun == "knapsack" }
    needed_gem = container.contents.find{ |item| item.name =~ /#{gem_name}/ }
    fput "get ##{needed_gem.id}"
    end

    output is this...

    >;test
    --- Lich: test active.
    [test]>get #
    Get what?
    --- Lich: test has exited.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •