How to send a random command

Seinchin
Posts: 9
Joined: Thu Jun 10, 2010 6:10 am

Re: How to send a random command

Post 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 :)

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: How to send a random command

Post by Vadi »


Seinchin
Posts: 9
Joined: Thu Jun 10, 2010 6:10 am

Re: How to send a random command

Post by Seinchin »

LOL Good one :)

Israafiyl
Posts: 56
Joined: Mon Jul 16, 2012 12:29 am

Re: How to send a random command

Post 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?

Golem
Posts: 30
Joined: Thu Feb 07, 2013 6:46 pm

Re: How to send a random command

Post 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 ;)

nubtater
Posts: 2
Joined: Fri Apr 03, 2015 10:00 am

Re: How to send a random command

Post 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

User avatar
Belgarath
Posts: 232
Joined: Fri Jul 26, 2013 7:19 am
Discord: macjabeth#7149

Re: How to send a random command

Post 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)])

nubtater
Posts: 2
Joined: Fri Apr 03, 2015 10:00 am

Re: How to send a random command

Post 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

Post Reply