Room Commands

All and any discussion and development of the Mudlet Mapper.
Post Reply
User avatar
Omit
Posts: 190
Joined: Sun Aug 01, 2010 10:54 pm
Location: Middle Earth
Contact:

Room Commands

Post by Omit »

The following code will allow you to save a list of commands for a specific room with your map(as 'RoomUserData') and later echo them to a user window as clickable links.
Code: [show] | [select all] lua
function addRoomCommand(rID,Cmd)
 local cmds = getRoomUserData(rID,"cmds")
 local cmdTable = string.split(cmds,"|")
  if table.contains(cmdTable,Cmd) then
   local ct = 1
   display(cmdTable)
    while cmdTable[ct] do
     if cmdTable[ct]==Cmd then
      table.remove(cmdTable,ct)
      echo("Room Command("..Cmd..") deleted.\n")
     end--if
     ct=ct+1
    end--while
  else
   if cmdTable[1]=="" then
    cmdTable[1]=Cmd
   else
    table.insert(cmdTable,Cmd)
   end--if
   echo("Room Command("..Cmd..") added.\n")
  end--if
 cmds=table.concat(cmdTable,"|")
 setRoomUserData(rID,"cmds",cmds)
end--func

function echoRoomCommands(rID,window,delimiter)
 local sep = delimiter or ","   --"\n"
 local cmds = getRoomUserData(rID,"cmds")
 local cmdTable = string.split(cmds,"|")
 local ct=1
  while cmdTable[ct] do
   if cmdTable[ct]~= "" then
    if window then
     echoLink(window,cmdTable[ct],[[send("]]..cmdTable[ct]..[[")]],"click to send:"..cmdTable[ct],false)
     echo(window,sep)
    else
     echoLink(cmdTable[ct],[[send("]]..cmdTable[ct]..[[")]],"click to send:"..cmdTable[ct],false)
     echo(sep)
    end--if
   end--if
   ct=ct+1
  end--while
end
These two functions are intended to be used like this
addRoomCommand(rID,Cmd)
where rID is the room ID you want to assign a command to and Cmd is the command to be saved as a string.

echoRoomCommands(rID,window,delimiter)
where rID is the room ID that you want to echo the commands of, window is the users window to echo the links to(echos to main window if nil) and delimiter is used to seperate the links that are echoed(uses a comma if nil)

Post Reply