Page 4 of 10 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 99

Thread: my script questions

  1. #31

    Default

    Quote Originally Posted by onurb View Post
    what if I wanted to loop something every 30 seconds.. like I wanted the gem alert to keep happening every 30 seconds.

    Code:
    while line = get
    	respond " ***  GEM ALERT *** "
    	if line =~ /"dropped"/
    		fput "loot room"
    		break
    	elseif line =~ /YOU HAVE BEEN IDLE TOO LONG./
    		fput "look"
    	end
    end
    
    fput "go turn those bad boys in"
    Do you just want the GEM ALERT every 30 seconds? Or the whole while statement?

    You can wrap the whole thing in a loop.

    Code:
    loop{
    	while line = get
    		respond " ***  GEM ALERT *** "
    		if line =~ /"dropped"/
    			fput "loot room"
    			break
    		elseif line =~ /YOU HAVE BEEN IDLE TOO LONG./
    			fput "look"
    		end
    	end
    
    	fput "go turn those bad boys in"
    	sleep 30
    }
    I'm also assuming you want the GEM ALERT to be within the first if statement, otherwise it's going to echo that after every line.

  2. #32

    Default

    Quote Originally Posted by Tgo01 View Post
    Do you just want the GEM ALERT every 30 seconds? Or the whole while statement?
    was wanting the gem alert message every 30 seconds while its waiting for those two matches "dropped" or "idle too long" to occur.

  3. #33

    Default

    Probably easiest to just run a new thread.

    Code:
    Thread.new
    	loop{
    		respond " ***  GEM ALERT *** "
    		sleep 30
    	}
    }
    
    while line = get
    	if line =~ /"dropped"/
    		fput "loot room"
    		break
    	elseif line =~ /YOU HAVE BEEN IDLE TOO LONG./
    		fput "look"
    	end
    end
    
    fput "go turn those bad boys in"
    A new thread basically just runs a set of code separately from the other code in the script. Careful when using a thread though because each thread and the main code share the game lines coming in, meaning if you have a thread/the main code both looking for game lines (such as a while line loop and using an fput) then one of them isn't going to see all of the game lines.

    It's fine otherwise for code that isn't looking at game lines, which respond does not.

  4. #34

    Default

    I am on the brink of putting this all together (thanks to you, and some others), but I seem to have one last error to iron out...

    Code:
    while line = get
    	if line =~ /(?:Bill|Bob|Ted) says, "(.*): (.*)"/
    		gem_quantity = $1
    		gem_name = $2
    		gem_quantity.times{ 
    			fput "get #{gem_name} from my knapsack"
    			fput "drop #{gem_name}"
    		}
    		fput "There you go!"
    	end
    end
    For some reason it dosen't understand how many times it's supposed to drop a gem. If I put an actual number in there like this "10.times" instead of "gem_quantity.times" it will work like a charm. I would also really like to figure out a way to not have to put a character between the two (.*): (.*) just to make it work. if you take out that semi colon, the first regex merges with the second regex even if there is a space between them. But if that cant be, not too worried about it.

    --- Lich: error: undefined method `times' for "10":String
    dropgem:6:in `_script'
    C:/Lich5/lich.rbw:802:in `eval'
    Last edited by onurb; 07-20-2022 at 01:34 AM.

  5. #35

    Default

    Quote Originally Posted by onurb View Post
    I am on the brink of putting this all together (thanks to you, and some others), but I seem to have one last error to iron out...

    Code:
    while line = get
    	if line =~ /(?:Bill|Bob|Ted) says, "(.*): (.*)"/
    		gem_quantity = $1
    		gem_name = $2
    		gem_quantity.times{ 
    			fput "get #{gem_name} from my knapsack"
    			fput "drop #{gem_name}"
    		}
    		fput "There you go!"
    	end
    end
    For some reason it dosen't understand how many times it's supposed to drop a gem. If I put an actual number in there like this "10.times" instead of "gem_quantity.times" it will work like a charm. I would also really like to figure out a way to not have to put a character between the two (.*): (.*) just to make it work. if you take out that semi colon, the first regex merges with the second regex even if there is a space between them. But if that cant be, not too worried about it.

    --- Lich: error: undefined method `times' for "10":String
    dropgem:6:in `_script'
    C:/Lich5/lich.rbw:802:in `eval'
    By default regex sees things as strings/characters, even though it is a digit, so it doesn't see the number 2 as a number, it sees it as a character just as if it were the letter "a".

    So you would need to do: gem_quantity = $1.to_i

    This would make it store the value as an integer.

    As far as the space issue you could do:

    (?:Bill|Bob|Ted) says, "(\d+) (.*)"

    \d means any digit and + just 1 or more, so that should work.

  6. #36

    Default



    I'll be back tomorrow. Need to figure out how to keep them from saying "There you go!" if they don't have the gems needed.

  7. #37

    Default

    seems I have run into an issue

    Code:
    if checkbounty =~ /The gem dealer in Ta'Illistim, Tanzania, has received orders from multiple customers requesting (?:an?|some|piece|of) (.*).  You have been tasked to retrieve (.*) of them./
    	gem_name = $1
    	gem_quantity = $2.to_i
    	gem_quantity.times{ 
    		fput "get my #{gem_name}"
    		fput "sell my #{gem_name}"
    	}
    end
    [sellgem]>get my green malachite stone
    Get what?
    >
    [sellgem]>sell my green malachite stone
    What were you referring to?

    Is there a way to ignore everything between "requesting" and the gem's noun? I think it would be too difficult to try and determine the adjective of the noun as sometimes its the first word in a 3 word gem, sometimes its the second word...

  8. #38

    Default

    Quote Originally Posted by onurb View Post
    seems I have run into an issue

    Code:
    if checkbounty =~ /The gem dealer in Ta'Illistim, Tanzania, has received orders from multiple customers requesting (?:an?|some|piece|of) (.*).  You have been tasked to retrieve (.*) of them./
    	gem_name = $1
    	gem_quantity = $2.to_i
    	gem_quantity.times{ 
    		fput "get my #{gem_name}"
    		fput "sell my #{gem_name}"
    	}
    end
    [sellgem]>get my green malachite stone
    Get what?
    >
    [sellgem]>sell my green malachite stone
    What were you referring to?

    Is there a way to ignore everything between "requesting" and the gem's noun? I think it would be too difficult to try and determine the adjective of the noun as sometimes its the first word in a 3 word gem, sometimes its the second word...
    Easiest way would probably be to use the code I posted earlier about looking through your knapsack container and getting the item ID number. That way it can match the whole name of the gem in your container and get the item ID so you don't have to worry about the wording.

  9. #39

    Default

    so I did that, and it seems like its using ids now instead of names. but it wants to use the same id every time...

    Code:
    if checkbounty =~ /concoction that requires (?:a |an )?(.*) found (?:on |in )?(.*?)(?: (?:near|between|under) .*?)?\.\s+These samples must be in pristine condition\.\s+You have been tasked to retrieve (\d+) (?:more )?sample/
    	herb_name = $1
    	herb_location = $2
    	herb_quantity = $3.to_i
    	container = GameObj.inv.find{ |item| item.noun == "knapsack" }
    	needed_item = container.contents.find{ |item| item.name =~ /#{herb_name}/ }
    	herb_quantity.times{ 
    		fput "get my ##{needed_item.id}"
    		fput "give my ##{needed_item.id} to jhiseth"
    	}
    end
    >;test
    --- Lich: test active.
    [test]>get my #1325423487
    Get what?
    >
    [test]>give my #1325423487 to jhiseth
    What is it you're trying to give?
    >
    [test]>get my #1325423487
    Get what?
    >
    [test]>give my #1325423487 to jhiseth
    What is it you're trying to give?
    >
    --- Lich: test has exited.

  10. Default

    Quote Originally Posted by onurb View Post
    so I did that, and it seems like its using ids now instead of names. but it wants to use the same id every time...

    Code:
    if checkbounty =~ /concoction that requires (?:a |an )?(.*) found (?:on |in )?(.*?)(?: (?:near|between|under) .*?)?\.\s+These samples must be in pristine condition\.\s+You have been tasked to retrieve (\d+) (?:more )?sample/
    	herb_name = $1
    	herb_location = $2
    	herb_quantity = $3.to_i
    	container = GameObj.inv.find{ |item| item.noun == "knapsack" }
    	needed_item = container.contents.find{ |item| item.name =~ /#{herb_name}/ }
    	herb_quantity.times{ 
    		fput "get my ##{needed_item.id}"
    		fput "give my ##{needed_item.id} to jhiseth"
    	}
    end
    >;test
    --- Lich: test active.
    [test]>get my #1325423487
    Get what?
    >
    [test]>give my #1325423487 to jhiseth
    What is it you're trying to give?
    >
    [test]>get my #1325423487
    Get what?
    >
    [test]>give my #1325423487 to jhiseth
    What is it you're trying to give?
    >
    --- Lich: test has exited.
    I'm ultimately not familiar with the methods and nuances of Lich's exposed methods, and I haven't really written Ruby since Ruby on Rails was the hot thing, so I can point you towards "what is happening" here but can't quite edge you towards a solid resolution without some research.

    Your ".times" method is creating a loop but you're updating the ID before you enter the loop on the line above it.

    If you want the ID to be different for each iteration you need to update it again inside the loop.

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
  •