Page 2 of 2

Re: How to send a random command

Posted: Thu Jun 10, 2010 1:13 pm
by Seinchin
This is really nice...helped me to optimise one of my scripts that randomly targets a body part. The scripts is now about 15 lines shorter :)

Re: How to send a random command

Posted: Thu Jun 10, 2010 3:03 pm
by Vadi

Re: How to send a random command

Posted: Thu Jun 10, 2010 6:14 pm
by Seinchin
LOL Good one :)

Re: How to send a random command

Posted: Sat Feb 09, 2013 7:51 am
by Israafiyl
how do you send the commands in order and then when done with the last repeat? Is it possible with some sort of variant of this command?

Re: How to send a random command

Posted: Sat Feb 09, 2013 8:07 am
by Golem
You could keep a global counter.
Code: [show] | [select all] lua
function doNext()
	local commands = { "a", "b", "c" }

	if counter == nil then
		counter = 1
	end

	send(commands[counter])
	counter = counter % #commands + 1
end
The counter just loops between 1 and 3 (or whatever the size of the table is - #commands).
Just remember that it is global, so perhaps use a more unique name for the counter ;)

Re: How to send a random command

Posted: Fri Apr 03, 2015 10:06 am
by nubtater
came across this thread, just started using mudlet not to long ago and have been trying to figure out the easiest way to make a random movement trigger, and this looks about what i am looking for though i think i am missing something during implementation of it.

the input from the mud I play looks like this

Obvious Exits: southwest, northwest, west, and north.

the trigger i am using to capture it is
Code: [show] | [select all] lua
^Obvious Exits: (. *) and (\w+)$
and using the above information this is what i put in
Code: [show] | [select all] lua
local commands = matches[2]
local which = math.random(#commands)

send(commands[which])
any help would be greatly appreciated, i've been spending alot of time reading up on lua, regex and pattern matching but still getting used to mudlet

Re: How to send a random command

Posted: Sun Apr 26, 2015 8:48 pm
by Belgarath
Hey.. nubtater. Here's an easy way to capture those exits:
Code: [show] | [select all] lua
-- ^Obvious Exits: (.+)\.$
local exits = matches[2]:split(", ")
exits[#exits] = exits[#exits]:gsub("and ", "")
send(exits[math.random(#exits)])

Re: How to send a random command

Posted: Sun May 31, 2015 3:02 pm
by nubtater
appreciate all the feedback, been using it to fiddle with in different ways to expand my understanding of lua so thank you for all the comments and info