Random alias

Posted by Sparafucile on Wed 19 Oct 2005 12:16 AM — 6 posts, 29,342 views.

#0
Hey guys. I have no scripting experience, and I need some help. I'm trying to do a random alias thing for a certain chat channel on the mud I play. Basically, every time I do 'bc (text)' I want it to do something like this:

Input: bc (text)
Output: {Buddy) [Alias 1] (text) OR
(Buddy) =Alias 3= (text) OR
(Buddy) ---Alias 2--- (text) OR... etc

So, every time I type in the channel, I want the script to pick a random alias to put a certain string before my text. I know it's asking alot to write a whole script out for me, but hey, I wouldn't know where to start. Or maybe at least give me the basics; I have -some- programming experience. Thanks!
Australia Forum Administrator #1
This will do it, if you have Lua selected as your scripting language. Just copy and paste into the Alias list box (click the Paste button). You can add any number of names to the "names" table below. It randomly chooses one from the list.


<aliases>
  <alias
   match="bc *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
do
local names =
  {
  "John",
  "Nick",
  "Peter",
  "Margaret"
  }

Send ("(Buddy) " .. 
     names [math.random (1, table.getn (names))] ..
     " %1")

end
</send>
  </alias>
</aliases>


Amended on Wed 19 Oct 2005 08:27 AM by Nick Gammon
#2
Thanks, I really appreciate it. Unfortunately, I'm still having some trouble, this time calling the script. Here's what I did:

- Selected Lua as Scripting Language, checked the Enable Script box, copied the program in a .lua file, set the path to it in the Script File box.

- I assumed the name of the routine was aliases, so I put 'aliases' (without the '') in the Get Focus box. This could be my problem, but I don't think it is becase...

- when I click ok, I get an error message that looks like this. Error Number: 0, Event: Compile Error, Description: "[string "Script file"]:1: unexpected symbol near `<'", Called by: Immediate execution.

Sorry, I really know nothing about this, heh. Also, in the event that I do get it working, I make an alias 'bc *', and put what in the send box? the script filename? or the name of the subroutine, aliases?
USA #3
Copy that whole thing (<aliases> to </aliases> inclusive) and then go to the alias screen (thats the one you get to when you push the alias button, with the grid of aliases), and click the 'paste' button on that screen.

That's all you have to do! No mucking with script files.
#4
Beautiful! thank you so much, both of you. Works like a charm!
Australia Forum Administrator #5
For future reference, the post Pasting triggers describes the general process. Although it refers to triggers the same idea applies to aliases.